michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: static bool michael@0: NativeGetterSetter(JSContext *cx, unsigned argc, jsval *vp) michael@0: { michael@0: return true; michael@0: } michael@0: michael@0: BEGIN_TEST(testDefineGetterSetterNonEnumerable) michael@0: { michael@0: static const char PROPERTY_NAME[] = "foo"; michael@0: michael@0: JS::RootedValue vobj(cx); michael@0: JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); michael@0: CHECK(obj); michael@0: vobj = OBJECT_TO_JSVAL(obj); michael@0: michael@0: JSFunction *funGet = JS_NewFunction(cx, NativeGetterSetter, 0, 0, JS::NullPtr(), "get"); michael@0: CHECK(funGet); michael@0: JS::RootedObject funGetObj(cx, JS_GetFunctionObject(funGet)); michael@0: JS::RootedValue vget(cx, OBJECT_TO_JSVAL(funGetObj)); michael@0: michael@0: JSFunction *funSet = JS_NewFunction(cx, NativeGetterSetter, 1, 0, JS::NullPtr(), "set"); michael@0: CHECK(funSet); michael@0: JS::RootedObject funSetObj(cx, JS_GetFunctionObject(funSet)); michael@0: JS::RootedValue vset(cx, OBJECT_TO_JSVAL(funSetObj)); michael@0: michael@0: JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj)); michael@0: CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, michael@0: JS::UndefinedHandleValue, michael@0: JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_ENUMERATE, michael@0: JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), michael@0: JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); michael@0: michael@0: CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, michael@0: JS::UndefinedHandleValue, michael@0: JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_PERMANENT, michael@0: JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), michael@0: JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); michael@0: michael@0: JS::Rooted desc(cx); michael@0: CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, &desc)); michael@0: CHECK(desc.object()); michael@0: CHECK(desc.hasGetterObject()); michael@0: CHECK(desc.hasSetterObject()); michael@0: CHECK(desc.isPermanent()); michael@0: CHECK(!desc.isEnumerable()); michael@0: michael@0: return true; michael@0: } michael@0: END_TEST(testDefineGetterSetterNonEnumerable)