1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "js/PropertyAndElement.h" // JS_DefineProperty
9 #include "jsapi-tests/tests.h"
11 static bool windowProxy_defineProperty(JSContext
* cx
, JS::HandleObject obj
,
13 JS::Handle
<JS::PropertyDescriptor
> desc
,
14 JS::ObjectOpResult
& result
) {
15 if (desc
.hasConfigurable() && !desc
.configurable()) {
16 result
.failCantDefineWindowNonConfigurable();
20 return NativeDefineProperty(cx
, obj
.as
<js::NativeObject
>(), id
, desc
, result
);
23 static const js::ObjectOps windowProxy_objectOps
= {
24 nullptr, // lookupProperty
25 windowProxy_defineProperty
, // defineProperty
26 nullptr, // hasProperty
27 nullptr, // getProperty
28 nullptr, // setProperty
29 nullptr, // getOwnPropertyDescriptor
30 nullptr, // deleteProperty
31 nullptr, // getElements
32 nullptr, // funToString
35 static const JSClass windowProxy_class
= {
36 "WindowProxy", 0, nullptr, nullptr, nullptr, &windowProxy_objectOps
};
38 BEGIN_TEST(testWindowNonConfigurable
) {
39 JS::RootedObject
obj(cx
, JS_NewObject(cx
, &windowProxy_class
));
41 CHECK(JS_DefineProperty(cx
, global
, "windowProxy", obj
, 0));
42 JS::RootedValue
v(cx
);
44 "Object.defineProperty(windowProxy, 'bar', {value: 1, configurable: "
47 CHECK(v
.isNull()); // This is the important bit!
49 "Object.defineProperty(windowProxy, 'bar', {value: 1, configurable: "
52 CHECK(&v
.toObject() == obj
);
54 "Reflect.defineProperty(windowProxy, 'foo', {value: 1, configurable: "
59 "Reflect.defineProperty(windowProxy, 'foo', {value: 1, configurable: "
66 END_TEST(testWindowNonConfigurable
)