Bug 1428075 - Remove non-rooted saved frame iterators r=fitzgen

This commit is contained in:
Jon Coppeard 2018-01-05 10:42:16 +00:00
Родитель 9bbdbfb532
Коммит 1f596afed3
3 изменённых файлов: 15 добавлений и 72 удалений

Просмотреть файл

@ -86,20 +86,6 @@ BEGIN_TEST(testSavedStacks_RangeBasedForLoops)
CHECK(obj->is<js::SavedFrame>());
JS::Rooted<js::SavedFrame*> savedFrame(cx, &obj->as<js::SavedFrame>());
js::SavedFrame* f = savedFrame.get();
for (auto& frame : *savedFrame.get()) {
CHECK(&frame == f);
f = f->getParent();
}
CHECK(f == nullptr);
const js::SavedFrame* cf = savedFrame.get();
for (const auto& frame : *savedFrame.get()) {
CHECK(&frame == cf);
cf = cf->getParent();
}
CHECK(cf == nullptr);
JS::Rooted<js::SavedFrame*> rf(cx, savedFrame);
for (JS::Handle<js::SavedFrame*> frame : js::SavedFrame::RootedRange(cx, rf)) {
JS_GC(cx);

Просмотреть файл

@ -190,35 +190,35 @@ BEGIN_TEST(testStructuredClone_SavedFrame)
JS::RootedObject destObj(cx, &destVal.toObject());
CHECK(destObj->is<js::SavedFrame>());
auto destFrame = &destObj->as<js::SavedFrame>();
JS::Handle<js::SavedFrame*> destFrame = destObj.as<js::SavedFrame>();
size_t framesCopied = 0;
for (auto& f : *destFrame) {
for (JS::Handle<js::SavedFrame*> f : js::SavedFrame::RootedRange(cx, destFrame)) {
framesCopied++;
CHECK(&f != srcFrame);
CHECK(f != srcFrame);
if (pp->principals == testPrincipals) {
// We shouldn't get a pointer to the same
// StructuredCloneTestPrincipals instance since we should have
// serialized and then deserialized it into a new instance.
CHECK(f.getPrincipals() != pp->principals);
CHECK(f->getPrincipals() != pp->principals);
// But it should certainly have the same rank.
CHECK(StructuredCloneTestPrincipals::getRank(f.getPrincipals()) ==
CHECK(StructuredCloneTestPrincipals::getRank(f->getPrincipals()) ==
StructuredCloneTestPrincipals::getRank(pp->principals));
} else {
// For our singleton principals, we should always get the same
// pointer back.
CHECK(js::ReconstructedSavedFramePrincipals::is(pp->principals) ||
pp->principals == nullptr);
CHECK(f.getPrincipals() == pp->principals);
CHECK(f->getPrincipals() == pp->principals);
}
CHECK(EqualStrings(f.getSource(), srcFrame->getSource()));
CHECK(f.getLine() == srcFrame->getLine());
CHECK(f.getColumn() == srcFrame->getColumn());
CHECK(EqualStrings(f.getFunctionDisplayName(), srcFrame->getFunctionDisplayName()));
CHECK(EqualStrings(f->getSource(), srcFrame->getSource()));
CHECK(f->getLine() == srcFrame->getLine());
CHECK(f->getColumn() == srcFrame->getColumn());
CHECK(EqualStrings(f->getFunctionDisplayName(), srcFrame->getFunctionDisplayName()));
srcFrame = srcFrame->getParent();
}

Просмотреть файл

@ -51,47 +51,16 @@ class SavedFrame : public NativeObject {
JSPrincipals* getPrincipals();
bool isSelfHosted(JSContext* cx);
// Iterators for use with C++11 range based for loops, eg:
//
// SavedFrame* stack = getSomeSavedFrameStack();
// for (const SavedFrame* frame : *stack) {
// ...
// }
//
// If you need to keep each frame rooted during iteration, you can use
// `SavedFrame::RootedRange`. Each frame yielded by
// `SavedFrame::RootedRange` is only a valid handle to a rooted `SavedFrame`
// within the loop's block for a single loop iteration. When the next
// iteration begins, the value is invalidated.
// Iterator for use with C++11 range based for loops, eg:
//
// RootedSavedFrame stack(cx, getSomeSavedFrameStack());
// for (HandleSavedFrame frame : SavedFrame::RootedRange(cx, stack)) {
// ...
// }
class Iterator {
SavedFrame* frame_;
public:
explicit Iterator(SavedFrame* frame) : frame_(frame) { }
SavedFrame& operator*() const { MOZ_ASSERT(frame_); return *frame_; }
bool operator!=(const Iterator& rhs) const { return rhs.frame_ != frame_; }
inline void operator++();
};
Iterator begin() { return Iterator(this); }
Iterator end() { return Iterator(nullptr); }
class ConstIterator {
const SavedFrame* frame_;
public:
explicit ConstIterator(const SavedFrame* frame) : frame_(frame) { }
const SavedFrame& operator*() const { MOZ_ASSERT(frame_); return *frame_; }
bool operator!=(const ConstIterator& rhs) const { return rhs.frame_ != frame_; }
inline void operator++();
};
ConstIterator begin() const { return ConstIterator(this); }
ConstIterator end() const { return ConstIterator(nullptr); }
//
// Each frame yielded by `SavedFrame::RootedRange` is only a valid handle to
// a rooted `SavedFrame` within the loop's block for a single loop
// iteration. When the next iteration begins, the value is invalidated.
class RootedRange;
@ -249,18 +218,6 @@ struct ReconstructedSavedFramePrincipals : public JSPrincipals
}
};
inline void
SavedFrame::Iterator::operator++()
{
frame_ = frame_->getParent();
}
inline void
SavedFrame::ConstIterator::operator++()
{
frame_ = frame_->getParent();
}
inline void
SavedFrame::RootedIterator::operator++()
{