Bug 951720: Allow the DebuggerWeakMaps used for Debugger.Source instances to have keys in invisible-to-debugger compartments. r=jonco

This commit is contained in:
Jim Blandy 2014-01-03 10:30:40 +00:00
parent c9c9bcc59d
commit 4ac40feb03
2 changed files with 19 additions and 3 deletions

View File

@ -0,0 +1,12 @@
// Looking at ScriptSourceObjects in invisible-to-debugger compartments is okay.
var gi = newGlobal({ invisibleToDebugger: true });
gi.eval('function f() {}');
var gv = newGlobal();
gv.f = gi.f;
gv.eval('f = clone(f);');
var dbg = new Debugger;
var gvw = dbg.addDebuggee(gv);
gvw.getOwnPropertyDescriptor('f').value.script.source;

View File

@ -37,8 +37,12 @@ class Breakpoint;
* swept in the same group as the debugger. This is a conservative approach,
* and compartments may be unnecessarily grouped, however it results in a
* simpler and faster implementation.
*
* If InvisibleKeysOk is true, then the map can have keys in invisible-to-
* debugger compartments. If it is false, we assert that such entries are never
* created.
*/
template <class Key, class Value>
template <class Key, class Value, bool InvisibleKeysOk=false>
class DebuggerWeakMap : private WeakMap<Key, Value, DefaultHasher<Key> >
{
private:
@ -78,7 +82,7 @@ class DebuggerWeakMap : private WeakMap<Key, Value, DefaultHasher<Key> >
template<typename KeyInput, typename ValueInput>
bool relookupOrAdd(AddPtr &p, const KeyInput &k, const ValueInput &v) {
JS_ASSERT(v->compartment() == Base::compartment);
JS_ASSERT(!k->compartment()->options_.invisibleToDebugger());
JS_ASSERT_IF(!InvisibleKeysOk, !k->compartment()->options_.invisibleToDebugger());
JS_ASSERT(!Base::has(k));
if (!incZoneCount(k->zone()))
return false;
@ -218,7 +222,7 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
ScriptWeakMap scripts;
/* The map from debuggee source script objects to their Debugger.Source instances. */
typedef DebuggerWeakMap<EncapsulatedPtrObject, RelocatablePtrObject> SourceWeakMap;
typedef DebuggerWeakMap<EncapsulatedPtrObject, RelocatablePtrObject, true> SourceWeakMap;
SourceWeakMap sources;
/* The map from debuggee objects to their Debugger.Object instances. */