|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
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/. */ |
|
7 |
|
8 #include "jsapi-tests/tests.h" |
|
9 |
|
10 static bool |
|
11 NativeGetterSetter(JSContext *cx, unsigned argc, jsval *vp) |
|
12 { |
|
13 return true; |
|
14 } |
|
15 |
|
16 BEGIN_TEST(testDefineGetterSetterNonEnumerable) |
|
17 { |
|
18 static const char PROPERTY_NAME[] = "foo"; |
|
19 |
|
20 JS::RootedValue vobj(cx); |
|
21 JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); |
|
22 CHECK(obj); |
|
23 vobj = OBJECT_TO_JSVAL(obj); |
|
24 |
|
25 JSFunction *funGet = JS_NewFunction(cx, NativeGetterSetter, 0, 0, JS::NullPtr(), "get"); |
|
26 CHECK(funGet); |
|
27 JS::RootedObject funGetObj(cx, JS_GetFunctionObject(funGet)); |
|
28 JS::RootedValue vget(cx, OBJECT_TO_JSVAL(funGetObj)); |
|
29 |
|
30 JSFunction *funSet = JS_NewFunction(cx, NativeGetterSetter, 1, 0, JS::NullPtr(), "set"); |
|
31 CHECK(funSet); |
|
32 JS::RootedObject funSetObj(cx, JS_GetFunctionObject(funSet)); |
|
33 JS::RootedValue vset(cx, OBJECT_TO_JSVAL(funSetObj)); |
|
34 |
|
35 JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj)); |
|
36 CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, |
|
37 JS::UndefinedHandleValue, |
|
38 JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_ENUMERATE, |
|
39 JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), |
|
40 JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); |
|
41 |
|
42 CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME, |
|
43 JS::UndefinedHandleValue, |
|
44 JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_PERMANENT, |
|
45 JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj), |
|
46 JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj))); |
|
47 |
|
48 JS::Rooted<JSPropertyDescriptor> desc(cx); |
|
49 CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, &desc)); |
|
50 CHECK(desc.object()); |
|
51 CHECK(desc.hasGetterObject()); |
|
52 CHECK(desc.hasSetterObject()); |
|
53 CHECK(desc.isPermanent()); |
|
54 CHECK(!desc.isEnumerable()); |
|
55 |
|
56 return true; |
|
57 } |
|
58 END_TEST(testDefineGetterSetterNonEnumerable) |