From 8490101998586e2522d1eda110429a26c44059d9 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 6 Apr 2018 11:33:57 -0700 Subject: [PATCH] Bug 1445973: Part 2: Add 'clearSavedFrames' testing function to JS shell. r=jorendorff OOM tests often depend on invoking a function repeatedly, failing a different allocation each time. Flushing the caches helps ensure consistent behavior from one invocation to the next. --HG-- extra : rebase_source : 0bf4a46c7c3e0bceb0fe77bbf96e422558a988c4 extra : source : 1a11067ab1e6b62602b79081e3208dcad31807bd --- js/src/builtin/TestingFunctions.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 315ce01fe063..d291cbe3e0d8 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -1241,6 +1241,23 @@ GetSavedFrameCount(JSContext* cx, unsigned argc, Value* vp) return true; } +static bool +ClearSavedFrames(JSContext* cx, unsigned argc, Value* vp) +{ + CallArgs args = CallArgsFromVp(argc, vp); + + js::SavedStacks& savedStacks = cx->compartment()->savedStacks(); + if (savedStacks.initialized()) + savedStacks.clear(); + + for (ActivationIterator iter(cx); !iter.done(); ++iter) { + iter->clearLiveSavedFrameCache(); + } + + args.rval().setUndefined(); + return true; +} + static bool SaveStack(JSContext* cx, unsigned argc, Value* vp) { @@ -5170,6 +5187,12 @@ static const JSFunctionSpecWithHelp TestingFunctions[] = { " Return the number of SavedFrame instances stored in this compartment's\n" " SavedStacks cache."), + JS_FN_HELP("clearSavedFrames", ClearSavedFrames, 0, 0, +"clearSavedFrames()", +" Empty the current compartment's cache of SavedFrame objects, so that\n" +" subsequent stack captures allocate fresh objects to represent frames.\n" +" Clear the current stack's LiveSavedFrameCaches."), + JS_FN_HELP("saveStack", SaveStack, 0, 0, "saveStack([maxDepth [, compartment]])", " Capture a stack. If 'maxDepth' is given, capture at most 'maxDepth' number\n"