summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testAtomizeWithoutActiveZone.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jsapi-tests/testAtomizeWithoutActiveZone.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jsapi-tests/testAtomizeWithoutActiveZone.cpp')
-rw-r--r--js/src/jsapi-tests/testAtomizeWithoutActiveZone.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testAtomizeWithoutActiveZone.cpp b/js/src/jsapi-tests/testAtomizeWithoutActiveZone.cpp
new file mode 100644
index 0000000000..5f4ff36f3e
--- /dev/null
+++ b/js/src/jsapi-tests/testAtomizeWithoutActiveZone.cpp
@@ -0,0 +1,52 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "js/Realm.h"
+#include "js/RootingAPI.h"
+#include "jsapi-tests/tests.h"
+#include "vm/CommonPropertyNames.h"
+#include "vm/JSAtomState.h"
+#include "vm/JSContext.h"
+
+BEGIN_TEST(testAtomizeWithoutActiveZone) {
+ // Tests for JS_AtomizeAndPinString when called without an active zone.
+
+ MOZ_ASSERT(cx->zone());
+
+ JS::RootedString testAtom1(cx, JS_AtomizeString(cx, "test1234@!"));
+ CHECK(testAtom1);
+
+ JS::RootedString testAtom2(cx);
+ {
+ JSAutoNullableRealm ar(cx, nullptr);
+ MOZ_ASSERT(!cx->zone());
+
+ // Permanent atom.
+ JSString* atom = JS_AtomizeAndPinString(cx, "boolean");
+ CHECK(atom);
+ CHECK_EQUAL(atom, cx->names().boolean);
+
+ // Static string.
+ atom = JS_AtomizeAndPinString(cx, "8");
+ CHECK(atom);
+ CHECK_EQUAL(atom, cx->staticStrings().getUint(8));
+
+ // Existing atom.
+ atom = JS_AtomizeAndPinString(cx, "test1234@!");
+ CHECK(atom);
+ CHECK_EQUAL(atom, testAtom1);
+
+ // New atom.
+ testAtom2 = JS_AtomizeAndPinString(cx, "asdflkjsdf987_@");
+ CHECK(testAtom2);
+ }
+
+ MOZ_ASSERT(cx->zone());
+ JSString* atom = JS_AtomizeString(cx, "asdflkjsdf987_@");
+ CHECK(atom);
+ CHECK_EQUAL(atom, testAtom2);
+
+ return true;
+}
+END_TEST(testAtomizeWithoutActiveZone)