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

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-04-02 20:24:18 +02:00 committed by Alexandre Julliard
parent 5bc629a3e1
commit 380ae426a4
4 changed files with 52 additions and 7 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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() {