js/src/jsapi-tests/testIntern.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "jsatom.h"
michael@0 6
michael@0 7 #include "gc/Marking.h"
michael@0 8 #include "jsapi-tests/tests.h"
michael@0 9 #include "vm/String.h"
michael@0 10
michael@0 11 using mozilla::ArrayLength;
michael@0 12
michael@0 13 BEGIN_TEST(testAtomizedIsNotInterned)
michael@0 14 {
michael@0 15 /* Try to pick a string that won't be interned by other tests in this runtime. */
michael@0 16 static const char someChars[] = "blah blah blah? blah blah blah";
michael@0 17 JS::Rooted<JSAtom*> atom(cx, js::Atomize(cx, someChars, ArrayLength(someChars)));
michael@0 18 CHECK(!JS_StringHasBeenInterned(cx, atom));
michael@0 19 CHECK(JS_InternJSString(cx, atom));
michael@0 20 CHECK(JS_StringHasBeenInterned(cx, atom));
michael@0 21 return true;
michael@0 22 }
michael@0 23 END_TEST(testAtomizedIsNotInterned)
michael@0 24
michael@0 25 struct StringWrapperStruct
michael@0 26 {
michael@0 27 JSString *str;
michael@0 28 bool strOk;
michael@0 29 } sw;
michael@0 30
michael@0 31 BEGIN_TEST(testInternAcrossGC)
michael@0 32 {
michael@0 33 sw.str = JS_InternString(cx, "wrapped chars that another test shouldn't be using");
michael@0 34 sw.strOk = false;
michael@0 35 CHECK(sw.str);
michael@0 36 JS_SetFinalizeCallback(rt, FinalizeCallback);
michael@0 37 JS_GC(rt);
michael@0 38 CHECK(sw.strOk);
michael@0 39 return true;
michael@0 40 }
michael@0 41
michael@0 42 static void
michael@0 43 FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartmentGC)
michael@0 44 {
michael@0 45 if (status == JSFINALIZE_GROUP_START)
michael@0 46 sw.strOk = js::gc::IsStringMarked(&sw.str);
michael@0 47 }
michael@0 48 END_TEST(testInternAcrossGC)

mercurial