testIntern.cpp (1533B)
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/. */ 4 5 #include "gc/GCContext.h" 6 #include "gc/Marking.h" 7 #include "jsapi-tests/tests.h" 8 #include "util/Text.h" 9 #include "vm/JSAtomUtils.h" // Atomize 10 #include "vm/StringType.h" 11 12 BEGIN_TEST(testAtomizedIsNotPinned) { 13 /* Try to pick a string that won't be interned by other tests in this runtime. 14 */ 15 static const char someChars[] = "blah blah blah? blah blah blah"; 16 JS::Rooted<JSAtom*> atom(cx, 17 js::Atomize(cx, someChars, js_strlen(someChars))); 18 CHECK(!JS_StringHasBeenPinned(cx, atom)); 19 20 JS::RootedString string(cx, JS_AtomizeAndPinString(cx, someChars)); 21 CHECK(string); 22 CHECK(string == atom); 23 24 CHECK(JS_StringHasBeenPinned(cx, atom)); 25 return true; 26 } 27 END_TEST(testAtomizedIsNotPinned) 28 29 struct StringWrapperStruct { 30 JSString* str; 31 bool strOk; 32 } sw; 33 34 BEGIN_TEST(testPinAcrossGC) { 35 sw.str = JS_AtomizeAndPinString( 36 cx, "wrapped chars that another test shouldn't be using"); 37 sw.strOk = false; 38 CHECK(sw.str); 39 JS_AddFinalizeCallback(cx, FinalizeCallback, nullptr); 40 JS_GC(cx); 41 CHECK(sw.strOk); 42 return true; 43 } 44 45 static void FinalizeCallback(JS::GCContext* gcx, JSFinalizeStatus status, 46 void* data) { 47 if (status == JSFINALIZE_GROUP_START) { 48 sw.strOk = js::gc::IsMarkedUnbarriered(gcx->runtime(), sw.str); 49 } 50 } 51 END_TEST(testPinAcrossGC)