Bug 880697 - Add JSRuntime constructor for Rooted. r=terrence

This commit is contained in:
Bill McCloskey 2013-06-12 14:17:54 -07:00
parent c95b7cbaed
commit 0a3508d15a
3 changed files with 43 additions and 4 deletions

View File

@ -506,9 +506,8 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase<T>
#endif
}
void init(js::PerThreadData *ptArg) {
void init(js::PerThreadDataFriendFields *pt) {
#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
js::PerThreadDataFriendFields *pt = js::PerThreadDataFriendFields::get(ptArg);
commonInit(pt->thingGCRooters);
#endif
}
@ -535,7 +534,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase<T>
: ptr(js::RootMethods<T>::initial())
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
init(pt);
init(js::PerThreadDataFriendFields::get(pt));
}
Rooted(js::PerThreadData *pt, T initial
@ -543,7 +542,23 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase<T>
: ptr(initial)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
init(pt);
init(js::PerThreadDataFriendFields::get(pt));
}
Rooted(JSRuntime *rt
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(js::RootMethods<T>::initial())
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
init(js::PerThreadDataFriendFields::getMainThread(rt));
}
Rooted(JSRuntime *rt, T initial
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(initial)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
init(js::PerThreadDataFriendFields::getMainThread(rt));
}
~Rooted() {

View File

@ -31,6 +31,7 @@ CPP_SOURCES += [
'testFindSCCs.cpp',
'testFuncCallback.cpp',
'testFunctionProperties.cpp',
'testGCExactRooting.cpp',
'testGCFinalizeCallback.cpp',
'testGCOutOfMemory.cpp',
'testGetPropertyDefault.cpp',

View File

@ -0,0 +1,23 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sts=4 et sw=4 tw=99:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "tests.h"
BEGIN_TEST(testGCExactRooting)
{
JS::RootedObject rootCx(cx, JS_NewObject(cx, NULL, NULL, NULL));
JS::RootedObject rootRt(cx->runtime(), JS_NewObject(cx, NULL, NULL, NULL));
JS_GC(cx->runtime());
/* Use the objects we just created to ensure that they are still alive. */
JS_DefineProperty(cx, rootCx, "foo", JS::DoubleValue(0), NULL, NULL, 0);
JS_DefineProperty(cx, rootRt, "foo", JS::DoubleValue(0), NULL, NULL, 0);
return true;
}
END_TEST(testGCExactRooting)