1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=99:
9 nativeGet(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
11 *vp = INT_TO_JSVAL(17);
15 BEGIN_TEST(testSetProperty_NativeGetterStubSetter)
18 JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
20 vobj = OBJECT_TO_JSVAL(obj);
22 CHECK(JS_DefineProperty(cx, global, "globalProp", vobj,
23 JS_PropertyStub, JS_StrictPropertyStub,
26 CHECK(JS_DefineProperty(cx, obj, "prop", JSVAL_VOID,
27 nativeGet, JS_StrictPropertyStub,
30 EXEC("'use strict'; \n"
31 "var error, passed = false; \n"
34 " this.globalProp.prop = 42; \n"
35 " throw new Error('setting property succeeded!'); \n"
40 " if (e instanceof TypeError) \n"
47 EXEC("var error, passed = false; \n"
50 " this.globalProp.prop = 42; \n"
51 " if (this.globalProp.prop === 17) \n"
54 " throw new Error('bad value after set!'); \n"
66 END_TEST(testSetProperty_NativeGetterStubSetter)
68 BEGIN_TEST(testSetProperty_InheritedGlobalSetter)
70 // This is a JSAPI test because jsapi-test globals do not have a resolve
71 // hook and therefore can use the property cache in some cases where the
73 JS_ASSERT(JS_GET_CLASS(cx, global)->resolve == &JS_ResolveStub);
75 CHECK(JS_DefineProperty(cx, global, "HOTLOOP", INT_TO_JSVAL(8), NULL, NULL, 0));
77 "var global = this;\n"
78 "function f() { n++; }\n"
79 "Object.defineProperty(Object.prototype, 'x', {set: f});\n"
80 "for (var i = 0; i < HOTLOOP; i++)\n"
82 EXEC("if (n != HOTLOOP)\n"
86 END_TEST(testSetProperty_InheritedGlobalSetter)