Piotr Caban : jscript: Add Error_number handling to constructor and error throwing functions.

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


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

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

jscript: Add Error_number handling to constructor and error throwing functions.

---

 dlls/jscript/error.c      |   43 ++++++++++++++++++++++++++++++++++++++-----
 dlls/jscript/tests/api.js |   27 ++++++++++++++++++---------
 2 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/dlls/jscript/error.c b/dlls/jscript/error.c
index 076215f..d160dd6 100644
--- a/dlls/jscript/error.c
+++ b/dlls/jscript/error.c
@@ -15,6 +15,10 @@
  * 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 "config.h"
+#include "wine/port.h"
+
+#include <math.h>
 
 #include "jscript.h"
 
@@ -213,7 +217,7 @@ static HRESULT alloc_error(script_ctx_t *ctx, BOOL error_prototype,
 }
 
 static HRESULT create_error(script_ctx_t *ctx, DispatchEx *constr,
-        const WCHAR *msg, DispatchEx **ret)
+        const UINT *number, const WCHAR *msg, DispatchEx **ret)
 {
     ErrorInstance *err;
     HRESULT hres;
@@ -222,10 +226,17 @@ static HRESULT create_error(script_ctx_t *ctx, DispatchEx *constr,
     if(FAILED(hres))
         return hres;
 
+    if(number) {
+        V_VT(&err->number) = VT_I4;
+        V_I4(&err->number) = *number;
+    }
+
     V_VT(&err->message) = VT_BSTR;
     if(msg) V_BSTR(&err->message) = SysAllocString(msg);
     else V_BSTR(&err->message) = SysAllocStringLen(NULL, 0);
 
+    VariantCopy(&err->description, &err->message);
+
     if(!V_BSTR(&err->message)) {
         heap_free(err);
         return E_OUTOFMEMORY;
@@ -238,11 +249,28 @@ static HRESULT create_error(script_ctx_t *ctx, DispatchEx *constr,
 static HRESULT error_constr(DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, DispatchEx *constr) {
     DispatchEx *err;
+    VARIANT numv;
+    UINT num;
     BSTR msg = NULL;
     HRESULT hres;
 
+    V_VT(&numv) = VT_NULL;
+
     if(arg_cnt(dp)) {
-        hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &msg);
+        hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &numv);
+        if(FAILED(hres) || (V_VT(&numv)==VT_R8 && isnan(V_R8(&numv))))
+            hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &msg);
+        else if(V_VT(&numv) == VT_I4)
+            num = V_I4(&numv);
+        else
+            num = V_R8(&numv);
+
+        if(FAILED(hres))
+            return hres;
+    }
+
+    if(arg_cnt(dp)>1 && !msg) {
+        hres = to_string(dispex->ctx, get_arg(dp, 1), ei, &msg);
         if(FAILED(hres))
             return hres;
     }
@@ -250,7 +278,11 @@ static HRESULT error_constr(DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
     switch(flags) {
     case INVOKE_FUNC:
     case DISPATCH_CONSTRUCT:
-        hres = create_error(dispex->ctx, constr, msg, &err);
+        if(V_VT(&numv) == VT_NULL)
+            hres = create_error(dispex->ctx, constr, NULL, msg, &err);
+        else
+            hres = create_error(dispex->ctx, constr, &num, msg, &err);
+
         if(FAILED(hres))
             return hres;
 
@@ -394,7 +426,8 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH
         memcpy(pos, str, len*sizeof(WCHAR));
     }
 
-    hres = create_error(ctx, constr, buf, &err);
+    id |= 0x800A0000;
+    hres = create_error(ctx, constr, &id, buf, &err);
     if(FAILED(hres))
         return hres;
 
@@ -404,7 +437,7 @@ static HRESULT throw_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCH
     V_VT(&ei->var) = VT_DISPATCH;
     V_DISPATCH(&ei->var) = (IDispatch*)_IDispatchEx_(err);
 
-    return 0x800A0000+id;
+    return id;
 }
 
 HRESULT throw_eval_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 4cf5bb6..c20cd8b 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -1287,22 +1287,31 @@ ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
 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) {
+err = new Error(123);
+ok(err.number === 123, "err.number = " + err.number);
+err = new Error(0, "message");
+ok(err.number === 0, "err.number = " + err.number);
+ok(err.message === "message", "err.message = " + err.message);
+ok(err.description === "message", "err.description = " + err.description);
+
+function exception_test(func, type, number) {
     ret = "";
+    num = "";
     try {
         func();
     } catch(e) {
         ret = e.name;
+        num = e.number;
     }
     ok(ret === type, "Exception test, ret = " + ret + ", expected " + type +". Executed function: " + func.toString());
+    ok(num === number, "Exception test, num = " + num + ", expected " + number + ". Executed function: " + func.toString());
 }
-exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError");
-exception_test(function() {Array(-3);}, "RangeError");
-exception_test(function() {arr.toString = Boolean.prototype.toString; arr.toString();}, "TypeError");
-exception_test(function() {date.setTime();}, "TypeError");
-exception_test(function() {arr.test();}, "TypeError");
-exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError");
-exception_test(function() {(new Number(3)).toString(1);}, "TypeError");
+exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError", -2146823282);
+exception_test(function() {Array(-3);}, "RangeError", -2146823259);
+exception_test(function() {arr.toString = Boolean.prototype.toString; arr.toString();}, "TypeError", -2146823278);
+exception_test(function() {date.setTime();}, "TypeError", -2146827839);
+exception_test(function() {arr.test();}, "TypeError", -2146827850);
+exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError", -2146823287);
+exception_test(function() {(new Number(3)).toString(1);}, "TypeError", -2146828283);
 
 reportSuccess();




More information about the wine-cvs mailing list