mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1233187 - Use normal Rooted for AutoLocationValueRooter; r=fitzgen
--HG-- extra : rebase_source : bf48041be76fd71227eb85d1ef211699210787d3
This commit is contained in:
parent
bdbea769ec
commit
1242151b5d
@ -1120,7 +1120,7 @@ SavedStacks::insertFrames(JSContext* cx, FrameIter& iter, MutableHandleSavedFram
|
||||
}
|
||||
}
|
||||
|
||||
AutoLocationValueRooter location(cx);
|
||||
Rooted<LocationValue> location(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, iter.compartment());
|
||||
if (!cx->compartment()->savedStacks().getLocation(cx, iter, &location))
|
||||
@ -1133,9 +1133,9 @@ SavedStacks::insertFrames(JSContext* cx, FrameIter& iter, MutableHandleSavedFram
|
||||
parentIsInCache = iter.hasCachedSavedFrame();
|
||||
|
||||
auto displayAtom = iter.isNonEvalFunctionFrame() ? iter.functionDisplayAtom() : nullptr;
|
||||
if (!stackChain->emplaceBack(location->source,
|
||||
location->line,
|
||||
location->column,
|
||||
if (!stackChain->emplaceBack(location.source(),
|
||||
location.line(),
|
||||
location.column(),
|
||||
displayAtom,
|
||||
nullptr,
|
||||
nullptr,
|
||||
@ -1323,7 +1323,8 @@ SavedStacks::sweepPCLocationMap()
|
||||
}
|
||||
|
||||
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
|
||||
// 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 (const char16_t* displayURL = iter.scriptDisplayURL()) {
|
||||
locationp->source = AtomizeChars(cx, displayURL, js_strlen(displayURL));
|
||||
locationp.setSource(AtomizeChars(cx, displayURL, js_strlen(displayURL)));
|
||||
} else {
|
||||
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;
|
||||
|
||||
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
|
||||
// which is how SpiderMonkey stores it internally. This will be
|
||||
// unnecessary once bug 1144340 is fixed.
|
||||
locationp->column++;
|
||||
locationp.setColumn(column + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -224,7 +224,8 @@ class SavedStacks {
|
||||
jsbytecode* pc;
|
||||
};
|
||||
|
||||
struct LocationValue {
|
||||
public:
|
||||
struct LocationValue : public JS::Traceable {
|
||||
LocationValue() : source(nullptr), line(0), column(0) { }
|
||||
LocationValue(JSAtom* source, size_t line, uint32_t column)
|
||||
: source(source),
|
||||
@ -232,6 +233,7 @@ class SavedStacks {
|
||||
column(column)
|
||||
{ }
|
||||
|
||||
static void trace(LocationValue* self, JSTracer* trc) { self->trace(trc); }
|
||||
void trace(JSTracer* trc) {
|
||||
if (source)
|
||||
TraceEdge(trc, &source, "SavedStacks::LocationValue::source");
|
||||
@ -242,38 +244,25 @@ class SavedStacks {
|
||||
uint32_t column;
|
||||
};
|
||||
|
||||
class MOZ_STACK_CLASS AutoLocationValueRooter : public JS::CustomAutoRooter
|
||||
{
|
||||
public:
|
||||
explicit AutoLocationValueRooter(JSContext* cx)
|
||||
: JS::CustomAutoRooter(cx),
|
||||
value() {}
|
||||
|
||||
inline LocationValue* operator->() { return &value; }
|
||||
void set(LocationValue& loc) { value = loc; }
|
||||
LocationValue& get() { return value; }
|
||||
|
||||
template <typename Outer>
|
||||
struct LocationValueOperations {
|
||||
JSAtom* source() const { return loc().source; }
|
||||
size_t line() const { return loc().line; }
|
||||
uint32_t column() const { return loc().column; }
|
||||
private:
|
||||
virtual void trace(JSTracer* trc) {
|
||||
value.trace(trc);
|
||||
}
|
||||
|
||||
SavedStacks::LocationValue value;
|
||||
const LocationValue& loc() const { return static_cast<const Outer*>(this)->get(); }
|
||||
};
|
||||
|
||||
class MOZ_STACK_CLASS MutableHandleLocationValue
|
||||
{
|
||||
public:
|
||||
inline MOZ_IMPLICIT MutableHandleLocationValue(AutoLocationValueRooter* location)
|
||||
: location(location) {}
|
||||
|
||||
inline LocationValue* operator->() { return &location->get(); }
|
||||
void set(LocationValue& loc) { location->set(loc); }
|
||||
|
||||
template <typename Outer>
|
||||
struct MutableLocationValueOperations : public LocationValueOperations<Outer> {
|
||||
void setSource(JSAtom* v) { loc().source = v; }
|
||||
void setLine(size_t v) { loc().line = v; }
|
||||
void setColumn(uint32_t v) { loc().column = v; }
|
||||
private:
|
||||
AutoLocationValueRooter* location;
|
||||
LocationValue& loc() { return static_cast<Outer*>(this)->get(); }
|
||||
};
|
||||
|
||||
private:
|
||||
struct PCLocationHasher : public DefaultHasher<PCKey> {
|
||||
typedef PointerHasher<JSScript*, 3> ScriptPtrHasher;
|
||||
typedef PointerHasher<jsbytecode*, 3> BytecodePtrHasher;
|
||||
@ -293,11 +282,21 @@ class SavedStacks {
|
||||
PCLocationMap pcLocationMap;
|
||||
|
||||
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);
|
||||
|
||||
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 */
|
||||
|
||||
#endif /* vm_SavedStacks_h */
|
||||
|
Loading…
Reference in New Issue
Block a user