Bug 1061909: Define a testing function to introduce easily traceable objects. r=fitzgen

This commit is contained in:
Jim Blandy 2015-06-28 13:11:06 -07:00
parent aced758ae0
commit 3f2037f66b
3 changed files with 36 additions and 15 deletions

View File

@ -2494,6 +2494,20 @@ GetConstructorName(JSContext* cx, unsigned argc, Value* vp)
return true;
}
static bool
AllocationMarker(JSContext* cx, unsigned argc, jsval* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
static const JSClass cls = { "AllocationMarker" };
RootedObject obj(cx, JS_NewObject(cx, &cls));
if (!obj)
return false;
args.rval().setObject(*obj);
return true;
}
static const JSFunctionSpecWithHelp TestingFunctions[] = {
JS_FN_HELP("gc", ::GC, 0, 0,
"gc([obj] | 'compartment' [, 'shrinking'])",
@ -2911,6 +2925,13 @@ gc::ZealModeHelpText),
" If the given object was created with `new Ctor`, return the constructor's display name. "
" Otherwise, return null."),
JS_FN_HELP("allocationMarker", AllocationMarker, 0, 0,
"allocationMarker()",
" Return a freshly allocated object whose [[Class]] name is\n"
" \"AllocationMarker\". Such objects are allocated only by calls\n"
" to this function, never implicitly by the system, making them\n"
" suitable for use in allocation tooling tests.\n"),
JS_FS_HELP_END
};

View File

@ -5,22 +5,22 @@ var g = newGlobal();
var dbg = new Debugger(g);
g.eval(`
function withTypedArrayOnStack(f) {
function withAllocationMarkerOnStack(f) {
(function () {
var onStack = new Int8Array();
var onStack = allocationMarker();
f();
}())
}
`);
assertEq("Int8Array" in dbg.memory.takeCensus().objects, false,
"There shouldn't exist any typed arrays in the census.");
assertEq("AllocationMarker" in dbg.memory.takeCensus().objects, false,
"There shouldn't exist any allocation markers in the census.");
var typedArrayCount;
g.withTypedArrayOnStack(() => {
typedArrayCount = dbg.memory.takeCensus().objects.Int8Array.count;
var allocationMarkerCount;
g.withAllocationMarkerOnStack(() => {
allocationMarkerCount = dbg.memory.takeCensus().objects.AllocationMarker.count;
});
assertEq(typedArrayCount, 1,
"Should have one typed array in the census, because there " +
assertEq(allocationMarkerCount, 1,
"Should have one allocation marker in the census, because there " +
"was one on the stack.");

View File

@ -4,11 +4,11 @@
var g = newGlobal();
var dbg = new Debugger(g);
assertEq("Int8Array" in dbg.memory.takeCensus().objects, false,
"There shouldn't exist any typed arrays in the census.");
assertEq("AllocationMarker" in dbg.memory.takeCensus().objects, false,
"There shouldn't exist any allocation markers in the census.");
this.ccw = g.eval("new Int8Array()");
this.ccw = g.allocationMarker();
assertEq(dbg.memory.takeCensus().objects.Int8Array.count, 1,
"Should have one typed array in the census, because there " +
"is one cross-compartment wrapper.");
assertEq(dbg.memory.takeCensus().objects.AllocationMarker.count, 1,
"Should have one allocation marker in the census, because there " +
"is one cross-compartment wrapper referring to it.");