[PATCH] jscript: throw TypeError if T in 'new T' is not an object. [try 2]

Reece Dunn msclrhd at googlemail.com
Fri Oct 1 02:59:45 CDT 2010


Hi,

try 1 -- throw TypeError if T in 'new T' is not an object.
try 2 -- handle the case when using a null dispatch pointer: `new nullDisp;`

NOTE: given `new 3;` the engine should report IDS_UNSUPPORTED_ACTION
instead of IDS_NO_PROPERTY but this requires more changes to the code
(constr.vt is VT_EMPTY in both of these cases in engine.c).

- Reece
-------------- next part --------------
From 3431a4b35b047a4448053ea0ed91fd7c5b29c99d Mon Sep 17 00:00:00 2001
From: Reece Dunn <msclrhd at gmail.com>
Date: Fri, 1 Oct 2010 08:51:56 +0100
Subject: [PATCH] jscript: throw TypeError if T in 'new T' is not an object.

---
 dlls/jscript/engine.c     |    5 ++---
 dlls/jscript/tests/api.js |    2 ++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 8aed4db..f93edd9 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -1562,10 +1562,9 @@ HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, j
     if(FAILED(hres))
         return hres;
 
-    if(V_VT(&constr) != VT_DISPATCH) {
-        FIXME("throw TypeError\n");
+    if(V_VT(&constr) != VT_DISPATCH || !V_DISPATCH(&constr)) {
         VariantClear(&constr);
-        return E_FAIL;
+        return throw_type_error(ctx->parser->script, ei, V_DISPATCH(&constr) ? IDS_OBJECT_EXPECTED : IDS_NO_PROPERTY, NULL);
     }
 
     hres = disp_call(ctx->parser->script, V_DISPATCH(&constr), DISPID_VALUE,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 2e0ae0b..7a77e57 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -1894,6 +1894,8 @@ exception_test(function() {(new Object()) instanceof nullDisp;}, "TypeError", -2
 exception_test(function() {"test" in 3;}, "TypeError", -2146823281);
 exception_test(function() {"test" in null;}, "TypeError", -2146823281);
 exception_test(function() {"test" in nullDisp;}, "TypeError", -2146823281);
+exception_test(function() {new null;}, "TypeError", -2146823281);
+exception_test(function() {new nullDisp;}, "TypeError", -2146827850);
 
 function testThisExcept(func, number) {
     exception_test(function() {func.call(new Object())}, "TypeError", number);
-- 
1.7.0.4


More information about the wine-patches mailing list