From 1242151b5d5ff48e9983f7c73cda71c252ef69bb Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Wed, 16 Dec 2015 12:18:46 -0800 Subject: [PATCH] Bug 1233187 - Use normal Rooted for AutoLocationValueRooter; r=fitzgen --HG-- extra : rebase_source : bf48041be76fd71227eb85d1ef211699210787d3 --- js/src/vm/SavedStacks.cpp | 22 +++++++++------- js/src/vm/SavedStacks.h | 55 +++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/js/src/vm/SavedStacks.cpp b/js/src/vm/SavedStacks.cpp index 97a1491c38c3..f3bd04cb07e4 100644 --- a/js/src/vm/SavedStacks.cpp +++ b/js/src/vm/SavedStacks.cpp @@ -1120,7 +1120,7 @@ SavedStacks::insertFrames(JSContext* cx, FrameIter& iter, MutableHandleSavedFram } } - AutoLocationValueRooter location(cx); + Rooted 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 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; } diff --git a/js/src/vm/SavedStacks.h b/js/src/vm/SavedStacks.h index 3c8e7770052f..3e26b3fc58df 100644 --- a/js/src/vm/SavedStacks.h +++ b/js/src/vm/SavedStacks.h @@ -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 + 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(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 + struct MutableLocationValueOperations : public LocationValueOperations { + 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(this)->get(); } }; + private: struct PCLocationHasher : public DefaultHasher { typedef PointerHasher ScriptPtrHasher; typedef PointerHasher 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 locationp); }; JSObject* SavedStacksMetadataCallback(JSContext* cx, JSObject* target); +template <> +class RootedBase + : public SavedStacks::MutableLocationValueOperations> +{}; + +template <> +class MutableHandleBase + : public SavedStacks::MutableLocationValueOperations> +{}; + } /* namespace js */ #endif /* vm_SavedStacks_h */