From 2e767e81cc1682597b3d42a0ca1dcebdf909aaaa Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 5 Jun 2020 18:26:39 +0200 Subject: [PATCH] jscript: Add Object.preventExtensions semi-stub implementation. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/object.c | 24 +++++++++++++++++++++++- dlls/mshtml/tests/es5.js | 23 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c index bac79ebde26..1e94f163446 100644 --- a/dlls/jscript/object.c +++ b/dlls/jscript/object.c @@ -671,13 +671,35 @@ static HRESULT Object_keys(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, return hres; } +static HRESULT Object_preventExtensions(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) +{ + jsdisp_t *obj; + + if(!argc || !is_object_instance(argv[0]) || !get_object(argv[0])) { + FIXME("invalid arguments\n"); + return E_NOTIMPL; + } + + FIXME("(%s) semi-stub\n", debugstr_jsval(argv[0])); + + obj = to_jsdisp(get_object(argv[0])); + if(!obj) { + FIXME("Non-JS object\n"); + return E_NOTIMPL; + } + + if(r) *r = jsval_obj(jsdisp_addref(obj)); + return S_OK; +} + static const builtin_prop_t ObjectConstr_props[] = { {L"create", Object_create, PROPF_ES5|PROPF_METHOD|2}, {L"defineProperties", Object_defineProperties, PROPF_ES5|PROPF_METHOD|2}, {L"defineProperty", Object_defineProperty, PROPF_ES5|PROPF_METHOD|2}, {L"getOwnPropertyDescriptor", Object_getOwnPropertyDescriptor, PROPF_ES5|PROPF_METHOD|2}, {L"getPrototypeOf", Object_getPrototypeOf, PROPF_ES5|PROPF_METHOD|1}, - {L"keys", Object_keys, PROPF_ES5|PROPF_METHOD|1} + {L"keys", Object_keys, PROPF_ES5|PROPF_METHOD|1}, + {L"preventExtensions", Object_preventExtensions, PROPF_ES5|PROPF_METHOD|1}, }; static const builtin_info_t ObjectConstr_info = { diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index f268eba24c6..ded25df5128 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -924,7 +924,28 @@ sync_test("reduce", function() { try { [].reduce(function(a) { return 0; }); ok(false, "expected exception"); - }catch(e) {trace(e.message);} + }catch(e) {} ok(Array.prototype.reduce.length === 1, "Array.prototype.reduce.length = " + Array.prototype.reduce.length); }); + +sync_test("preventExtensions", function() { + var o = {}; + var r = Object.preventExtensions(o); + ok(r === o, "r != o"); + o.x = 1; + todo_wine. + ok(!("x" in o), "x property added to o"); + try { + Object.defineProperty(o, "y", { value: true }); + todo_wine. + ok(false, "expected exception"); + }catch(e) { + ok(e.name === "TypeError", "got " + e.name + " exception"); + } + + r = Object.preventExtensions(o); + ok(r === o, "r != o"); + + ok(Object.preventExtensions.length === 1, "Object.preventExtensions.length = " + Object.preventExtensions.length); +});