tor-browser

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

testAtomizeWithoutActiveZone.cpp (1430B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "js/Realm.h"
      6 #include "js/RootingAPI.h"
      7 #include "jsapi-tests/tests.h"
      8 #include "vm/CommonPropertyNames.h"
      9 #include "vm/JSAtomState.h"
     10 #include "vm/JSContext.h"
     11 
     12 BEGIN_TEST(testAtomizeWithoutActiveZone) {
     13  // Tests for JS_AtomizeAndPinString when called without an active zone.
     14 
     15  MOZ_ASSERT(cx->zone());
     16 
     17  JS::RootedString testAtom1(cx, JS_AtomizeString(cx, "test1234@!"));
     18  CHECK(testAtom1);
     19 
     20  JS::RootedString testAtom2(cx);
     21  {
     22    JSAutoNullableRealm ar(cx, nullptr);
     23    MOZ_ASSERT(!cx->zone());
     24 
     25    // Permanent atom.
     26    JSString* atom = JS_AtomizeAndPinString(cx, "boolean");
     27    CHECK(atom);
     28    CHECK_EQUAL(atom, cx->names().boolean);
     29 
     30    // Static string.
     31    atom = JS_AtomizeAndPinString(cx, "8");
     32    CHECK(atom);
     33    CHECK_EQUAL(atom, cx->staticStrings().getUint(8));
     34 
     35    // Existing atom.
     36    atom = JS_AtomizeAndPinString(cx, "test1234@!");
     37    CHECK(atom);
     38    CHECK_EQUAL(atom, testAtom1);
     39 
     40    // New atom.
     41    testAtom2 = JS_AtomizeAndPinString(cx, "asdflkjsdf987_@");
     42    CHECK(testAtom2);
     43  }
     44 
     45  MOZ_ASSERT(cx->zone());
     46  JSString* atom = JS_AtomizeString(cx, "asdflkjsdf987_@");
     47  CHECK(atom);
     48  CHECK_EQUAL(atom, testAtom2);
     49 
     50  return true;
     51 }
     52 END_TEST(testAtomizeWithoutActiveZone)