Bug 1716030 [wpt PR 29346] - Update wpt metadata, a=testonly
[gecko.git] / js / src / jsapi-tests / testDefineGetterSetterNonEnumerable.cpp
blob37c57fb3c32f2459d24ae1e733a47667181baf0e
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:
3 */
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) {
13 return true;
16 BEGIN_TEST(testDefineGetterSetterNonEnumerable) {
17 static const char PROPERTY_NAME[] = "foo";
19 JS::RootedValue vobj(cx);
20 JS::RootedObject obj(cx, JS_NewPlainObject(cx));
21 CHECK(obj);
22 vobj.setObject(*obj);
24 JSFunction* funGet = JS_NewFunction(cx, NativeGetterSetter, 0, 0, "get");
25 CHECK(funGet);
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");
30 CHECK(funSet);
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,
36 JSPROP_ENUMERATE));
38 CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, funGetObj, funSetObj,
39 JSPROP_PERMANENT));
41 JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> desc(cx);
42 CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, &desc));
43 CHECK(desc.isSome());
44 CHECK(desc->hasGetter());
45 CHECK(desc->hasSetter());
46 CHECK(!desc->configurable());
47 CHECK(!desc->enumerable());
49 return true;
51 END_TEST(testDefineGetterSetterNonEnumerable)