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
10 #include "jsapi-tests/tests.h"
12 class WindowProxyHandler
: public js::ForwardingProxyHandler
{
14 constexpr WindowProxyHandler() : js::ForwardingProxyHandler(&family
) {}
16 static const char family
;
18 virtual bool defineProperty(JSContext
* cx
, JS::HandleObject proxy
,
20 JS::Handle
<JS::PropertyDescriptor
> desc
,
21 JS::ObjectOpResult
& result
) const override
{
22 if (desc
.hasConfigurable() && !desc
.configurable()) {
23 result
.failCantDefineWindowNonConfigurable();
26 return ForwardingProxyHandler::defineProperty(cx
, proxy
, id
, desc
, result
);
29 const char WindowProxyHandler::family
= 0;
31 static const JSClass windowProxy_class
=
32 PROXY_CLASS_DEF("TestWindowProxy", JSCLASS_HAS_RESERVED_SLOTS(1));
33 static const WindowProxyHandler windowProxy_handler
;
35 BEGIN_TEST(testWindowNonConfigurable
) {
36 JS::RootedObject
wrapped(cx
, JS_NewObject(cx
, nullptr));
38 JS::RootedValue
wrappedVal(cx
, JS::ObjectValue(*wrapped
));
39 js::ProxyOptions options
;
40 options
.setClass(&windowProxy_class
);
41 JS::RootedObject
obj(cx
, NewProxyObject(cx
, &windowProxy_handler
, wrappedVal
,
44 CHECK(JS_DefineProperty(cx
, global
, "windowProxy", obj
, 0));
45 JS::RootedValue
v(cx
);
47 "Object.defineProperty(windowProxy, 'bar', {value: 1, configurable: "
50 CHECK(v
.isNull()); // This is the important bit!
52 "Object.defineProperty(windowProxy, 'bar', {value: 1, configurable: "
55 CHECK(&v
.toObject() == obj
);
57 "Reflect.defineProperty(windowProxy, 'foo', {value: 1, configurable: "
62 "Reflect.defineProperty(windowProxy, 'foo', {value: 1, configurable: "
69 END_TEST(testWindowNonConfigurable
)