summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testExternalStrings.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testExternalStrings.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testExternalStrings.cpp')
-rw-r--r--js/src/jsapi-tests/testExternalStrings.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testExternalStrings.cpp b/js/src/jsapi-tests/testExternalStrings.cpp
new file mode 100644
index 000000000..9aca388b3
--- /dev/null
+++ b/js/src/jsapi-tests/testExternalStrings.cpp
@@ -0,0 +1,61 @@
+/* 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 "mozilla/ArrayUtils.h"
+#include "mozilla/PodOperations.h"
+
+#include "jsapi-tests/tests.h"
+
+using mozilla::ArrayLength;
+using mozilla::PodEqual;
+
+static const char16_t arr[] = {
+ 'h', 'i', ',', 'd', 'o', 'n', '\'', 't', ' ', 'd', 'e', 'l', 'e', 't', 'e', ' ', 'm', 'e', '\0'
+};
+static const size_t arrlen = ArrayLength(arr) - 1;
+
+static int finalized1 = 0;
+static int finalized2 = 0;
+
+static void
+finalize_str(JS::Zone* zone, const JSStringFinalizer* fin, char16_t* chars);
+
+static const JSStringFinalizer finalizer1 = { finalize_str };
+static const JSStringFinalizer finalizer2 = { finalize_str };
+
+static void
+finalize_str(JS::Zone* zone, const JSStringFinalizer* fin, char16_t* chars)
+{
+ if (chars && PodEqual(const_cast<const char16_t*>(chars), arr, arrlen)) {
+ if (fin == &finalizer1) {
+ ++finalized1;
+ } else if (fin == &finalizer2) {
+ ++finalized2;
+ }
+ }
+}
+
+BEGIN_TEST(testExternalStrings)
+{
+ const unsigned N = 1000;
+
+ for (unsigned i = 0; i < N; ++i) {
+ CHECK(JS_NewExternalString(cx, arr, arrlen, &finalizer1));
+ CHECK(JS_NewExternalString(cx, arr, arrlen, &finalizer2));
+ }
+
+ // clear that newborn root
+ JS_NewUCStringCopyN(cx, arr, arrlen);
+
+ JS_GC(cx);
+
+ // a generous fudge factor to account for strings rooted by conservative gc
+ const unsigned epsilon = 10;
+
+ CHECK((N - finalized1) < epsilon);
+ CHECK((N - finalized2) < epsilon);
+
+ return true;
+}
+END_TEST(testExternalStrings)