1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testDefineGetterSetterNonEnumerable.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "jsapi-tests/tests.h" 1.12 + 1.13 +static bool 1.14 +NativeGetterSetter(JSContext *cx, unsigned argc, jsval *vp) 1.15 +{ 1.16 + return true; 1.17 +} 1.18 + 1.19 +BEGIN_TEST(testDefineGetterSetterNonEnumerable) 1.20 +{ 1.21 + static const char PROPERTY_NAME[] = "foo"; 1.22 + 1.23 + JS::RootedValue vobj(cx); 1.24 + JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); 1.25 + CHECK(obj); 1.26 + vobj = OBJECT_TO_JSVAL(obj); 1.27 + 1.28 + JSFunction *funGet = JS_NewFunction(cx, NativeGetterSetter, 0, 0, JS::NullPtr(), "get"); 1.29 + CHECK(funGet); 1.30 + JS::RootedObject funGetObj(cx, JS_GetFunctionObject(funGet)); 1.31 + JS::RootedValue vget(cx, OBJECT_TO_JSVAL(funGetObj)); 1.32 + 1.33 + JSFunction *funSet = JS_NewFunction(cx, NativeGetterSetter, 1, 0, JS::NullPtr(), "set"); 1.34 + CHECK(funSet); 1.35 + JS::RootedObject funSetObj(cx, JS_GetFunctionObject(funSet)); 1.36 + JS::RootedValue vset(cx, OBJECT_TO_JSVAL(funSetObj)); 1.37 + 1.38 + JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj)); 1.39 + CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, 1.40 + JS::UndefinedHandleValue, 1.41 + JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_ENUMERATE, 1.42 + JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), 1.43 + JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); 1.44 + 1.45 + CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, 1.46 + JS::UndefinedHandleValue, 1.47 + JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_PERMANENT, 1.48 + JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), 1.49 + JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); 1.50 + 1.51 + JS::Rooted<JSPropertyDescriptor> desc(cx); 1.52 + CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, &desc)); 1.53 + CHECK(desc.object()); 1.54 + CHECK(desc.hasGetterObject()); 1.55 + CHECK(desc.hasSetterObject()); 1.56 + CHECK(desc.isPermanent()); 1.57 + CHECK(!desc.isEnumerable()); 1.58 + 1.59 + return true; 1.60 +} 1.61 +END_TEST(testDefineGetterSetterNonEnumerable)