Bug 1233187 - Use normal Rooted for AutoLocationValueRooter; r=fitzgen

--HG--
extra : rebase_source : bf48041be76fd71227eb85d1ef211699210787d3
This commit is contained in:
Terrence Cole 2015-12-16 12:18:46 -08:00
parent bdbea769ec
commit 1242151b5d
2 changed files with 39 additions and 38 deletions

View file

@ -1120,7 +1120,7 @@ SavedStacks::insertFrames(JSContext* cx, FrameIter& iter, MutableHandleSavedFram
} }
} }
AutoLocationValueRooter location(cx); Rooted<LocationValue> location(cx);
{ {
AutoCompartment ac(cx, iter.compartment()); AutoCompartment ac(cx, iter.compartment());
if (!cx->compartment()->savedStacks().getLocation(cx, iter, &location)) if (!cx->compartment()->savedStacks().getLocation(cx, iter, &location))
@ -1133,9 +1133,9 @@ SavedStacks::insertFrames(JSContext* cx, FrameIter& iter, MutableHandleSavedFram
parentIsInCache = iter.hasCachedSavedFrame(); parentIsInCache = iter.hasCachedSavedFrame();
auto displayAtom = iter.isNonEvalFunctionFrame() ? iter.functionDisplayAtom() : nullptr; auto displayAtom = iter.isNonEvalFunctionFrame() ? iter.functionDisplayAtom() : nullptr;
if (!stackChain->emplaceBack(location->source, if (!stackChain->emplaceBack(location.source(),
location->line, location.line(),
location->column, location.column(),
displayAtom, displayAtom,
nullptr, nullptr,
nullptr, nullptr,
@ -1323,7 +1323,8 @@ SavedStacks::sweepPCLocationMap()
} }
bool bool
SavedStacks::getLocation(JSContext* cx, const FrameIter& iter, MutableHandleLocationValue locationp) SavedStacks::getLocation(JSContext* cx, const FrameIter& iter,
MutableHandle<LocationValue> locationp)
{ {
// We should only ever be caching location values for scripts in this // We should only ever be caching location values for scripts in this
// compartment. Otherwise, we would get dead cross-compartment scripts in // compartment. Otherwise, we would get dead cross-compartment scripts in
@ -1338,19 +1339,20 @@ SavedStacks::getLocation(JSContext* cx, const FrameIter& iter, MutableHandleLoca
if (!iter.hasScript()) { if (!iter.hasScript()) {
if (const char16_t* displayURL = iter.scriptDisplayURL()) { if (const char16_t* displayURL = iter.scriptDisplayURL()) {
locationp->source = AtomizeChars(cx, displayURL, js_strlen(displayURL)); locationp.setSource(AtomizeChars(cx, displayURL, js_strlen(displayURL)));
} else { } else {
const char* filename = iter.scriptFilename() ? iter.scriptFilename() : ""; const char* filename = iter.scriptFilename() ? iter.scriptFilename() : "";
locationp->source = Atomize(cx, filename, strlen(filename)); locationp.setSource(Atomize(cx, filename, strlen(filename)));
} }
if (!locationp->source) if (!locationp.source())
return false; return false;
locationp->line = iter.computeLine(&locationp->column); uint32_t column = 0;
locationp.setLine(iter.computeLine(&column));
// XXX: Make the column 1-based as in other browsers, instead of 0-based // XXX: Make the column 1-based as in other browsers, instead of 0-based
// which is how SpiderMonkey stores it internally. This will be // which is how SpiderMonkey stores it internally. This will be
// unnecessary once bug 1144340 is fixed. // unnecessary once bug 1144340 is fixed.
locationp->column++; locationp.setColumn(column + 1);
return true; return true;
} }

View file

@ -224,7 +224,8 @@ class SavedStacks {
jsbytecode* pc; jsbytecode* pc;
}; };
struct LocationValue { public:
struct LocationValue : public JS::Traceable {
LocationValue() : source(nullptr), line(0), column(0) { } LocationValue() : source(nullptr), line(0), column(0) { }
LocationValue(JSAtom* source, size_t line, uint32_t column) LocationValue(JSAtom* source, size_t line, uint32_t column)
: source(source), : source(source),
@ -232,6 +233,7 @@ class SavedStacks {
column(column) column(column)
{ } { }
static void trace(LocationValue* self, JSTracer* trc) { self->trace(trc); }
void trace(JSTracer* trc) { void trace(JSTracer* trc) {
if (source) if (source)
TraceEdge(trc, &source, "SavedStacks::LocationValue::source"); TraceEdge(trc, &source, "SavedStacks::LocationValue::source");
@ -242,38 +244,25 @@ class SavedStacks {
uint32_t column; uint32_t column;
}; };
class MOZ_STACK_CLASS AutoLocationValueRooter : public JS::CustomAutoRooter template <typename Outer>
{ struct LocationValueOperations {
public: JSAtom* source() const { return loc().source; }
explicit AutoLocationValueRooter(JSContext* cx) size_t line() const { return loc().line; }
: JS::CustomAutoRooter(cx), uint32_t column() const { return loc().column; }
value() {}
inline LocationValue* operator->() { return &value; }
void set(LocationValue& loc) { value = loc; }
LocationValue& get() { return value; }
private: private:
virtual void trace(JSTracer* trc) { const LocationValue& loc() const { return static_cast<const Outer*>(this)->get(); }
value.trace(trc);
}
SavedStacks::LocationValue value;
}; };
class MOZ_STACK_CLASS MutableHandleLocationValue template <typename Outer>
{ struct MutableLocationValueOperations : public LocationValueOperations<Outer> {
public: void setSource(JSAtom* v) { loc().source = v; }
inline MOZ_IMPLICIT MutableHandleLocationValue(AutoLocationValueRooter* location) void setLine(size_t v) { loc().line = v; }
: location(location) {} void setColumn(uint32_t v) { loc().column = v; }
inline LocationValue* operator->() { return &location->get(); }
void set(LocationValue& loc) { location->set(loc); }
private: private:
AutoLocationValueRooter* location; LocationValue& loc() { return static_cast<Outer*>(this)->get(); }
}; };
private:
struct PCLocationHasher : public DefaultHasher<PCKey> { struct PCLocationHasher : public DefaultHasher<PCKey> {
typedef PointerHasher<JSScript*, 3> ScriptPtrHasher; typedef PointerHasher<JSScript*, 3> ScriptPtrHasher;
typedef PointerHasher<jsbytecode*, 3> BytecodePtrHasher; typedef PointerHasher<jsbytecode*, 3> BytecodePtrHasher;
@ -293,11 +282,21 @@ class SavedStacks {
PCLocationMap pcLocationMap; PCLocationMap pcLocationMap;
void sweepPCLocationMap(); void sweepPCLocationMap();
bool getLocation(JSContext* cx, const FrameIter& iter, MutableHandleLocationValue locationp); bool getLocation(JSContext* cx, const FrameIter& iter, MutableHandle<LocationValue> locationp);
}; };
JSObject* SavedStacksMetadataCallback(JSContext* cx, JSObject* target); JSObject* SavedStacksMetadataCallback(JSContext* cx, JSObject* target);
template <>
class RootedBase<SavedStacks::LocationValue>
: public SavedStacks::MutableLocationValueOperations<JS::Rooted<SavedStacks::LocationValue>>
{};
template <>
class MutableHandleBase<SavedStacks::LocationValue>
: public SavedStacks::MutableLocationValueOperations<JS::MutableHandle<SavedStacks::LocationValue>>
{};
} /* namespace js */ } /* namespace js */
#endif /* vm_SavedStacks_h */ #endif /* vm_SavedStacks_h */