1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: set ts=8 sts=2 et sw=2 tw=80:
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 "js/PropertyAndElement.h"  // JS_DefineObject
9 #include "jsapi-tests/tests.h"
10 
11 static int g_counter;
12 
CounterAdd(JSContext * cx,JS::HandleObject obj,JS::HandleId id,JS::HandleValue v)13 static bool CounterAdd(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
14                        JS::HandleValue v) {
15   g_counter++;
16   return true;
17 }
18 
19 static const JSClassOps CounterClassOps = {
20     CounterAdd,  // addProperty
21     nullptr,     // delProperty
22     nullptr,     // enumerate
23     nullptr,     // newEnumerate
24     nullptr,     // resolve
25     nullptr,     // mayResolve
26     nullptr,     // finalize
27     nullptr,     // call
28     nullptr,     // hasInstance
29     nullptr,     // construct
30     nullptr,     // trace
31 };
32 
33 static const JSClass CounterClass = {"Counter", /* name */
34                                      0,         /* flags */
35                                      &CounterClassOps};
36 
BEGIN_TEST(testPropCache_bug505798)37 BEGIN_TEST(testPropCache_bug505798) {
38   g_counter = 0;
39   EXEC("var x = {};");
40   CHECK(JS_DefineObject(cx, global, "y", &CounterClass, JSPROP_ENUMERATE));
41   EXEC(
42       "var arr = [x, y];\n"
43       "for (var i = 0; i < arr.length; i++)\n"
44       "    arr[i].p = 1;\n");
45   CHECK_EQUAL(g_counter, 1);
46   return true;
47 }
48 END_TEST(testPropCache_bug505798)
49