StaticNodeList* SVGSVGElement::collectIntersectionOrEnclosureList( const FloatRect& rect, SVGElement* referenceElement, CheckIntersectionOrEnclosure mode) const { HeapVector<Member<Node>> nodes; const SVGElement* root = this; if (referenceElement) { // Only the common subtree needs to be traversed. if (contains(referenceElement)) { root = referenceElement; } else if (!isDescendantOf(referenceElement)) { // No common subtree. return StaticNodeList::adopt(nodes); } } for (SVGGraphicsElement& element : Traversal<SVGGraphicsElement>::descendantsOf(*root)) { if (checkIntersectionOrEnclosure(element, rect, mode)) nodes.append(&element); } return StaticNodeList::adopt(nodes); }
void c_WaitableWaitHandle::throwCycleException(c_WaitableWaitHandle* child) const { assertx(isDescendantOf(child)); req::vector<std::string> exception_msg_items; exception_msg_items.push_back("Encountered dependency cycle.\n"); exception_msg_items.push_back("Existing stack:\n"); exception_msg_items.push_back(folly::stringPrintf( " %s (%" PRIxPTR ") (dupe)\n", child->getName().data(), (uintptr_t)child )); for (auto current = child; current != this;) { current = current->getChild(); assertx(current); exception_msg_items.push_back(folly::stringPrintf( " %s (%" PRIxPTR ")\n", current->getName().data(), (uintptr_t)current )); } exception_msg_items.push_back("Trying to introduce dependency on:\n"); exception_msg_items.push_back(folly::stringPrintf( " %s (%" PRIxPTR ") (dupe)\n", child->getName().data(), (uintptr_t)child )); SystemLib::throwInvalidOperationExceptionObject( folly::join("", exception_msg_items)); }
ObjectData* c_BlockableWaitHandle::createCycleException(c_WaitableWaitHandle* child) const { assert(isDescendantOf(child)); smart::vector<std::string> exception_msg_items; exception_msg_items.push_back("Encountered dependency cycle.\n"); exception_msg_items.push_back("Existing stack:\n"); exception_msg_items.push_back(folly::stringPrintf( " %s (%" PRId64 ")\n", child->getName().data(), child->t_getid())); assert(child->instanceof(c_BlockableWaitHandle::classof())); auto current = static_cast<c_BlockableWaitHandle*>(child); while (current != this) { assert(current->getState() == STATE_BLOCKED); assert(current->getChild()->instanceof(c_BlockableWaitHandle::classof())); current = static_cast<c_BlockableWaitHandle*>(current->getChild()); exception_msg_items.push_back(folly::stringPrintf( " %s (%" PRId64 ")\n", current->getName().data(), current->t_getid())); } exception_msg_items.push_back("Trying to introduce dependency on:\n"); exception_msg_items.push_back(folly::stringPrintf( " %s (%" PRId64 ") (dupe)\n", child->getName().data(), child->t_getid())); return SystemLib::AllocInvalidOperationExceptionObject( folly::join("", exception_msg_items)); }
bool StateMachineDebugInterface::isDescendantOf(State ascendant, State state) const { if (state == rootState()) return false; State parent = parentState(state); if (parent == ascendant) return true; return isDescendantOf(ascendant, parent); }
void c_AsyncGeneratorWaitHandle::prepareChild(c_WaitableWaitHandle* child) { assert(!child->isFinished()); // import child into the current context, throw on cross-context cycles child->enterContext(getContextIdx()); // detect cycles if (UNLIKELY(isDescendantOf(child))) { Object e(createCycleException(child)); throw e; } }
void SharedUiItemsTreeModel::TreeItem::adoptChild(TreeItem *child, int newRow) { //qDebug() << "adoptChild" << this << child << newRow << "/" << _children.size(); Q_ASSERT_X(child, "SharedUiItemsTreeModel::TreeItem::adoptChild()", "null child"); Q_ASSERT_X(!isDescendantOf(child), "SharedUiItemsTreeModel::TreeItem::adoptChild()", "cannot adopt an ancestor"); Q_ASSERT_X((newRow >= 0 && newRow <= _children.size()), "SharedUiItemsTreeModel::TreeItem::adoptChild()", "inconsistent row number"); if (child->_parent) child->_parent->removeChild(child->_row, false); child->_parent = this; child->_row = newRow; _children.insert(newRow, child); }
bool TreeScopeEventContext::isUnclosedTreeOf(const TreeScopeEventContext& other) { // Exclude closed nodes if necessary. // If a node is in a closed shadow root, or in a tree whose ancestor has a closed shadow root, // it should not be visible to nodes above the closed shadow root. // (1) If |this| is an ancestor of |other| in tree-of-trees, include it. if (isInclusiveAncestorOf(other)) return true; // (2) If no closed shadow root in ancestors of this, include it. if (!containingClosedShadowTree()) return true; // (3) If |this| is descendent of |other|, exclude if any closed shadow root in between. if (isDescendantOf(other)) return !containingClosedShadowTree()->isDescendantOf(other); // (4) |this| and |other| must be in exclusive branches. ASSERT(other.isExclusivePartOf(*this)); return false; }
void c_AsyncFunctionWaitHandle::run() { // may happen if scheduled in multiple contexts if (getState() != STATE_SCHEDULED) { return; } try { setState(STATE_RUNNING); // resume async function if (LIKELY(m_child->isSucceeded())) { // child succeeded, pass the result to the async function g_context->resumeAsyncFunc(resumable(), m_child, m_child->getResult()); } else if (m_child->isFailed()) { // child failed, raise the exception inside the async function g_context->resumeAsyncFuncThrow(resumable(), m_child, m_child->getException()); } else { throw FatalErrorException( "Invariant violation: child neither succeeded nor failed"); } retry: // async function reached RetC, which already set m_resultOrException if (isSucceeded()) { m_child = nullptr; markAsSucceeded(); return; } // async function reached AsyncSuspend, which already set m_child assert(!m_child->isFinished()); assert(m_child->instanceof(c_WaitableWaitHandle::classof())); // import child into the current context, detect cross-context cycles try { child()->enterContext(getContextIdx()); } catch (Object& e) { g_context->resumeAsyncFuncThrow(resumable(), m_child, e.get()); goto retry; } // detect cycles if (UNLIKELY(isDescendantOf(child()))) { Object e(createCycleException(child())); g_context->resumeAsyncFuncThrow(resumable(), m_child, e.get()); goto retry; } // on await callback AsioSession* session = AsioSession::Get(); if (UNLIKELY(session->hasOnAsyncFunctionAwaitCallback())) { session->onAsyncFunctionAwait(this, m_child); } // set up dependency setState(STATE_BLOCKED); blockOn(child()); } catch (const Object& exception) { // process exception thrown by the async function m_child = nullptr; markAsFailed(exception); } catch (...) { // process C++ exception m_child = nullptr; markAsFailed(AsioSession::Get()->getAbruptInterruptException()); throw; } }
// throws if establishing a dependency from this to child would form a cycle void c_BlockableWaitHandle::detectCycle(c_WaitableWaitHandle* child) const { if (UNLIKELY(isDescendantOf(child))) { Object e(createCycleException(child)); throw e; } }
void c_AsyncFunctionWaitHandle::run() { // may happen if scheduled in multiple contexts if (getState() != STATE_SCHEDULED) { return; } try { setState(STATE_RUNNING); // iterate continuation if (LIKELY(m_child->isSucceeded())) { // child succeeded, pass the result to the continuation m_continuation->call_send(m_child->getResult()); } else if (m_child->isFailed()) { // child failed, raise the exception inside continuation m_continuation->call_raise(m_child->getException()); } else { throw FatalErrorException( "Invariant violation: child neither succeeded nor failed"); } // continuation finished, retrieve result from its m_value if (m_continuation->done()) { markAsSucceeded(*m_continuation->m_value.asCell()); return; } retry: // save child Cell* value = tvAssertCell(m_continuation->m_value.asTypedValue()); assert(dynamic_cast<c_WaitableWaitHandle*>(c_WaitHandle::fromCell(value))); m_child = static_cast<c_WaitableWaitHandle*>(value->m_data.pobj); assert(!m_child->isFinished()); // import child into the current context, detect cross-context cycles try { m_child->enterContext(getContextIdx()); } catch (Object& e) { m_continuation->call_raise(e.get()); goto retry; } // detect cycles if (UNLIKELY(isDescendantOf(m_child.get()))) { Object e(createCycleException(m_child.get())); m_continuation->call_raise(e.get()); goto retry; } // on await callback AsioSession* session = AsioSession::Get(); if (UNLIKELY(session->hasOnAsyncFunctionAwaitCallback())) { session->onAsyncFunctionAwait(this, m_child.get()); } // set up dependency blockOn(m_child.get()); } catch (const Object& exception) { // process exception thrown by the async function markAsFailed(exception); } catch (...) { // process C++ exception markAsFailed(AsioSession::Get()->getAbruptInterruptException()); throw; } }