michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsatom.h" michael@0: michael@0: #include "gc/Marking.h" michael@0: #include "jsapi-tests/tests.h" michael@0: #include "vm/String.h" michael@0: michael@0: using mozilla::ArrayLength; michael@0: michael@0: BEGIN_TEST(testAtomizedIsNotInterned) michael@0: { michael@0: /* Try to pick a string that won't be interned by other tests in this runtime. */ michael@0: static const char someChars[] = "blah blah blah? blah blah blah"; michael@0: JS::Rooted atom(cx, js::Atomize(cx, someChars, ArrayLength(someChars))); michael@0: CHECK(!JS_StringHasBeenInterned(cx, atom)); michael@0: CHECK(JS_InternJSString(cx, atom)); michael@0: CHECK(JS_StringHasBeenInterned(cx, atom)); michael@0: return true; michael@0: } michael@0: END_TEST(testAtomizedIsNotInterned) michael@0: michael@0: struct StringWrapperStruct michael@0: { michael@0: JSString *str; michael@0: bool strOk; michael@0: } sw; michael@0: michael@0: BEGIN_TEST(testInternAcrossGC) michael@0: { michael@0: sw.str = JS_InternString(cx, "wrapped chars that another test shouldn't be using"); michael@0: sw.strOk = false; michael@0: CHECK(sw.str); michael@0: JS_SetFinalizeCallback(rt, FinalizeCallback); michael@0: JS_GC(rt); michael@0: CHECK(sw.strOk); michael@0: return true; michael@0: } michael@0: michael@0: static void michael@0: FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC) michael@0: { michael@0: if (status == JSFINALIZE_GROUP_START) michael@0: sw.strOk = js::gc::IsStringMarked(&sw.str); michael@0: } michael@0: END_TEST(testInternAcrossGC)