Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "jsapi-tests/tests.h" |
michael@0 | 9 | |
michael@0 | 10 | static bool |
michael@0 | 11 | NativeGetterSetter(JSContext *cx, unsigned argc, jsval *vp) |
michael@0 | 12 | { |
michael@0 | 13 | return true; |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | BEGIN_TEST(testDefineGetterSetterNonEnumerable) |
michael@0 | 17 | { |
michael@0 | 18 | static const char PROPERTY_NAME[] = "foo"; |
michael@0 | 19 | |
michael@0 | 20 | JS::RootedValue vobj(cx); |
michael@0 | 21 | JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); |
michael@0 | 22 | CHECK(obj); |
michael@0 | 23 | vobj = OBJECT_TO_JSVAL(obj); |
michael@0 | 24 | |
michael@0 | 25 | JSFunction *funGet = JS_NewFunction(cx, NativeGetterSetter, 0, 0, JS::NullPtr(), "get"); |
michael@0 | 26 | CHECK(funGet); |
michael@0 | 27 | JS::RootedObject funGetObj(cx, JS_GetFunctionObject(funGet)); |
michael@0 | 28 | JS::RootedValue vget(cx, OBJECT_TO_JSVAL(funGetObj)); |
michael@0 | 29 | |
michael@0 | 30 | JSFunction *funSet = JS_NewFunction(cx, NativeGetterSetter, 1, 0, JS::NullPtr(), "set"); |
michael@0 | 31 | CHECK(funSet); |
michael@0 | 32 | JS::RootedObject funSetObj(cx, JS_GetFunctionObject(funSet)); |
michael@0 | 33 | JS::RootedValue vset(cx, OBJECT_TO_JSVAL(funSetObj)); |
michael@0 | 34 | |
michael@0 | 35 | JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj)); |
michael@0 | 36 | CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, |
michael@0 | 37 | JS::UndefinedHandleValue, |
michael@0 | 38 | JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_ENUMERATE, |
michael@0 | 39 | JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), |
michael@0 | 40 | JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); |
michael@0 | 41 | |
michael@0 | 42 | CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, |
michael@0 | 43 | JS::UndefinedHandleValue, |
michael@0 | 44 | JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_PERMANENT, |
michael@0 | 45 | JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), |
michael@0 | 46 | JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); |
michael@0 | 47 | |
michael@0 | 48 | JS::Rooted<JSPropertyDescriptor> desc(cx); |
michael@0 | 49 | CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, &desc)); |
michael@0 | 50 | CHECK(desc.object()); |
michael@0 | 51 | CHECK(desc.hasGetterObject()); |
michael@0 | 52 | CHECK(desc.hasSetterObject()); |
michael@0 | 53 | CHECK(desc.isPermanent()); |
michael@0 | 54 | CHECK(!desc.isEnumerable()); |
michael@0 | 55 | |
michael@0 | 56 | return true; |
michael@0 | 57 | } |
michael@0 | 58 | END_TEST(testDefineGetterSetterNonEnumerable) |