Jacek Caban : jscript: Throw error when trying to add a property to non-extensible objects in jsdisp_propput_idx.

Alexandre Julliard julliard at winehq.org
Fri Apr 2 16:10:12 CDT 2021


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Apr  2 20:24:18 2021 +0200

jscript: Throw error when trying to add a property to non-extensible objects in jsdisp_propput_idx.

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/function.c  |  2 +-
 dlls/jscript/jscript.h   |  2 +-
 dlls/mshtml/tests/es5.js | 43 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c
index ca404f92fe5..38055fe4cfa 100644
--- a/dlls/jscript/dispex.c
+++ b/dlls/jscript/dispex.c
@@ -2145,7 +2145,7 @@ HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, W
     return hres;
 }
 
-HRESULT jsdisp_propput(jsdisp_t *obj, const WCHAR *name, DWORD flags, jsval_t val)
+HRESULT jsdisp_propput(jsdisp_t *obj, const WCHAR *name, DWORD flags, BOOL throw, jsval_t val)
 {
     dispex_prop_t *prop;
     HRESULT hres;
@@ -2153,16 +2153,18 @@ HRESULT jsdisp_propput(jsdisp_t *obj, const WCHAR *name, DWORD flags, jsval_t va
     if(obj->extensible)
         hres = ensure_prop_name(obj, name, flags, &prop);
     else
-        hres = find_prop_name_prot(obj, string_hash(name), name, &prop);
-    if(FAILED(hres) || !prop)
+        hres = find_prop_name(obj, string_hash(name), name, &prop);
+    if(FAILED(hres))
         return hres;
+    if(!prop || (prop->type == PROP_DELETED && !obj->extensible))
+        return throw ? JS_E_INVALID_ACTION : S_OK;
 
     return prop_put(obj, prop, val);
 }
 
 HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
 {
-    return jsdisp_propput(obj, name, PROPF_ENUMERABLE | PROPF_CONFIGURABLE | PROPF_WRITABLE, val);
+    return jsdisp_propput(obj, name, PROPF_ENUMERABLE | PROPF_CONFIGURABLE | PROPF_WRITABLE, FALSE, val);
 }
 
 HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
@@ -2170,7 +2172,7 @@ HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
     WCHAR buf[12];
 
     swprintf(buf, ARRAY_SIZE(buf), L"%d", idx);
-    return jsdisp_propput_name(obj, buf, val);
+    return jsdisp_propput(obj, buf, PROPF_ENUMERABLE | PROPF_CONFIGURABLE | PROPF_WRITABLE, TRUE, val);
 }
 
 HRESULT disp_propput(script_ctx_t *ctx, IDispatch *disp, DISPID id, jsval_t val)
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 7a6dd4b61f3..318d6be6da7 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -206,7 +206,7 @@ HRESULT setup_arguments_object(script_ctx_t *ctx, call_frame_t *frame)
         hres = jsdisp_define_data_property(&args->jsdisp, L"callee", PROPF_WRITABLE | PROPF_CONFIGURABLE,
                                            jsval_obj(&args->function->function.dispex));
     if(SUCCEEDED(hres))
-        hres = jsdisp_propput(frame->base_scope->jsobj, L"arguments", PROPF_WRITABLE, jsval_obj(&args->jsdisp));
+        hres = jsdisp_propput(frame->base_scope->jsobj, L"arguments", PROPF_WRITABLE, TRUE, jsval_obj(&args->jsdisp));
     if(FAILED(hres)) {
         jsdisp_release(&args->jsdisp);
         return hres;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 3999f04a970..ec5001af117 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -303,7 +303,7 @@ HRESULT disp_propget(script_ctx_t*,IDispatch*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,jsval_t) DECLSPEC_HIDDEN;
 HRESULT disp_propput_name(script_ctx_t*,IDispatch*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
 HRESULT jsdisp_propget(jsdisp_t*,DISPID,jsval_t*) DECLSPEC_HIDDEN;
-HRESULT jsdisp_propput(jsdisp_t*,const WCHAR*,DWORD,jsval_t) DECLSPEC_HIDDEN;
+HRESULT jsdisp_propput(jsdisp_t*,const WCHAR*,DWORD,BOOL,jsval_t) DECLSPEC_HIDDEN;
 HRESULT jsdisp_propput_name(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
 HRESULT jsdisp_propput_idx(jsdisp_t*,DWORD,jsval_t) DECLSPEC_HIDDEN;
 HRESULT jsdisp_propget_name(jsdisp_t*,LPCWSTR,jsval_t*) DECLSPEC_HIDDEN;
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 6099c4090f3..f81eefdfd47 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -979,6 +979,23 @@ sync_test("preventExtensions", function() {
         ok(e.name === "TypeError", "got " + e.name + " exception");
     }
 
+    o = [];
+    Object.preventExtensions(o);
+    try {
+        o.push(1);
+        ok(false, "exception expected on o.push");
+    }catch(e) {
+        ok(e.name === "TypeError", "got " + e.name + " exception");
+    }
+    ok(!("0" in o), "0 is in o");
+    ok(o.length === 0, "o.length = " + o.length);
+
+    o = [1];
+    Object.preventExtensions(o);
+    o.pop();
+    ok(!("0" in o), "0 is in o");
+    ok(o.length === 0, "o.length = " + o.length);
+
     ok(Object.preventExtensions.length === 1, "Object.preventExtensions.length = " + Object.preventExtensions.length);
     ok(Object.isExtensible.length === 1, "Object.isExtensible.length = " + Object.isExtensible.length);
 });
@@ -1022,6 +1039,19 @@ sync_test("freeze", function() {
     ok(r === 2, "r = " + r);
     r = 3;
     ok(o.accprop === 3, "o.accprop = " + o.accprop);
+
+    o = [1];
+    Object.freeze(o);
+    try {
+        o.pop();
+        todo_wine.
+        ok(false, "exception expected on o.pop");
+    }catch(e) {
+        ok(e.name === "TypeError", "got " + e.name + " exception");
+    }
+    ok(o[0] === 1, "o[0] = " + o[0]);
+    todo_wine.
+    ok(o.length === 1, "o.length = " + o.length);
 });
 
 sync_test("seal", function() {
@@ -1063,6 +1093,19 @@ sync_test("seal", function() {
     ok(r === 2, "r = " + r);
     r = 3;
     ok(o.accprop === 3, "o.accprop = " + o.accprop);
+
+    o = [1];
+    Object.seal(o);
+    try {
+        o.pop();
+        todo_wine.
+       ok(false, "exception expected on o.pop");
+    }catch(e) {
+        ok(e.name === "TypeError", "got " + e.name + " exception");
+    }
+    ok(o[0] === 1, "o[0] = " + o[0]);
+    todo_wine.
+    ok(o.length === 1, "o.length = " + o.length);
 });
 
 sync_test("head_setter", function() {




More information about the wine-cvs mailing list