Ignore:
Timestamp:
Nov 12, 2017, 10:12:09 PM (8 years ago)
Author:
Darin Adler
Message:

More is<> and downcast<>, less static_cast<>
https://bugs.webkit.org/show_bug.cgi?id=179600

Reviewed by Chris Dumez.

Source/JavaScriptCore:

  • runtime/JSString.h:

(JSC::jsSubstring): Removed unneeded static_cast; length already returns unsigned.
(JSC::jsSubstringOfResolved): Ditto.

Source/WebCore:

  • Modules/fetch/FetchBody.cpp:

(WebCore::FetchBody::extract): Use downcast instead of static_cast.
(WebCore::FetchBody::bodyAsFormData const): Ditto.

  • Modules/indexeddb/IDBObjectStore.cpp:

(WebCore::IDBObjectStore::putOrAdd): Ditto.

  • Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:

(WebCore::CanvasCaptureMediaStreamTrack::Source::canvasChanged): Ditto.

  • Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:

(WebCore::libWebRTCProvider): Ditto.

  • accessibility/AccessibilityMediaControls.cpp:

(WebCore::AccessibilityMediaTimeDisplay::stringValue const): Got rid of local
variable and used std::abs instead of fabsf. Did not use downcast here because
it doesn't exist for this class.

  • bindings/js/JSEventTargetCustom.h:

(WebCore::IDLOperation<JSEventTarget>::call): Use downcast instead of toDOMWindow.

  • dom/DocumentEventQueue.cpp:

(WebCore::DocumentEventQueue::dispatchEvent): Ditto.

  • dom/Element.h: Added is/downcast for EventTarget.
  • dom/EventContext.cpp:

(WebCore::TouchEventContext::checkReachability const): Use downcast instead
of toNode.

  • dom/EventContext.h:

(WebCore::EventContext::isUnreachableNode const): Ditto.

  • dom/EventPath.cpp:

(WebCore::shouldEventCrossShadowBoundary): Ditto.
(WebCore::EventPath::setRelatedTarget): Ditto.
(WebCore::EventPath::retargetTouch): Ditto.
(WebCore::EventPath::EventPath): Ditto.

  • dom/EventTarget.cpp:

(WebCore::EventTarget::toNode): Deleted.
(WebCore::EventTarget::isNode const): Added.
(WebCore::EventTarget::toDOMWindow): Deleted.
(WebCore::EventTarget::isMessagePort const): Deleted. This was not used.
(WebCore::EventTarget::addEventListener): Use downcast instead of toDOMWindow
and toNode.

  • dom/EventTarget.h: Updated for the above.
  • dom/MessagePort.h: Deleted unused isMessagePort.
  • dom/MouseEvent.cpp:

(WebCore::MouseEvent::toElement const): Use downcast instead of toNode.
Also refactored to make function a little smaller.
(WebCore::MouseEvent::fromElement const): Ditto.

  • dom/MouseRelatedEvent.cpp:

(WebCore::MouseRelatedEvent::computeRelativePosition): Use downcast
instead of toNode.

  • dom/Node.cpp:

(WebCore::Node::isNode const): Added.
(WebCore::Node::toNode): Deleted.

  • dom/Node.h: Updated for the above. Also added SPECIALIZE_TYPE_TRAITS

so we can do is/downcast.

  • dom/ScopedEventQueue.cpp:

(WebCore::ScopedEventQueue::enqueueEvent): Use is instead of toNode.
(WebCore::ScopedEventQueue::dispatchEvent const): Use downcast instead of toNode.

  • dom/make_names.pl:

(printTypeHelpers): Added support for is/downcast from EventTarget.

  • editing/Editor.cpp:

(WebCore::Editor::selectionForCommand): Use is/downcast instead of toNode.

  • editing/EditorCommand.cpp:

(WebCore::targetFrame): Ditto.

  • html/HTMLAnchorElement.cpp:

(WebCore::appendServerMapMousePosition): Ditto.

  • html/HTMLCanvasElement.cpp:

(WebCore::HTMLCanvasElement::createContextWebGL): Use downcast instead of
static_cast.
(WebCore::HTMLCanvasElement::getContextWebGL): Ditto.
(WebCore::HTMLCanvasElement::getImageData): Ditto.

  • html/HTMLElement.h: Added support for is/downcast from EventTarget.
  • html/HTMLFormElement.cpp:

(WebCore::HTMLFormElement::handleLocalEvents): Use is instead of toNode.
(WebCore::submitElementFromEvent): Deleted. Was a duplicate of findSubmitButton.
(WebCore::HTMLFormElement::prepareForSubmission): Rewrote code that calls
submitElementFromEvent to call findSubmitButton instead. Also don't bother
finding the submit button unless we are going to validate, since all we do
after finding it is reconsider whether we should validate.
(WebCore::HTMLFormElement::findSubmitButton const): Rewrote to use is,
downcast, and lineageOfType rather than a handwritten loop and toNode.
Relies on the fact that the target is an element, never a text node.

  • html/HTMLLabelElement.cpp:

(WebCore::HTMLLabelElement::defaultEventHandler): Use is and downcast instead
of toNode.

  • html/HTMLPlugInImageElement.cpp:

(WebCore::HTMLPlugInImageElement::partOfSnapshotOverlay const): Changed argument
type to EventTarget so we can do the type checking and casting here instead of at
each of the callers.

  • html/HTMLPlugInImageElement.h: Updated for the above.
  • html/HTMLSummaryElement.cpp:

(WebCore::isClickableControl): Changed argument type to EventTarget so we can do
the type checking and casting here instead of at each of the callers.
(WebCore::HTMLSummaryElement::defaultEventHandler): Removed call to toNode.

  • html/HTMLTextFormControlElement.h: Added support for is/downcast from EventTarget.
  • html/MediaDocument.cpp:

(WebCore::MediaDocument::defaultEventHandler): Use is/downcast instead of toNode.

  • html/RangeInputType.cpp:

(WebCore::RangeInputType::handleMouseDownEvent): Ditto.

  • html/shadow/MediaControlElements.cpp:

(WebCore::MediaControlVolumeSliderContainerElement::defaultEventHandler): Ditto.
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Ditto.
Also use get instead of find/end.

  • html/shadow/MediaControls.cpp:

(WebCore::MediaControls::containsRelatedTarget): Use is/downcast instead of toNode.

  • inspector/InspectorFrontendHost.cpp:

(WebCore::InspectorFrontendHost::dispatchEventAsContextMenuEvent): Ditto.

  • inspector/agents/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::didAddEventListener): Ditto.
(WebCore::InspectorDOMAgent::willRemoveEventListener): Ditto.

  • page/ContextMenuController.cpp:

(WebCore::ContextMenuController::maybeCreateContextMenu): Ditto.

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::toDOMWindow): Deleted.

  • page/DOMWindow.h: Updated for the above. Also added SPECIALIZE_TYPE_TRAITS

so we can do is/downcast.

  • page/EventHandler.cpp:

(WebCore::EventHandler::handleTouchEvent): Use is/downcast instead of toNode.

  • platform/graphics/WidthCache.h:

(WebCore::WidthCache::add): Removed unneeded static_cast; length already returns unsigned.

  • rendering/RenderSnapshottedPlugIn.cpp:

(WebCore::RenderSnapshottedPlugIn::handleEvent): Removed unneeded toNode now that
partOfSnapshotOverlay takes an EventTarget.

Source/WebKit:

  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMPrivate.cpp:

(WebKit::wrap): Use is/downcast.

  • WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:

(WebKit::WebEditorClient::handleKeyboardEvent): Ditto.

  • WebProcess/WebCoreSupport/wpe/WebEditorClientWPE.cpp:

(WebKit::WebEditorClient::handleKeyboardEvent): Ditto.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::handleEditingKeyboardEvent): Ditto.

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::frameForEvent): Ditto.

Source/WebKitLegacy/mac:

  • DOM/DOM.mm:

(kit): Use is/downcast.

  • WebCoreSupport/WebEditorClient.mm:

(WebEditorClient::handleKeyboardEvent): Ditto.
(WebEditorClient::handleInputMethodKeydown): Ditto.

  • WebView/WebHTMLView.mm:

(-[WebHTMLView _interpretKeyEvent:savingCommands:]): Ditto.

Source/WebKitLegacy/win:

  • WebView.cpp:

(WebView::handleEditingKeyboardEvent): Use downcast.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r224055 r224740  
    582582inline JSString* jsSubstring(VM& vm, ExecState* exec, JSString* s, unsigned offset, unsigned length)
    583583{
    584     ASSERT(offset <= static_cast<unsigned>(s->length()));
    585     ASSERT(length <= static_cast<unsigned>(s->length()));
    586     ASSERT(offset + length <= static_cast<unsigned>(s->length()));
     584    ASSERT(offset <= s->length());
     585    ASSERT(length <= s->length());
     586    ASSERT(offset + length <= s->length());
    587587    if (!length)
    588588        return vm.smallStrings.emptyString();
     
    594594inline JSString* jsSubstringOfResolved(VM& vm, GCDeferralContext* deferralContext, JSString* s, unsigned offset, unsigned length)
    595595{
    596     ASSERT(offset <= static_cast<unsigned>(s->length()));
    597     ASSERT(length <= static_cast<unsigned>(s->length()));
    598     ASSERT(offset + length <= static_cast<unsigned>(s->length()));
     596    ASSERT(offset <= s->length());
     597    ASSERT(length <= s->length());
     598    ASSERT(offset + length <= s->length());
    599599    if (!length)
    600600        return vm.smallStrings.emptyString();
     
    616616inline JSString* jsSubstring(VM* vm, const String& s, unsigned offset, unsigned length)
    617617{
    618     ASSERT(offset <= static_cast<unsigned>(s.length()));
    619     ASSERT(length <= static_cast<unsigned>(s.length()));
    620     ASSERT(offset + length <= static_cast<unsigned>(s.length()));
     618    ASSERT(offset <= s.length());
     619    ASSERT(length <= s.length());
     620    ASSERT(offset + length <= s.length());
    621621    if (!length)
    622622        return vm->smallStrings.emptyString();
Note: See TracChangeset for help on using the changeset viewer.