Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 "jsatom.h"
7 #include "gc/Marking.h"
8 #include "jsapi-tests/tests.h"
9 #include "vm/String.h"
11 using mozilla::ArrayLength;
13 BEGIN_TEST(testAtomizedIsNotInterned)
14 {
15 /* Try to pick a string that won't be interned by other tests in this runtime. */
16 static const char someChars[] = "blah blah blah? blah blah blah";
17 JS::Rooted<JSAtom*> atom(cx, js::Atomize(cx, someChars, ArrayLength(someChars)));
18 CHECK(!JS_StringHasBeenInterned(cx, atom));
19 CHECK(JS_InternJSString(cx, atom));
20 CHECK(JS_StringHasBeenInterned(cx, atom));
21 return true;
22 }
23 END_TEST(testAtomizedIsNotInterned)
25 struct StringWrapperStruct
26 {
27 JSString *str;
28 bool strOk;
29 } sw;
31 BEGIN_TEST(testInternAcrossGC)
32 {
33 sw.str = JS_InternString(cx, "wrapped chars that another test shouldn't be using");
34 sw.strOk = false;
35 CHECK(sw.str);
36 JS_SetFinalizeCallback(rt, FinalizeCallback);
37 JS_GC(rt);
38 CHECK(sw.strOk);
39 return true;
40 }
42 static void
43 FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC)
44 {
45 if (status == JSFINALIZE_GROUP_START)
46 sw.strOk = js::gc::IsStringMarked(&sw.str);
47 }
48 END_TEST(testInternAcrossGC)