1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=99:
4 * Tests the JSClass::getProperty hook
10 int called_test_prop_get;
12 static JSBool test_prop_get( JSContext *cx, JSObject *obj, jsid id, jsval *vp )
14 called_test_prop_get++;
19 PTest(JSContext* cx, uintN argc, jsval *vp)
21 JSObject *obj = JS_NewObjectForConstructor(cx, vp);
24 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
28 static JSClass ptestClass = {
32 JS_PropertyStub, // add
33 JS_PropertyStub, // delete
35 JS_StrictPropertyStub, // set
40 JSCLASS_NO_OPTIONAL_MEMBERS
43 static JSBool test_fn(JSContext *cx, uintN argc, jsval *vp)
49 static JSFunctionSpec ptestFunctions[] = {
50 JS_FS( "test_fn", test_fn, 0, 0 ),
54 BEGIN_TEST(testClassGetter_isCalled)
56 CHECK(JS_InitClass(cx, JS_GetGlobalObject(cx), NULL, &ptestClass, PTest, 0,
57 NULL, ptestFunctions, NULL, NULL));
59 EXEC("function check() { var o = new PTest(); o.test_fn(); o.test_value1; o.test_value2; o.test_value1; }");
61 for (int i = 1; i < 9; i++) {
63 CHECK(JS_CallFunctionName(cx, global, "check", 0, NULL, rval.addr()));
64 CHECK_SAME(INT_TO_JSVAL(called_test_fn), INT_TO_JSVAL(i));
65 CHECK_SAME(INT_TO_JSVAL(called_test_prop_get), INT_TO_JSVAL(4 * i));
69 END_TEST(testClassGetter_isCalled)