Piotr Caban : jscript: Add error throwing functions.

Alexandre Julliard julliard at winehq.org
Tue Jul 21 09:34:08 CDT 2009


Module: wine
Branch: master
Commit: 469b5972128e8b501ddcec4f03aacede77b5b93f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=469b5972128e8b501ddcec4f03aacede77b5b93f

Author: Piotr Caban <piotr.caban at gmail.com>
Date:   Mon Jul 20 18:18:00 2009 +0200

jscript: Add error throwing functions.

---

 dlls/jscript/Makefile.in    |    6 +++-
 dlls/jscript/date.c         |    6 +---
 dlls/jscript/error.c        |   60 +++++++++++++++++++++++++++++++++++++++++++
 dlls/jscript/jscript.h      |   11 ++++++++
 dlls/jscript/jscript_En.rc  |   26 ++++++++++++++++++
 dlls/jscript/jscript_main.c |    2 +-
 dlls/jscript/resource.h     |   21 +++++++++++++++
 dlls/jscript/tests/api.js   |   11 ++++++++
 8 files changed, 136 insertions(+), 7 deletions(-)

diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in
index b740546..c76bed0 100644
--- a/dlls/jscript/Makefile.in
+++ b/dlls/jscript/Makefile.in
@@ -3,9 +3,11 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = jscript.dll
-IMPORTS   = oleaut32 advapi32 kernel32
+IMPORTS   = oleaut32 user32 advapi32 kernel32
 
-RC_SRCS = rsrc.rc
+RC_SRCS = \
+	jscript_En.rc \
+	rsrc.rc
 
 C_SRCS = \
 	array.c \
diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c
index b65f03e..1630828 100644
--- a/dlls/jscript/date.c
+++ b/dlls/jscript/date.c
@@ -590,10 +590,8 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
 
     TRACE("\n");
 
-    if(!is_class(dispex, JSCLASS_DATE)) {
-        FIXME("throw TypeError\n");
-        return E_FAIL;
-    }
+    if(!is_class(dispex, JSCLASS_DATE))
+        return throw_type_error(dispex->ctx, ei, IDS_NOT_DATE, NULL);
 
     date = (DateInstance*)dispex;
     time = local_time(date->time, date);
diff --git a/dlls/jscript/error.c b/dlls/jscript/error.c
index b122c39..422412a 100644
--- a/dlls/jscript/error.c
+++ b/dlls/jscript/error.c
@@ -330,3 +330,63 @@ HRESULT init_error_constr(script_ctx_t *ctx)
 
     return S_OK;
 }
+
+static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str, DispatchEx *constr)
+{
+    WCHAR buf[1024], *pos = NULL;
+    DispatchEx *err;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    LoadStringW(jscript_hinstance, id,  buf, sizeof(buf)/sizeof(WCHAR));
+
+    if(str) pos = strchrW(buf, '|');
+    if(pos) {
+        int len = strlenW(str);
+        memmove(pos+len, pos+1, strlenW(pos+1)*sizeof(WCHAR));
+        memcpy(pos, str, len*sizeof(WCHAR));
+    }
+
+    hres = create_error(ctx, constr, buf, &err);
+    if(FAILED(hres))
+        return hres;
+
+    if(!ei)
+        return id;
+
+    V_VT(&ei->var) = VT_DISPATCH;
+    V_DISPATCH(&ei->var) = (IDispatch*)_IDispatchEx_(err);
+
+    return 0x800A0000+id;
+}
+
+HRESULT throw_eval_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
+{
+    return throw_error(ctx, ei, id, str, ctx->eval_error_constr);
+}
+
+HRESULT throw_range_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
+{
+    return throw_error(ctx, ei, id, str, ctx->range_error_constr);
+}
+
+HRESULT throw_reference_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
+{
+    return throw_error(ctx, ei, id, str, ctx->reference_error_constr);
+}
+
+HRESULT throw_syntax_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
+{
+    return throw_error(ctx, ei, id, str, ctx->syntax_error_constr);
+}
+
+HRESULT throw_type_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
+{
+    return throw_error(ctx, ei, id, str, ctx->type_error_constr);
+}
+
+HRESULT throw_uri_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
+{
+    return throw_error(ctx, ei, id, str, ctx->uri_error_constr);
+}
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 14903e9..f99299f 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -28,6 +28,8 @@
 #include "dispex.h"
 #include "activscp.h"
 
+#include "resource.h"
+
 #include "wine/unicode.h"
 #include "wine/list.h"
 
@@ -58,6 +60,8 @@ jsheap_t *jsheap_mark(jsheap_t*);
 
 typedef struct DispatchEx DispatchEx;
 
+extern HINSTANCE jscript_hinstance;
+
 #define PROPF_ARGMASK 0x00ff
 #define PROPF_METHOD  0x0100
 #define PROPF_ENUM    0x0200
@@ -139,6 +143,13 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_inf
         DispatchEx*,DispatchEx**);
 HRESULT Function_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
 
+HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
+HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
+HRESULT throw_reference_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
+HRESULT throw_syntax_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
+HRESULT throw_type_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
+HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
+
 
 HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
 HRESULT create_math(script_ctx_t*,DispatchEx**);
diff --git a/dlls/jscript/jscript_En.rc b/dlls/jscript/jscript_En.rc
new file mode 100644
index 0000000..cee2718
--- /dev/null
+++ b/dlls/jscript/jscript_En.rc
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2009 Piotr Caban
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "resource.h"
+
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
+
+STRINGTABLE DISCARDABLE
+{
+    IDS_NOT_DATE            "'[object]' is not a date object"
+}
diff --git a/dlls/jscript/jscript_main.c b/dlls/jscript/jscript_main.c
index 37266e5..4f59ecb 100644
--- a/dlls/jscript/jscript_main.c
+++ b/dlls/jscript/jscript_main.c
@@ -40,7 +40,7 @@ static const CLSID CLSID_JScriptEncode =
 
 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
 
-static HINSTANCE jscript_hinstance;
+HINSTANCE jscript_hinstance;
 
 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
 {
diff --git a/dlls/jscript/resource.h b/dlls/jscript/resource.h
new file mode 100644
index 0000000..e0f6661
--- /dev/null
+++ b/dlls/jscript/resource.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2009 Piotr Caban
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <windef.h>
+
+#define IDS_NOT_DATE                        0x138E
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 18e6141..36fb191 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -1288,4 +1288,15 @@ err = new Error("message");
 ok(err.message === "message", "err.message !== 'message'");
 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
 
+function exception_test(func, type) {
+    ret = "";
+    try {
+        func();
+    } catch(e) {
+        ret = e.name;
+    }
+    ok(ret === type, "Exception test, ret = " + ret + ", expected " + type +". Executed function: " + func.toString());
+}
+exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError");
+
 reportSuccess();




More information about the wine-cvs mailing list