1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testIntern.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "jsatom.h" 1.9 + 1.10 +#include "gc/Marking.h" 1.11 +#include "jsapi-tests/tests.h" 1.12 +#include "vm/String.h" 1.13 + 1.14 +using mozilla::ArrayLength; 1.15 + 1.16 +BEGIN_TEST(testAtomizedIsNotInterned) 1.17 +{ 1.18 + /* Try to pick a string that won't be interned by other tests in this runtime. */ 1.19 + static const char someChars[] = "blah blah blah? blah blah blah"; 1.20 + JS::Rooted<JSAtom*> atom(cx, js::Atomize(cx, someChars, ArrayLength(someChars))); 1.21 + CHECK(!JS_StringHasBeenInterned(cx, atom)); 1.22 + CHECK(JS_InternJSString(cx, atom)); 1.23 + CHECK(JS_StringHasBeenInterned(cx, atom)); 1.24 + return true; 1.25 +} 1.26 +END_TEST(testAtomizedIsNotInterned) 1.27 + 1.28 +struct StringWrapperStruct 1.29 +{ 1.30 + JSString *str; 1.31 + bool strOk; 1.32 +} sw; 1.33 + 1.34 +BEGIN_TEST(testInternAcrossGC) 1.35 +{ 1.36 + sw.str = JS_InternString(cx, "wrapped chars that another test shouldn't be using"); 1.37 + sw.strOk = false; 1.38 + CHECK(sw.str); 1.39 + JS_SetFinalizeCallback(rt, FinalizeCallback); 1.40 + JS_GC(rt); 1.41 + CHECK(sw.strOk); 1.42 + return true; 1.43 +} 1.44 + 1.45 +static void 1.46 +FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC) 1.47 +{ 1.48 + if (status == JSFINALIZE_GROUP_START) 1.49 + sw.strOk = js::gc::IsStringMarked(&sw.str); 1.50 +} 1.51 +END_TEST(testInternAcrossGC)