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 "js/PropertyDescriptor.h" // JS_GetOwnPropertyDescriptor
10 #include "jsapi-tests/tests.h"
12 static bool NativeGetterSetter(JSContext
* cx
, unsigned argc
, JS::Value
* vp
) {
16 BEGIN_TEST(testDefineGetterSetterNonEnumerable
) {
17 static const char PROPERTY_NAME
[] = "foo";
19 JS::RootedValue
vobj(cx
);
20 JS::RootedObject
obj(cx
, JS_NewPlainObject(cx
));
24 JSFunction
* funGet
= JS_NewFunction(cx
, NativeGetterSetter
, 0, 0, "get");
26 JS::RootedObject
funGetObj(cx
, JS_GetFunctionObject(funGet
));
27 JS::RootedValue
vget(cx
, JS::ObjectValue(*funGetObj
));
29 JSFunction
* funSet
= JS_NewFunction(cx
, NativeGetterSetter
, 1, 0, "set");
31 JS::RootedObject
funSetObj(cx
, JS_GetFunctionObject(funSet
));
32 JS::RootedValue
vset(cx
, JS::ObjectValue(*funSetObj
));
34 JS::RootedObject
vObject(cx
, vobj
.toObjectOrNull());
35 CHECK(JS_DefineProperty(cx
, vObject
, PROPERTY_NAME
, funGetObj
, funSetObj
,
38 CHECK(JS_DefineProperty(cx
, vObject
, PROPERTY_NAME
, funGetObj
, funSetObj
,
41 JS::Rooted
<mozilla::Maybe
<JS::PropertyDescriptor
>> desc(cx
);
42 CHECK(JS_GetOwnPropertyDescriptor(cx
, vObject
, PROPERTY_NAME
, &desc
));
44 CHECK(desc
->hasGetter());
45 CHECK(desc
->hasSetter());
46 CHECK(!desc
->configurable());
47 CHECK(!desc
->enumerable());
51 END_TEST(testDefineGetterSetterNonEnumerable
)