Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testAtomizeWithoutActiveZone.cpp
blob5f4ff36f3e2056f8d039466f01a25ac2e4583972
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/. */
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"
12 BEGIN_TEST(testAtomizeWithoutActiveZone) {
13 // Tests for JS_AtomizeAndPinString when called without an active zone.
15 MOZ_ASSERT(cx->zone());
17 JS::RootedString testAtom1(cx, JS_AtomizeString(cx, "test1234@!"));
18 CHECK(testAtom1);
20 JS::RootedString testAtom2(cx);
22 JSAutoNullableRealm ar(cx, nullptr);
23 MOZ_ASSERT(!cx->zone());
25 // Permanent atom.
26 JSString* atom = JS_AtomizeAndPinString(cx, "boolean");
27 CHECK(atom);
28 CHECK_EQUAL(atom, cx->names().boolean);
30 // Static string.
31 atom = JS_AtomizeAndPinString(cx, "8");
32 CHECK(atom);
33 CHECK_EQUAL(atom, cx->staticStrings().getUint(8));
35 // Existing atom.
36 atom = JS_AtomizeAndPinString(cx, "test1234@!");
37 CHECK(atom);
38 CHECK_EQUAL(atom, testAtom1);
40 // New atom.
41 testAtom2 = JS_AtomizeAndPinString(cx, "asdflkjsdf987_@");
42 CHECK(testAtom2);
45 MOZ_ASSERT(cx->zone());
46 JSString* atom = JS_AtomizeString(cx, "asdflkjsdf987_@");
47 CHECK(atom);
48 CHECK_EQUAL(atom, testAtom2);
50 return true;
52 END_TEST(testAtomizeWithoutActiveZone)