Jacek Caban : jscript: Delay error object creation for builtin errors with message string until it's needed.

Alexandre Julliard julliard at winehq.org
Mon Feb 3 15:06:07 CST 2020


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Feb  3 14:47:32 2020 +0100

jscript: Delay error object creation for builtin errors with message string until it's needed.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/dispex.c  | 12 ++++++------
 dlls/jscript/engine.c  | 10 ++++------
 dlls/jscript/error.c   | 41 ++++++++---------------------------------
 dlls/jscript/jscript.h |  2 +-
 4 files changed, 19 insertions(+), 46 deletions(-)

diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c
index 4ed327ad72..e986de6ef2 100644
--- a/dlls/jscript/dispex.c
+++ b/dlls/jscript/dispex.c
@@ -2483,13 +2483,13 @@ HRESULT jsdisp_define_property(jsdisp_t *obj, const WCHAR *name, property_desc_t
         if(((desc->mask & PROPF_CONFIGURABLE) && (desc->flags & PROPF_CONFIGURABLE))
            || ((desc->mask & PROPF_ENUMERABLE)
                && ((desc->flags & PROPF_ENUMERABLE) != (prop->flags & PROPF_ENUMERABLE))))
-            return throw_type_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
+            return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
     }
 
     if(desc->explicit_value || (desc->mask & PROPF_WRITABLE)) {
         if(prop->type == PROP_ACCESSOR) {
             if(!(prop->flags & PROPF_CONFIGURABLE))
-                return throw_type_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
+                return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
             if(prop->u.accessor.getter)
                 jsdisp_release(prop->u.accessor.getter);
             if(prop->u.accessor.setter)
@@ -2504,7 +2504,7 @@ HRESULT jsdisp_define_property(jsdisp_t *obj, const WCHAR *name, property_desc_t
         }else {
             if(!(prop->flags & PROPF_CONFIGURABLE) && !(prop->flags & PROPF_WRITABLE)) {
                 if((desc->mask & PROPF_WRITABLE) && (desc->flags & PROPF_WRITABLE))
-                    return throw_type_error(obj->ctx, JS_E_NONWRITABLE_MODIFIED, name);
+                    return throw_error(obj->ctx, JS_E_NONWRITABLE_MODIFIED, name);
                 if(desc->explicit_value) {
                     if(prop->type == PROP_JSVAL) {
                         BOOL eq;
@@ -2512,7 +2512,7 @@ HRESULT jsdisp_define_property(jsdisp_t *obj, const WCHAR *name, property_desc_t
                         if(FAILED(hres))
                             return hres;
                         if(!eq)
-                            return throw_type_error(obj->ctx, JS_E_NONWRITABLE_MODIFIED, name);
+                            return throw_error(obj->ctx, JS_E_NONWRITABLE_MODIFIED, name);
                     }else {
                         FIXME("redefinition of property type %d\n", prop->type);
                     }
@@ -2533,7 +2533,7 @@ HRESULT jsdisp_define_property(jsdisp_t *obj, const WCHAR *name, property_desc_t
     }else if(desc->explicit_getter || desc->explicit_setter) {
         if(prop->type != PROP_ACCESSOR) {
             if(!(prop->flags & PROPF_CONFIGURABLE))
-                return throw_type_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
+                return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
             if(prop->type == PROP_JSVAL)
                 jsval_release(prop->u.val);
             prop->type = PROP_ACCESSOR;
@@ -2541,7 +2541,7 @@ HRESULT jsdisp_define_property(jsdisp_t *obj, const WCHAR *name, property_desc_t
         }else if(!(prop->flags & PROPF_CONFIGURABLE)) {
             if((desc->explicit_getter && desc->getter != prop->u.accessor.getter)
                || (desc->explicit_setter && desc->setter != prop->u.accessor.setter))
-                return throw_type_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
+                return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
         }
 
         if(desc->explicit_getter) {
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index e84dd4e3d7..054b0c7602 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -918,7 +918,7 @@ static HRESULT interp_throw_type(script_ctx_t *ctx)
     TRACE("%08x %s\n", hres, debugstr_jsstr(str));
 
     ptr = jsstr_flatten(str);
-    return ptr ? throw_type_error(ctx, hres, ptr) : E_OUTOFMEMORY;
+    return ptr ? throw_error(ctx, hres, ptr) : E_OUTOFMEMORY;
 }
 
 /* ECMA-262 3rd Edition    12.14 */
@@ -1287,7 +1287,7 @@ static HRESULT identifier_value(script_ctx_t *ctx, BSTR identifier)
         return hres;
 
     if(exprval.type == EXPRVAL_INVALID)
-        return throw_type_error(ctx, exprval.u.hres, identifier);
+        return throw_error(ctx, exprval.u.hres, identifier);
 
     hres = exprval_to_value(ctx, &exprval, &v);
     if(FAILED(hres))
@@ -2777,10 +2777,8 @@ static HRESULT unwind_exception(script_ctx_t *ctx, HRESULT exception_hres)
     }
 
     frame = ctx->call_ctx;
-    if(exception_hres != DISP_E_EXCEPTION) {
-        reset_ei(ei);
-        ei->error = exception_hres;
-    }
+    if(exception_hres != DISP_E_EXCEPTION)
+        throw_error(ctx, exception_hres, NULL);
     set_error_location(ei, frame->bytecode, frame->bytecode->instrs[frame->ip].loc, IDS_RUNTIME_ERROR);
 
     while(!frame->except_frame) {
diff --git a/dlls/jscript/error.c b/dlls/jscript/error.c
index b58210d2a7..eca6c90138 100644
--- a/dlls/jscript/error.c
+++ b/dlls/jscript/error.c
@@ -409,40 +409,15 @@ static jsstr_t *format_error_message(HRESULT error, const WCHAR *arg)
     return r;
 }
 
-static HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str, jsdisp_t *constr)
+HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
 {
-    jsdisp_t *err;
-    jsstr_t *msg;
-    HRESULT hres;
-
-    if(!is_jscript_error(error))
-        return error;
-
-    msg = format_error_message(error, str);
-    if(!msg)
-        return E_OUTOFMEMORY;
-
-    WARN("%s\n", debugstr_jsstr(msg));
-
-    hres = create_error(ctx, constr, error, msg, &err);
-    jsstr_release(msg);
-    if(FAILED(hres))
-        return hres;
-
-    reset_ei(ctx->ei);
-    ctx->ei->valid_value = TRUE;
-    ctx->ei->value = jsval_obj(err);
-    return error;
-}
-
-HRESULT throw_syntax_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
-{
-    return throw_error(ctx, error, str, ctx->syntax_error_constr);
-}
-
-HRESULT throw_type_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
-{
-    return throw_error(ctx, error, str, ctx->type_error_constr);
+    jsexcept_t *ei = ctx->ei;
+    TRACE("%08x\n", error);
+    reset_ei(ei);
+    ei->error = error;
+    if(str)
+        ei->message = format_error_message(error, str);
+    return DISP_E_EXCEPTION;
 }
 
 void set_error_location(jsexcept_t *ei, bytecode_t *code, unsigned loc, unsigned source_id)
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 9933347950..8db76bb50d 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -312,7 +312,7 @@ HRESULT Function_get_value(script_ctx_t*,jsdisp_t*,jsval_t*) DECLSPEC_HIDDEN;
 struct _function_code_t *Function_get_code(jsdisp_t*) DECLSPEC_HIDDEN;
 #define DEFAULT_FUNCTION_VALUE {NULL, Function_value,0, Function_get_value}
 
-HRESULT throw_type_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
+HRESULT throw_error(script_ctx_t*,HRESULT,const WCHAR*) DECLSPEC_HIDDEN;
 jsdisp_t *create_builtin_error(script_ctx_t *ctx) DECLSPEC_HIDDEN;
 
 HRESULT create_object(script_ctx_t*,jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list