tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testPropCache.cpp (1397B)


      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 
     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,     // construct
     29    nullptr,     // trace
     30 };
     31 
     32 static const JSClass CounterClass = {
     33    "Counter", /* name */
     34    0,         /* flags */
     35    &CounterClassOps,
     36 };
     37 
     38 BEGIN_TEST(testPropCache_bug505798) {
     39  g_counter = 0;
     40  EXEC("var x = {};");
     41  CHECK(JS_DefineObject(cx, global, "y", &CounterClass, JSPROP_ENUMERATE));
     42  EXEC(
     43      "var arr = [x, y];\n"
     44      "for (var i = 0; i < arr.length; i++)\n"
     45      "    arr[i].p = 1;\n");
     46  CHECK_EQUAL(g_counter, 1);
     47  return true;
     48 }
     49 END_TEST(testPropCache_bug505798)