Skip to content

Commit 056434f

Browse files
committed
Refactor test runner code to cut down on copy/paste code and long-winded repetitive idioms
https://bugs.webkit.org/show_bug.cgi?id=217028 Reviewed by Sam Weinig. Source/JavaScriptCore: * API/JSRetainPtr.h: Added support for JSClassRef. Tools: I did a lot of simplifying, but even more is possible. For some reason, the test code is a hotbed of repeated idioms, and copy and paste rather than helper functions. Even after the refactoring, I have some doubts about the way this code is written with so much repeated marshaling for each function. * DumpRenderTree/AccessibilityController.cpp: (AccessibilityController::makeWindowObject): Use setGlobalObjectProperty. (AccessibilityController::createJSClass): Replaced getJSClass with this. Return a JSRetainPtr to make it clear this passes ownership to the caller. * DumpRenderTree/AccessibilityController.h: Updated for the above. * DumpRenderTree/AccessibilityUIElement.cpp: (uiElementCountForSearchPredicateCallback): Removed unneeded initialization of JSRetainPtr, which starts out null. * DumpRenderTree/Bindings/CodeGeneratorDumpRenderTree.pm: (_platformTypeConstructor): Use toOptionalBool and createJSString. (_returnExpression): Use makeValue. * DumpRenderTree/GCController.cpp: (GCController::GCController): Deleted. (GCController::~GCController): Deleted. (collectCallback): Use a reference and auto. (collectOnAlternateThreadCallback): Ditto. (getJSObjectCountCallback): Ditto. (GCController::makeWindowObject): Use setGlobalObjectProperty. (AccessibilityController::createJSClass): Replaced getJSClass with this. Return a JSRetainPtr to make it clear this passes ownership to the caller. * DumpRenderTree/GCController.h: Updated for the above. * DumpRenderTree/TestRunner.cpp: (encodeHostNameCallback): Use createJSString. (execCommandCallback): Ditto. (findStringCallback): Ditto. (isCommandEnabledCallback): Ditto. (overridePreferenceCallback): Ditto. (queueLoadCallback): Ditto. (queueLoadHTMLStringCallback): Ditto. (TestRunner::makeWindowObject): Use setGlobalObjectProperty. (TestRunner::createJSClass): Replaced getJSClass with this. Return a JSRetainPtr to make it clear this passes ownership to the caller. (TestRunner::staticValues): Made return value const*. (TestRunner::staticFunctions): Ditto. (TestRunner::waitToDumpWatchdogTimerFired): Simplified printing. (TestRunner::cacheTestRunnerCallback): Updated to use object pointers as hash table values instead of values, since callbacks need to be objects. (TestRunner::callTestRunnerCallback): Ditto. (TestRunner::clearTestRunnerCallbacks): Ditto. (TestRunner::setOpenPanelFiles): Use arrayLength. * DumpRenderTree/TestRunner.h: Updated for the above. * DumpRenderTree/ios/AccessibilityControllerIOS.mm: (AccessibilityController::platformName const): Use createJSString. * DumpRenderTree/ios/AccessibilityUIElementIOS.mm: (createEmptyJSString): Dleted. (AccessibilityUIElement::stringForTextMarkerRange): Use createJSString. (AccessibilityUIElement::attributesOfLinkedUIElements): Ditto. (AccessibilityUIElement::attributesOfDocumentLinks): Ditto. (AccessibilityUIElement::attributesOfChildren): Ditto. (AccessibilityUIElement::allAttributes): Ditto. (AccessibilityUIElement::stringAttributeValue): Ditto. (AccessibilityUIElement::parameterizedAttributeNames): Ditto. (AccessibilityUIElement::role): Ditto. (AccessibilityUIElement::subrole): Ditto. (AccessibilityUIElement::roleDescription): Ditto. (AccessibilityUIElement::computedRoleString): Ditto. (AccessibilityUIElement::title): Ditto. (AccessibilityUIElement::orientation const): Ditto. (AccessibilityUIElement::language): Ditto. (AccessibilityUIElement::valueDescription): Ditto. (AccessibilityUIElement::ariaDropEffects const): Ditto. (AccessibilityUIElement::boundsForRange): Ditto. (AccessibilityUIElement::attributesOfColumnHeaders): Ditto. (AccessibilityUIElement::attributesOfRowHeaders): Ditto. (AccessibilityUIElement::attributesOfColumns): Ditto. (AccessibilityUIElement::attributesOfRows): Ditto. (AccessibilityUIElement::attributesOfVisibleCells): Ditto. (AccessibilityUIElement::attributesOfHeader): Ditto. (AccessibilityUIElement::selectedTextRange): Ditto. (AccessibilityUIElement::accessibilityValue const): Ditto. (AccessibilityUIElement::documentEncoding): Ditto. (AccessibilityUIElement::documentURI): Ditto. * DumpRenderTree/mac/AccessibilityCommonMac.h: Removed unneeded "extern". * DumpRenderTree/mac/AccessibilityCommonMac.mm: (searchPredicateParameterizedAttributeForSearchCriteria): Use arrayLength. Removed unneeded call to JSValueToObject after JSValueIsObject. * DumpRenderTree/mac/AccessibilityControllerMac.mm: (AccessibilityController::platformName const): Use createJSString. * DumpRenderTree/mac/AccessibilityUIElementMac.mm: (createEmptyJSString): Deleted. (selectTextParameterizedAttributeForCriteria): Use arrayLength. Removed unneeded call to JSValueToObject after JSValueIsObject. (searchTextParameterizedAttributeForCriteria): Ditto. (AccessibilityUIElement::accessibilityValue const): Use createJSString. (AccessibilityUIElement::documentEncoding): Ditto. (AccessibilityUIElement::documentURI): Ditto. * DumpRenderTree/mac/FrameLoadDelegate.mm: (-[FrameLoadDelegate didClearWindowObjectInStandardWorldForFrame:]): Use auto. Pass fewer arguments to makeWindowObject. Simplified object creation code by using adoptNS instead of release. (-[FrameLoadDelegate didClearWindowObjectForFrame:inIsolatedWorld:]): Use createJSString. * DumpRenderTree/mac/TestRunnerMac.mm: (TestRunner::findString): Use arrayLength. * DumpRenderTree/win/FrameLoadDelegate.cpp: (FrameLoadDelegate::didClearWindowObjectForFrameInStandardWorld): Pass fewer arguments to makeWindowObject. * DumpRenderTree/win/TextInputController.cpp: (TextInputController::makeWindowObject): Use setGlobalObjectProperty. (TextInputController::createJSClass): Replaced getJSClass with this. Return a JSRetainPtr to make it clear this passes ownership to the caller. (TextInputController::staticValues): Made return value const*. (TextInputController::staticFunctions): Ditto. * DumpRenderTree/win/TextInputController.h: Updated for above. * TestRunnerShared/Bindings/JSBasics.cpp: (WTR::toOptionalBool): Renamed from JSValueMakeBooleanOrNull. (WTR::toOptionalDouble): Added. (WTR::makeValue): Added with overloads for various types. Replaced JSValueToNullableBoolean and JSValueMakeStringOrNull. (WTR::createJSString): Added with overloads for various types. (WTR::property): Added. (WTR::stringProperty): Added. (WTR::booleanProperty): Added. (WTR::numericProperty): Added. (WTR::objectProperty): Refactored to call property. (WTR::arrayLength): Added. (WTR::setGlobalObjectProperty): Added. (WTR::call): Refactored to let objectProperty do more of the null checking. (WTR::callConstructor): Ditto. * TestRunnerShared/Bindings/JSBasics.h: Updated for the above. * TestRunnerShared/Bindings/JSWrappable.h: Reduced includes a bit. * TestRunnerShared/Bindings/JSWrapper.h: Added setGlobalObjectProperty. * TestRunnerShared/UIScriptContext/UIScriptContext.cpp: (UIScriptContext::UIScriptContext): Pass fewer arguments to makeWindowObject. (UIScriptContext::runUIScript): Use createJSString. (UIScriptContext::objectFromRect const): Use setProperty. * TestRunnerShared/UIScriptContext/UIScriptController.h: Updated for the above. * TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp: (WTR::toDeviceOrientation): Use createJSString and JSStringIsEqualToUTF8CString. (WTR::UIScriptController::makeWindowObject): Use setGlobalObjectProperty. * TestRunnerShared/cocoa/LayoutTestSpellChecker.mm: (-[LayoutTestSpellChecker setResultsFromJSValue:inContext:]): Use createJSString and removed unneeded use of lroundl. * WebKitTestRunner/DictionaryFunctions.h: Added. Contains convenience functions for dealing with WKDictionaryRef. * WebKitTestRunner/EventSenderProxy.h: Initialize data members. * WebKitTestRunner/GeolocationProviderMock.cpp: (GeolocationProviderMock::setPosition): Use Optional instead of separate bool. * WebKitTestRunner/GeolocationProviderMock.h: Updated for the above. * WebKitTestRunner/InjectedBundle/AccessibilityController.cpp: (WTR::AccessibilityController::makeWindowObject): Use setGlobalObjectProperty. * WebKitTestRunner/InjectedBundle/AccessibilityController.h: Updated for the above. * WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm: (_generateImplementationFile): Use static initialization and a lambda instead of an if statement to initialize. (_platformTypeConstructor): Use toOptionalBool and createJSString. Also added support for nullable doubles and used auto a bit more. (_returnExpression): Use makeValue. * InjectedBundle/Bindings/TestRunner.idl: Made the optional arguments to the setMockGeolocationPosition function "double?" instead of "object". * WebKitTestRunner/InjectedBundle/EventSendingController.cpp: (WTR::getMenuItemChildrenCallback): Use auto and not JSValueToObject. (WTR::arrayLength): Moved to JSBasics.h/cpp. (WTR::parseTouchModifier): Added. Factored out of the EventSendingController::setTouchModifier function. (WTR::parseModifierArray): Use createJSString and remove unneeded ignored exception out argument, since that is optional. Also added overload that gets the context. (WTR::EventSendingController::EventSendingController): Deleted. (WTR::EventSendingController::~EventSendingController): Deleted. (WTR::createMouseMessageBody): Use adoptWK and setValue. Return a WKRetainPtr. (WTR::EventSendingController::mouseDown): Use postSynchronousPageMessage. (WTR::EventSendingController::mouseUp): Ditto. (WTR::EventSendingController::mouseMoveTo): Use setValue and postSynchronousPageMessages. (WTR::EventSendingController::mouseForceClick): Ditto. (WTR::EventSendingController::startAndCancelMouseForceClick): Ditto. (WTR::EventSendingController::mouseForceDown): Ditto. (WTR::EventSendingController::mouseForceUp): Ditto. (WTR::EventSendingController::mouseForceChanged): Ditto. (WTR::EventSendingController::leapForward): Ditto. (WTR::EventSendingController::scheduleAsynchronousClick): Use postPageMessage. (WTR::createKeyDownMessageBody): Use setValue. (WTR::EventSendingController::keyDown): Use postSynchronousPageMessage. (WTR::EventSendingController::scheduleAsynchronousKeyDown): Use postPageMessage. (WTR::EventSendingController::mouseScrollBy): Use setValue and postPageMessage. (WTR::EventSendingController::mouseScrollByWithWheelAndMomentumPhases): Use setValue and postPageMessage. (WTR::EventSendingController::continuousMouseScrollBy): Use setValue and postSynchronousPageMessage. (WTR::EventSendingController::contextClick): Use auto and not JSValueToObject. (WTR::toMonitorWheelEventsOptions): Use booleanProperty. (WTR::EventSendingController::addTouchPoint): Use setValue and postSynchronousPageMessage. (WTR::EventSendingController::updateTouchPoint): Ditto. (WTR::EventSendingController::setTouchModifier): Ditto. (WTR::EventSendingController::setTouchPointRadius): Ditto. (WTR::EventSendingController::touchStart): Ditto. (WTR::EventSendingController::touchMove): Ditto. (WTR::EventSendingController::touchEnd): Ditto. (WTR::EventSendingController::touchCancel): Ditto. (WTR::EventSendingController::clearTouchPoints): Ditto. (WTR::EventSendingController::releaseTouchPoint): Ditto. (WTR::EventSendingController::cancelTouchPoint): Ditto. (WTR::EventSendingController::makeWindowObject): Use setGlobalObjectProperty. * WebKitTestRunner/InjectedBundle/EventSendingController.h: Updated for the above. Deleted various unneeded functions. * WebKitTestRunner/InjectedBundle/GCController.cpp: (WTR::GCController::GCController): Deleted. (WTR::GCController::~GCController): Deleted. (WTR::GCController::makeWindowObject): Use setGlobalObjectProperty. * WebKitTestRunner/InjectedBundle/GCController.h: Updated for the above. Also marked the class final. * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp: (WTR::InjectedBundle::didCreatePage): Use booleanValue. (WTR::InjectedBundle::didReceiveMessage): Use toWK. (WTR::InjectedBundle::postPageMessage): Added. (WTR::InjectedBundle::reportLiveDocuments): Use postPageMessage. (WTR::InjectedBundle::didReceiveMessageToPage): Use dictionaryValue, booleanValue, postPageMessage, value, and more to streamline. (WTR::InjectedBundle::booleanForKey): Deleted. (WTR::InjectedBundle::stringForKey): Deleted. (WTR::InjectedBundle::beginTesting): Use booleanValue. (WTR::InjectedBundle::done): Use stringValue. (WTR::InjectedBundle::closeOtherPages): Use setValue and toWK. (WTR::InjectedBundle::dumpToStdErr): Use postPageMessage (WTR::InjectedBundle::outputText): Use toWK. (WTR::InjectedBundle::postNewBeforeUnloadReturnValue): Use postPageMessage. (WTR::InjectedBundle::postAddChromeInputField): Ditto. (WTR::InjectedBundle::postRemoveChromeInputField): Ditto. (WTR::InjectedBundle::postFocusWebView): Ditto. (WTR::InjectedBundle::postSetBackingScaleFactor): Ditto. (WTR::InjectedBundle::postSetWindowIsKey): Use toWK. (WTR::InjectedBundle::postSetViewSize): Use setValue and toWK. (WTR::InjectedBundle::postSimulateWebNotificationClick): Use postPageMessage. (WTR::InjectedBundle::postSetAddsVisitedLinks): Ditto. (WTR::InjectedBundle::setGeolocationPermission): Ditto. (WTR::InjectedBundle::setMockGeolocationPosition): Use setValue and postPageMessage, and use Optional instead of bool/double pairs. (WTR::InjectedBundle::setMockGeolocationPositionUnavailableError): Use postPageMessage. (WTR::InjectedBundle::isGeolocationProviderActive const): Use toWK and booleanValue. (WTR::InjectedBundle::imageCountInGeneralPasteboard const): Use toWK and uint64Value. (WTR::InjectedBundle::setUserMediaPermission): Use postPageMessage. (WTR::InjectedBundle::resetUserMediaPermission): Ditto. (WTR::InjectedBundle::setUserMediaPersistentPermissionForOrigin): Use setValue and postPageMessage. (WTR::InjectedBundle::userMediaPermissionRequestCountForOrigin const): Ditto. (WTR::InjectedBundle::resetUserMediaPermissionRequestCountForOrigin): Uset setValue and uint64Value. (WTR::InjectedBundle::setCustomPolicyDelegate): Use setValue and postPageMessage. (WTR::InjectedBundle::setHidden): Ditto. (WTR::InjectedBundle::setCacheModel): Ditto. (WTR::InjectedBundle::shouldProcessWorkQueue const): Use toWK and booleanValue. (WTR::InjectedBundle::processWorkQueue): Use postPageMessage. (WTR::InjectedBundle::queueBackNavigation): Ditto. (WTR::InjectedBundle::queueForwardNavigation): Ditto. (WTR::InjectedBundle::queueLoad): Use setValue and postPageMessage. (WTR::InjectedBundle::queueLoadHTMLString): Ditto. (WTR::InjectedBundle::queueReload): Ditto. (WTR::InjectedBundle::queueLoadingScript): Ditto. (WTR::InjectedBundle::queueNonLoadingScript): Ditto. (WTR::postMessage): Added. Overloads for many types to keep caller code streamlined. (WTR::postSynchronousMessage): Ditto. (WTR::postPageMessage): Ditto. (WTR::postSynchronousPageMessage): Ditto. * WebKitTestRunner/InjectedBundle/InjectedBundle.h: Updated for the above. * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp: (WTR::propertyValue): Deleted. Use functions from JSBasics.h instead. (WTR::propertyValueDouble): Ditto. (WTR::propertyValueInt): Ditto. (WTR::numericWindowProperty): Renamed from numericWindowPropertyValue for brevity and for consistency with JSBasics.h functions. (WTR::dumpPath): Use stringProperty, objectProperty, and makeString. (WTR::rangeToStr): Use auto, numericProperty, and makeString. (WTR::NavigationTypeToString): Use toWK. (WTR::string): Renamed from securityOriginToStr. Use makeString. (WTR::frameToStr): Use auto. (WTR::InjectedBundlePage::resetAfterTest): Removed unneeded local. (WTR::dumpFrameDescriptionSuitableForTestResult): Use auto. (WTR::dumpRequestDescriptionSuitableForTestResult): Ditto. (WTR::dumpErrorDescriptionSuitableForTestResult): Use auto and toWK. (WTR::dumpFrameScrollPosition): Update for name change. (WTR::toJS): Deleted. Use functions from JSBasics.h instead. (WTR::hasDocumentElement): Use objectProperty. (WTR::InjectedBundlePage::didClearWindowForFrame): Use setGlobalObjectProperty, and pass fewer arguments to makeWindowObject. (WTR::InjectedBundlePage::decidePolicyForNavigationAction): Streamline code a bit. (WTR::InjectedBundlePage::decidePolicyForResponse): Use makeString. (WTR::lastFileURLPathComponent): Ditto. (WTR::InjectedBundlePage::willSetStatusbarText): Ditto. (WTR::InjectedBundlePage::didReachApplicationCacheOriginQuota): Ditto. (WTR::InjectedBundlePage::didExceedDatabaseQuota): Ditto. (WTR::InjectedBundlePage::shouldBeginEditing): Ditto. (WTR::InjectedBundlePage::shouldEndEditing): Ditto. * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::TestRunner): Use toWK. (WTR::page): Added. (WTR::mainFrame): Added. (WTR::mainFrameJSContext): Added. (WTR::TestRunner::display): Use page. (WTR::TestRunner::displayAndTrackRepaints): Use page. (WTR::toWK): Added overload for double. (WTR::createWKDictionary): Added. (WTR::postSynchronousMessageWithReturnValue): Added. (WTR::postSynchronousMessageReturningBoolean): Added. (WTR::postSynchronousPageMessageWithReturnValue): Added. (WTR::postSynchronousPageMessageReturningBoolean): Added. (WTR::postSynchronousPageMessageReturningUInt64): Added. (WTR::postSynchronousMessageReturningUInt64): Added. (WTR::overridePreference): Added. (WTR::TestRunner::shouldDumpPixels const): Use postSynchronousMessageReturningBoolean. (WTR::TestRunner::setDumpPixels): Use postSynchronousMessage. (WTR::TestRunner::whatToDump const): Use postSynchronousMessageReturningUInt64. (WTR::TestRunner::setWhatToDump): Use postSynchronousMessage. (WTR::TestRunner::setWaitUntilDone): Use postSynchronousMessage. (WTR::TestRunner::shouldWaitUntilDone const): Use postSynchronousMessageReturningBoolean. (WTR::TestRunner::setShouldDumpFrameLoadCallbacks): Use postSynchronousMessage. (WTR::TestRunner::shouldDumpFrameLoadCallbacks): Use postSynchronousMessageReturningBoolean. (WTR::TestRunner::addUserScript): Use page. (WTR::TestRunner::addUserStyleSheet): Ditto. (WTR::TestRunner::execCommand): Ditto. (WTR::findOptionsFromArray): Use mainFrameJSContext, arrayLength, and createJSString. (WTR::TestRunner::findString): Use page. (WTR::TestRunner::findStringMatchesInPage): Ditto. (WTR::TestRunner::replaceFindMatchesAtIndices): Use mainFrameJSContext and arrayLength and removed unneeded call to std::round. (WTR::TestRunner::clearAllDatabases): Use postSynchronousMessage. (WTR::TestRunner::syncLocalStorage): Ditto. (WTR::TestRunner::clearAllApplicationCaches): Use page. (WTR::TestRunner::clearApplicationCacheForOrigin): Ditto. (WTR::TestRunner::setAppCacheMaximumSize): Ditto. (WTR::TestRunner::applicationCacheDiskUsageForOrigin): Ditto. (WTR::stringArrayToJS): Tweaked coding style a bit. (WTR::TestRunner::originsWithApplicationCache): Use page. (WTR::TestRunner::isCommandEnabled): Ditto. (WTR::TestRunner::setCanOpenWindows): Use postSynchronousMessage. (WTR::TestRunner::setXSSAuditorEnabled): Use overridePreference. (WTR::TestRunner::setMediaDevicesEnabled): Ditto. (WTR::TestRunner::setWebRTCMDNSICECandidatesEnabled): Ditto. (WTR::TestRunner::setCustomUserAgent): Use postSynchronousMessage. (WTR::TestRunner::setWebAPIStatisticsEnabled): Use overridePreference. (WTR::TestRunner::setModernMediaControlsEnabled): Ditto. (WTR::TestRunner::setWebGL2Enabled): Ditto. (WTR::TestRunner::setWritableStreamAPIEnabled): Ditto. (WTR::TestRunner::setTransformStreamAPIEnabled): Ditto. (WTR::TestRunner::setReadableByteStreamAPIEnabled): Ditto. (WTR::TestRunner::setEncryptedMediaAPIEnabled): Ditto. (WTR::TestRunner::setPictureInPictureAPIEnabled): Ditto. (WTR::TestRunner::setGenericCueAPIEnabled): Ditto. (WTR::TestRunner::setAllowsAnySSLCertificate): Use postSynchronousPageMessage. (WTR::TestRunner::setShouldSwapToEphemeralSessionOnNextNavigation): Ditto. (WTR::TestRunner::setShouldSwapToDefaultSessionOnNextNavigation): Ditto. (WTR::TestRunner::setPluginsEnabled): Use overridePreference. (WTR::TestRunner::isPageBoxVisible): Use mainFrame. (WTR::TestRunner::setValueForUser): Removed local. (WTR::TestRunner::setAudioResult): Ditto. (WTR::TestRunner::clearBackForwardList): Use page. (WTR::TestRunner::makeWindowObject): Use setGlobalObjectProperty. (WTR::TestRunner::showWebInspector): Use page. (WTR::TestRunner::closeWebInspector): Ditto. (WTR::TestRunner::evaluateInWebInspector): Ditto. (WTR::TestRunner::worldIDForWorld): Use range-based for loop. (WTR::TestRunner::evaluateScriptInIsolatedWorld): Use mainFrame. (WTR::TestRunner::setTextDirection): Use mainFrame. (WTR::TestRunner::didReceiveServerRedirectForProvisionalNavigation const): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::clearDidReceiveServerRedirectForProvisionalNavigation): Use postSynchronousPageMessage. (WTR::cacheTestRunnerCallback): Changed map to store objects instead of values. (WTR::callTestRunnerCallback): Simplify since map has objects. Use mainFrameJSContext. (WTR::TestRunner::clearTestRunnerCallbacks): Ditto. (WTR::TestRunner::setAlwaysAcceptCookies): Use postSynchronousMessage. (WTR::TestRunner::setOnlyAcceptFirstPartyCookies): Use auto and toWK. (WTR::TestRunner::setUserStyleSheetEnabled): Use toWK. (WTR::TestRunner::setUserStyleSheetLocation): Use page. (WTR::TestRunner::setTabKeyCyclesThroughElements): Ditto. (WTR::TestRunner::grantWebNotificationPermission): Ditto. (WTR::TestRunner::denyWebNotificationPermission): Ditto. (WTR::TestRunner::removeAllWebNotificationPermissions): Use mainFrameJSContext. (WTR::TestRunner::simulateWebNotificationClick): Ditto. (WTR::TestRunner::setMockGeolocationPosition): Use Optional<double> instead of bool/double pairs, letting the IDL bindings do the work for us. (WTR::TestRunner::setMockGeolocationPositionUnavailableError): Removed local. (WTR::TestRunner::isDoingMediaCapture const): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::setUserMediaPersistentPermissionForOrigin): Removed locals. (WTR::TestRunner::userMediaPermissionRequestCountForOrigin const): Ditto. (WTR::TestRunner::resetUserMediaPermissionRequestCountForOrigin): DItto. (WTR::TestRunner::callShouldCloseOnWebView): Use mainFrame. (WTR::TestRunner::queueLoad): Ditto. (WTR::TestRunner::queueLoadHTMLString): Removed a local. (WTR::TestRunner::queueLoadingScript): Ditto. (WTR::TestRunner::queueNonLoadingScript): Ditto. (WTR::TestRunner::setRejectsProtectionSpaceAndContinueForAuthenticationChallenges): Use postPageMessage. (WTR::TestRunner::setHandlesAuthenticationChallenges): Ditto. (WTR::TestRunner::setShouldLogCanAuthenticateAgainstProtectionSpace): Ditto. (WTR::TestRunner::setShouldLogDownloadCallbacks): Ditto. (WTR::TestRunner::setAuthenticationUsername): Ditto. (WTR::TestRunner::setAuthenticationPassword): Ditto. (WTR::TestRunner::secureEventInputIsEnabled const): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::setBlockAllPlugins): Use postPageMessage. (WTR::TestRunner::setPluginSupportedMode): Ditto. (WTR::TestRunner::failNextNewCodeBlock): Use mainFrameJSContext. (WTR::TestRunner::numberOfDFGCompiles): Ditto. (WTR::TestRunner::neverInlineFunction): Ditto. (WTR::TestRunner::setShouldDecideNavigationPolicyAfterDelay): Use postPageMessage. (WTR::TestRunner::setShouldDecideResponsePolicyAfterDelay): Ditto. (WTR::TestRunner::setNavigationGesturesEnabled): Ditto. (WTR::TestRunner::setIgnoresViewportScaleLimits): Ditto. (WTR::TestRunner::setShouldDownloadUndisplayableMIMETypes): Ditto. (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): Ditto. (WTR::TestRunner::terminateNetworkProcess): Use postSynchronousPageMessage. (WTR::TestRunner::terminateServiceWorkers): Ditto. (WTR::TestRunner::setUseSeparateServiceWorkerProcess): Ditto. (WTR::TestRunner::runUIScript): Use postPageMessage. (WTR::TestRunner::runUIScriptImmediately): Ditto. (WTR::TestRunner::runUIScriptCallback): Use mainFrameJSContext. (WTR::TestRunner::setAllowedMenuActions): Use mainFrameJSContext, arrayLength, and postPageMessage. (WTR::TestRunner::installCustomMenuAction): Use postPageMessage. (WTR::TestRunner::clearStatisticsDataForDomain): Use postSynchronousMessage. (WTR::TestRunner::doesStatisticsDomainIDExistInDatabase): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::setStatisticsEnabled): Use postSynchronousMessage. (WTR::TestRunner::isStatisticsEphemeral): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::setStatisticsDebugMode): Use postMessage. (WTR::TestRunner::setStatisticsPrevalentResourceForDebugMode): Ditto. (WTR::TestRunner::setStatisticsLastSeen): Ditto. (WTR::TestRunner::setStatisticsMergeStatistic): Ditto. (WTR::TestRunner::setStatisticsExpiredStatistic): Ditto. (WTR::TestRunner::setStatisticsPrevalentResource): Ditto. (WTR::TestRunner::setStatisticsVeryPrevalentResource): Ditto. (WTR::TestRunner::dumpResourceLoadStatistics): Use postSynchronousPageMessage. (WTR::TestRunner::isStatisticsPrevalentResource): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::isStatisticsVeryPrevalentResource): Ditto. (WTR::TestRunner::isStatisticsRegisteredAsSubresourceUnder): Ditto. (WTR::TestRunner::isStatisticsRegisteredAsSubFrameUnder): Ditto. (WTR::TestRunner::isStatisticsRegisteredAsRedirectingTo): Ditto. (WTR::TestRunner::setStatisticsHasHadUserInteraction): Use postMessage. (WTR::TestRunner::isStatisticsHasHadUserInteraction): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::isStatisticsOnlyInDatabaseOnce): Ditto. (WTR::TestRunner::setStatisticsGrandfathered): Use postSynchronousMessage. (WTR::TestRunner::setUseITPDatabase): Ditto. (WTR::TestRunner::isStatisticsGrandfathered): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::setStatisticsSubframeUnderTopFrameOrigin): Use postSynchronousMessage. (WTR::TestRunner::setStatisticsSubresourceUnderTopFrameOrigin): Ditto. (WTR::TestRunner::setStatisticsSubresourceUniqueRedirectTo): Ditto. (WTR::TestRunner::setStatisticsSubresourceUniqueRedirectFrom): Ditto. (WTR::TestRunner::setStatisticsTopFrameUniqueRedirectTo): Ditto. (WTR::TestRunner::setStatisticsTopFrameUniqueRedirectFrom): Ditto. (WTR::TestRunner::setStatisticsCrossSiteLoadWithLinkDecoration): Ditto. (WTR::TestRunner::setStatisticsTimeToLiveUserInteraction): Ditto. (WTR::TestRunner::statisticsDidRunTelemetryCallback): Use mainFrameJSContext. (WTR::TestRunner::statisticsProcessStatisticsAndDataRecords): Use postSynchronousMessage. (WTR::TestRunner::statisticsUpdateCookieBlocking): Use postMessage. (WTR::TestRunner::statisticsSubmitTelemetry): Use postSynchronousMessage. (WTR::TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned): Ditto. (WTR::TestRunner::setStatisticsIsRunningTest): Ditto. (WTR::TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval): Ditto. (WTR::TestRunner::setStatisticsMinimumTimeBetweenDataRecordsRemoval): Ditto. (WTR::TestRunner::setStatisticsGrandfatheringTime): Ditto. (WTR::TestRunner::setStatisticsMaxStatisticsEntries): Ditto. (WTR::TestRunner::setStatisticsPruneEntriesDownTo): Ditto. (WTR::TestRunner::statisticsClearInMemoryAndPersistentStore): Use postMessage. (WTR::TestRunner::statisticsClearInMemoryAndPersistentStoreModifiedSinceHours): Ditto. (WTR::TestRunner::statisticsClearThroughWebsiteDataRemoval): Ditto. (WTR::TestRunner::statisticsDeleteCookiesForHost): Use postSynchronousMessage. (WTR::TestRunner::isStatisticsHasLocalStorage): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::setStatisticsCacheMaxAgeCap): Use postSynchronousMessage. (WTR::TestRunner::hasStatisticsIsolatedSession): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::setStatisticsShouldDowngradeReferrer): Use postMessage. (WTR::TestRunner::setStatisticsShouldBlockThirdPartyCookies): Ditto. (WTR::TestRunner::setStatisticsFirstPartyWebsiteDataRemovalMode): Ditto. (WTR::TestRunner::statisticsSetToSameSiteStrictCookies): Ditto. (WTR::TestRunner::statisticsSetFirstPartyHostCNAMEDomain): Ditto. (WTR::TestRunner::statisticsSetThirdPartyCNAMEDomain): Ditto. (WTR::TestRunner::statisticsResetToConsistentState): Ditto. (WTR::TestRunner::getAllStorageAccessEntries): Ditto. (WTR::makeDomainsValue): Factored out. Use mainFrameJSContext. (WTR::TestRunner::callDidReceiveAllStorageAccessEntriesCallback): Use makeDomainsValue. (WTR::TestRunner::loadedSubresourceDomains): Use postMessage. (WTR::TestRunner::callDidReceiveLoadedSubresourceDomainsCallback): Use makeDomainsValue. (WTR::TestRunner::addMockMediaDevice): Use postSynchronousMessage. (WTR::TestRunner::clearMockMediaDevices): Ditto. (WTR::TestRunner::removeMockMediaDevice): Ditto. (WTR::TestRunner::resetMockMediaDevices): Ditto. (WTR::TestRunner::setMockCameraOrientation): Ditto. (WTR::TestRunner::isMockRealtimeMediaSourceCenterEnabled): Use postSynchronousMessageReturningBoolean. (WTR::TestRunner::connectMockGamepad): Use postSynchronousMessage. (WTR::TestRunner::disconnectMockGamepad): Ditto. (WTR::TestRunner::setMockGamepadDetails): Ditto. (WTR::TestRunner::setMockGamepadAxisValue): Ditto. (WTR::TestRunner::setMockGamepadButtonValue): Ditto. (WTR::TestRunner::setOpenPanelFiles): Use mainFrameJSContext, arrayLength, createJSString, and postPageMessage. (WTR::TestRunner::setOpenPanelFilesMediaIcon): Use mainFrameJSContext and postPageMessage. (WTR::TestRunner::removeAllSessionCredentials): Use postMessage. (WTR::TestRunner::clearDOMCache): Use postSynchronousMessage. (WTR::TestRunner::clearDOMCaches): Ditto. (WTR::TestRunner::hasDOMCache): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::domCacheSize): Use postSynchronousPageMessageReturningUInt64. (WTR::TestRunner::setAllowStorageQuotaIncrease): Use postSynchronousPageMessage. (WTR::TestRunner::getApplicationManifestThen): Use postMessage. (WTR::TestRunner::injectUserScript): Use postSynchronousMessage. (WTR::TestRunner::sendDisplayConfigurationChangedMessageForTesting): Ditto. (WTR::TestRunner::setServiceWorkerFetchTimeout): Ditto. (WTR::TestRunner::addTestKeyToKeychain): Ditto. (WTR::TestRunner::cleanUpKeychain): Ditto. (WTR::TestRunner::keyExistsInKeychain): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::serverTrustEvaluationCallbackCallsCount): Use postSynchronousMessageReturningUInt64. (WTR::TestRunner::setShouldDismissJavaScriptAlertsAsynchronously): Use postSynchronousMessage. (WTR::TestRunner::abortModal): Ditto. (WTR::TestRunner::dumpAdClickAttribution): Use postSynchronousPageMessage. (WTR::TestRunner::clearAdClickAttribution): Ditto. (WTR::TestRunner::clearAdClickAttributionsThroughWebsiteDataRemoval): Ditto. (WTR::TestRunner::setAdClickAttributionOverrideTimerForTesting): Ditto. (WTR::TestRunner::setAdClickAttributionConversionURLForTesting): Ditto. (WTR::TestRunner::markAdClickAttributionsAsExpiredForTesting): Ditto. (WTR::TestRunner::setOffscreenCanvasEnabled): Use overridePreference. (WTR::TestRunner::hasAppBoundSession): Use postSynchronousPageMessageReturningBoolean. (WTR::TestRunner::clearAppBoundSession): Use postSynchronousMessage. (WTR::TestRunner::setAppBoundDomains): Use mainFrameJSContext, arrayLength, createJSString, and toWK. (WTR::TestRunner::postMessage): Added. * WebKitTestRunner/InjectedBundle/TestRunner.h: Updated for the above. Also changed overridePreference ot a static member function. * WebKitTestRunner/InjectedBundle/TextInputController.cpp: (WTR::TextInputController::TextInputController): Deleted. (WTR::TextInputController::~TextInputController): Deleted. (WTR::TextInputController::makeWindowObject): Use setGlobalObjectProperty. (WTR::arrayLength): Deleted. Use the one from JSBasics.h now. (WTR::createCompositionHighlightData): Use setValue. * WebKitTestRunner/InjectedBundle/TextInputController.h: Updated for the above. * WebKitTestRunner/InjectedBundle/ios/AccessibilityControllerIOS.mm: (WTR::AccessibilityController::platformName): Use createJSString. * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm: (WTR::createEmptyJSString): Deleted. Use createJSString from JSBasics.h now. (WTR::AccessibilityUIElement::attributesOfLinkedUIElements): Use createJSString. (WTR::AccessibilityUIElement::attributesOfDocumentLinks): Ditto. (WTR::AccessibilityUIElement::attributesOfChildren): Ditto. (WTR::AccessibilityUIElement::allAttributes): Ditto. (WTR::AccessibilityUIElement::stringDescriptionOfAttributeValue): Ditto. (WTR::AccessibilityUIElement::stringAttributeValue): Ditto. (WTR::AccessibilityUIElement::parameterizedAttributeNames): Ditto. (WTR::AccessibilityUIElement::role): Ditto. (WTR::AccessibilityUIElement::subrole): Ditto. (WTR::AccessibilityUIElement::computedRoleString): Ditto. (WTR::AccessibilityUIElement::title): Ditto. (WTR::AccessibilityUIElement::orientation const): Ditto. (WTR::AccessibilityUIElement::language): Ditto. (WTR::AccessibilityUIElement::valueDescription): Ditto. (WTR::AccessibilityUIElement::isFocused const): Ditto. (WTR::AccessibilityUIElement::isSelectedOptionActive const): Ditto. (WTR::AccessibilityUIElement::isIndeterminate const): Ditto. (WTR::AccessibilityUIElement::ariaDropEffects const): Ditto. (WTR::AccessibilityUIElement::boundsForRange): Ditto. (WTR::AccessibilityUIElement::attributesOfColumnHeaders): Ditto. (WTR::AccessibilityUIElement::attributesOfRowHeaders): Ditto. (WTR::AccessibilityUIElement::attributesOfColumns): Ditto. (WTR::AccessibilityUIElement::attributesOfRows): Ditto. (WTR::AccessibilityUIElement::attributesOfVisibleCells): Ditto. (WTR::AccessibilityUIElement::attributesOfHeader): Ditto. (WTR::AccessibilityUIElement::clearSelectedChildren const): Ditto. (WTR::AccessibilityUIElement::accessibilityValue const): Ditto. (WTR::AccessibilityUIElement::documentEncoding): Ditto. (WTR::AccessibilityUIElement::documentURI): Ditto. (WTR::AccessibilityUIElement::isSelectable const): Ditto. (WTR::AccessibilityUIElement::isMultiSelectable const): Ditto. (WTR::AccessibilityUIElement::isVisible const): Ditto. (WTR::AccessibilityUIElement::isOffScreen const): Ditto. (WTR::AccessibilityUIElement::isCollapsed const): Ditto. (WTR::AccessibilityUIElement::isSingleLine const): Ditto. (WTR::AccessibilityUIElement::isMultiLine const): Ditto. (WTR::AccessibilityUIElement::takeFocus): Ditto. (WTR::AccessibilityUIElement::takeSelection): Ditto. (WTR::AccessibilityUIElement::addSelection): Ditto. (WTR::AccessibilityUIElement::removeSelection): Ditto. (WTR::AccessibilityUIElement::stringForTextMarkerRange): Ditto. * WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm: (WTR::EventSenderProxy::EventSenderProxy): Initialize in the class definition. (WTR::EventSenderProxy::~EventSenderProxy): Deleted. * WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.mm: (WTR::makeJSArray): Return a JSObjectRef. Renamed from makeArrayRefForArray. (WTR::makeJSObject): Return a JSObjectRef. Renamed from makeObjectRefForDictionary. (WTR::makeValueRefForValue): Updated for the above. (WTR::searchPredicateParameterizedAttributeForSearchCriteria): Use toWTFString and arrayLength. * WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm: (WTR::AccessibilityController::platformName): Use createJSString. * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm: (WTR::createEmptyJSString): Deleted. Use createJSString from JSBasics.h instead. (WTR::convertVectorToObjectArray): Deleted. (WTR::makeJSArray): Renamed from convertVectorToObjectArray. (WTR::selectTextParameterizedAttributeForCriteria): Use toWTFString and arrayLength. (WTR::searchTextParameterizedAttributeForCriteria): Ditto. (WTR::AccessibilityUIElement::rowHeaders const): Use makeJSArray. (WTR::AccessibilityUIElement::columnHeaders const): Ditto. (WTR::AccessibilityUIElement::uiElementArrayAttributeValue const): Ditto. (WTR::AccessibilityUIElement::searchTextWithCriteria): Ditto. (WTR::AccessibilityUIElement::accessibilityValue const): Use createJSString. (WTR::AccessibilityUIElement::documentEncoding): Ditto. (WTR::AccessibilityUIElement::documentURI): Ditto. * WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm: (WTR::TestRunner::inspectorTestStubURL): Remove locals. * WebKitTestRunner/StringFunctions.h: Added toWKString overload that converts from a JSValueRef, JSStringRef, or JSRetainPtr<JSStringRef> and toWK overload that converts from a const char*. * WebKitTestRunner/TestController.cpp: (WTR::TestController::initialize): Use toWK. (WTR::TestController::generateContextConfiguration const): Ditto. (WTR::TestController::resetPreferencesToConsistentValues): Ditto. (WTR::TestController::resetStateToConsistentValues): Use setValue. (WTR::TestController::updateLiveDocumentsAfterTest): Ditto. (WTR::TestController::checkForWorldLeaks): Use toWK. (WTR::contentExtensionJSONPath): Use toSTD. (WTR::TestController::configureContentExtensionForTest): Use toWK. (WTR::TestController::didReceiveKeyDownMessageFromInjectedBundle): Use stringValue and uint64Value. (WTR::TestController::didReceiveLiveDocumentsList): Use dictionaryValue and uint64Value. (WTR::TestController::didReceiveMessageFromInjectedBundle): Use dictionaryValue, stringValue, uint64Value, doubleValue, booleanValue. (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle): Ditto. (WTR::TestController::setBlockAllPlugins): Use toWK. (WTR::TestController::setPluginSupportedMode): Ditto. (WTR::TestController::canAuthenticateAgainstProtectionSpace): Use auto. (WTR::TestController::didFinishNavigation): Removed local. (WTR::TestController::didReceiveAuthenticationChallenge): Use auto and toWTFString instead of toSTD. (WTR::TestController::setMockGeolocationPosition): Use Optional instead of pairs of bool and double. (WTR::TestController::handleCheckOfUserMediaPermissionForOrigin): Use toWK. (WTR::TestController::decidePolicyForUserMediaPermissionRequestIfPossible): Ditto. (WTR::TestController::updateBundleIdentifierInNetworkProcess): Use toWK. * WebKitTestRunner/TestController.h: Updated for the above. * WebKitTestRunner/TestInvocation.cpp: (WTR::postPageMessage): Added. (WTR::TestInvocation::TestIncovation): Use toWTFString. (WTR::TestInvocation::createTestSettingsDictionary): Use auto and setValue. (WTR::TestInvocation::invoke): Use postPageMessage and setValue. (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Use postPageMessage and stringValue. (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): Use dictionaryValue, booleanValue, value, stringValue, doubleValue, and optionalDoubleValue. (WTR::TestInvocation::uiScriptDidComplete): Use postPageMessage and setValue. (WTR::TestInvocation::didBeginSwipe): Use postPageMessage. (WTR::TestInvocation::willEndSwipe): Ditto. (WTR::TestInvocation::didEndSwipe): Ditto. (WTR::TestInvocation::didRemoveSwipeSnapshot): Ditto. (WTR::TestInvocation::notifyDownloadDone): Ditto. (WTR::TestInvocation::didClearStatisticsInMemoryAndPersistentStore): Ditto. (WTR::TestInvocation::didClearStatisticsThroughWebsiteDataRemoval): Ditto. (WTR::TestInvocation::didSetShouldDowngradeReferrer): Ditto. (WTR::TestInvocation::didSetShouldBlockThirdPartyCookies): Ditto. (WTR::TestInvocation::didSetFirstPartyWebsiteDataRemovalMode): Ditto. (WTR::TestInvocation::didSetToSameSiteStrictCookies): Ditto. (WTR::TestInvocation::didSetFirstPartyHostCNAMEDomain): Ditto. (WTR::TestInvocation::didSetThirdPartyCNAMEDomain): Ditto. (WTR::TestInvocation::didResetStatisticsToConsistentState): Ditto. (WTR::TestInvocation::didSetBlockCookiesForHost): Ditto. (WTR::TestInvocation::didSetStatisticsDebugMode): Ditto. (WTR::TestInvocation::didSetPrevalentResourceForDebugMode): Ditto. (WTR::TestInvocation::didSetLastSeen): Ditto. (WTR::TestInvocation::didMergeStatistic): Ditto. (WTR::TestInvocation::didSetExpiredStatistic): Ditto. (WTR::TestInvocation::didSetPrevalentResource): Ditto. (WTR::TestInvocation::didSetVeryPrevalentResource): Ditto. (WTR::TestInvocation::didSetHasHadUserInteraction): Ditto. (WTR::TestInvocation::didReceiveAllStorageAccessEntries): Ditto. (WTR::TestInvocation::didReceiveLoadedSubresourceDomains): Ditto. (WTR::TestInvocation::didRemoveAllSessionCredentials): Ditto. (WTR::TestInvocation::didSetAppBoundDomains): Ditto. (WTR::TestInvocation::performCustomMenuAction): Ditto. * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj: Added JSBasics.h to DictionaryFunctions.h to appropriate targets. * WebKitTestRunner/WorkQueueManager.cpp: (WTR::ScriptItem::ScriptItem): Use toWK. (WTR::WorkQueueManager::queueLoadHTMLString): Ditto. * WebKitTestRunner/cocoa/UIScriptControllerCocoa.h: Make most functions private. * WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm: (WTR::UIScriptControllerCocoa::overridePreference): Use toWTFString. * WebKitTestRunner/ios/UIScriptControllerIOS.h: Marked the class final and made most functions private. * WebKitTestRunner/ios/UIScriptControllerIOS.mm: (WTR::arrayLength): Deleted. Use the one in JSBasics.h. (WTR::parseModifierArray): Use the new toWTFString overload. (WTR::UIScriptControllerIOS::typeCharacterUsingHardwareKeyboard): Ditto. * WebKitTestRunner/mac/EventSenderProxy.mm: (WTR::EventSenderProxy::EventSenderProxy): Initialize in the class definition. (WTR::EventSenderProxy::keyDown): Use toWTFString. * WebKitTestRunner/mac/UIScriptControllerMac.h: Marked the class final and made most functions private. Canonical link: https://commits.webkit.org/229883@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@267761 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent c17b92c commit 056434f

80 files changed

Lines changed: 3054 additions & 4562 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/JavaScriptCore/API/JSRetainPtr.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2005-2018 Apple Inc. All rights reserved.
2+
* Copyright (C) 2005-2020 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -29,13 +29,16 @@
2929
#pragma once
3030

3131
#include <JavaScriptCore/JSContextRef.h>
32+
#include <JavaScriptCore/JSObjectRef.h>
3233
#include <JavaScriptCore/JSStringRef.h>
3334
#include <algorithm>
3435

35-
inline void JSRetain(JSStringRef string) { JSStringRetain(string); }
36-
inline void JSRelease(JSStringRef string) { JSStringRelease(string); }
36+
inline void JSRetain(JSClassRef context) { JSClassRetain(context); }
37+
inline void JSRelease(JSClassRef context) { JSClassRelease(context); }
3738
inline void JSRetain(JSGlobalContextRef context) { JSGlobalContextRetain(context); }
3839
inline void JSRelease(JSGlobalContextRef context) { JSGlobalContextRelease(context); }
40+
inline void JSRetain(JSStringRef string) { JSStringRetain(string); }
41+
inline void JSRelease(JSStringRef string) { JSStringRelease(string); }
3942

4043
enum AdoptTag { Adopt };
4144

@@ -74,6 +77,7 @@ template<typename T> class JSRetainPtr {
7477
T m_ptr { nullptr };
7578
};
7679

80+
JSRetainPtr<JSClassRef> adopt(JSClassRef);
7781
JSRetainPtr<JSStringRef> adopt(JSStringRef);
7882
JSRetainPtr<JSGlobalContextRef> adopt(JSGlobalContextRef);
7983

@@ -82,6 +86,11 @@ template<typename T> inline JSRetainPtr<T>::JSRetainPtr(AdoptTag, T ptr)
8286
{
8387
}
8488

89+
inline JSRetainPtr<JSClassRef> adopt(JSClassRef o)
90+
{
91+
return JSRetainPtr<JSClassRef>(Adopt, o);
92+
}
93+
8594
inline JSRetainPtr<JSStringRef> adopt(JSStringRef o)
8695
{
8796
return JSRetainPtr<JSStringRef>(Adopt, o);

Source/JavaScriptCore/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2020-09-26 Darin Adler <darin@apple.com>
2+
3+
Refactor test runner code to cut down on copy/paste code and long-winded repetitive idioms
4+
https://bugs.webkit.org/show_bug.cgi?id=217028
5+
6+
Reviewed by Sam Weinig.
7+
8+
* API/JSRetainPtr.h: Added support for JSClassRef.
9+
110
2020-09-29 Yusuke Suzuki <ysuzuki@apple.com>
211

312
[JSC] Annotate JIT operation functions called from B3 etc.

Tools/ChangeLog

Lines changed: 757 additions & 0 deletions
Large diffs are not rendered by default.

Tools/DumpRenderTree/AccessibilityController.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved.
2+
* Copyright (C) 2008-2020 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -30,6 +30,7 @@
3030
#include "AccessibilityController.h"
3131

3232
#include "AccessibilityUIElement.h"
33+
#include "JSBasics.h"
3334

3435
// Static Value Getters
3536

@@ -47,15 +48,9 @@ static JSValueRef getRootElementCallback(JSContextRef context, JSObjectRef thisO
4748

4849
// Object Creation
4950

50-
void AccessibilityController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
51+
void AccessibilityController::makeWindowObject(JSContextRef context)
5152
{
52-
auto accessibilityControllerStr = adopt(JSStringCreateWithUTF8CString("accessibilityController"));
53-
54-
JSClassRef classRef = getJSClass();
55-
JSValueRef accessibilityControllerObject = JSObjectMake(context, classRef, this);
56-
JSClassRelease(classRef);
57-
58-
JSObjectSetProperty(context, windowObject, accessibilityControllerStr.get(), accessibilityControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
53+
WTR::setGlobalObjectProperty(context, "accessibilityController", JSObjectMake(context, createJSClass().get(), this));
5954
}
6055

6156
static JSValueRef logFocusEventsCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*)
@@ -152,9 +147,9 @@ static JSValueRef getPlatformNameCallback(JSContextRef context, JSObjectRef this
152147
return JSValueMakeString(context, platformName.get());
153148
}
154149

155-
JSClassRef AccessibilityController::getJSClass()
150+
JSRetainPtr<JSClassRef> AccessibilityController::createJSClass()
156151
{
157-
static JSStaticFunction staticFunctions[] = {
152+
static constexpr JSStaticFunction functions[] = {
158153
{ "logFocusEvents", logFocusEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
159154
{ "logValueChangeEvents", logValueChangeEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
160155
{ "logScrollingStartEvents", logScrollingStartEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
@@ -166,21 +161,18 @@ JSClassRef AccessibilityController::getJSClass()
166161
{ "enableEnhancedAccessibility", enableEnhancedAccessibilityCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
167162
{ 0, 0, 0 }
168163
};
169-
170-
static JSStaticValue staticValues[] = {
164+
static constexpr JSStaticValue values[] = {
171165
{ "focusedElement", getFocusedElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
172166
{ "rootElement", getRootElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
173167
{ "enhancedAccessibilityEnabled", getEnhancedAccessibilityEnabledCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
174168
{ "platformName", getPlatformNameCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
175169
{ 0, 0, 0, 0 }
176170
};
177-
178-
static JSClassDefinition classDefinition = {
179-
0, kJSClassAttributeNone, "AccessibilityController", 0, staticValues, staticFunctions,
171+
static const JSClassDefinition definition = {
172+
0, kJSClassAttributeNone, "AccessibilityController", 0, values, functions,
180173
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
181174
};
182-
183-
return JSClassCreate(&classDefinition);
175+
return adopt(JSClassCreate(&definition));
184176
}
185177

186178
void AccessibilityController::resetToConsistentState()

Tools/DumpRenderTree/AccessibilityController.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved.
2+
* Copyright (C) 2008-2020 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -47,7 +47,7 @@ class AccessibilityController {
4747
AccessibilityController();
4848
~AccessibilityController();
4949

50-
void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);
50+
void makeWindowObject(JSContextRef);
5151

5252
// Controller Methods - platform-independent implementations
5353
AccessibilityUIElement rootElement();
@@ -83,7 +83,7 @@ class AccessibilityController {
8383
#endif
8484

8585
private:
86-
static JSClassRef getJSClass();
86+
static JSRetainPtr<JSClassRef> createJSClass();
8787

8888
#if PLATFORM(WIN)
8989
HWINEVENTHOOK m_focusEventHook { nullptr };

Tools/DumpRenderTree/AccessibilityUIElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static JSValueRef uiElementCountForSearchPredicateCallback(JSContextRef context,
206206
AccessibilityUIElement* startElement = nullptr;
207207
bool isDirectionNext = true;
208208
JSValueRef searchKey = nullptr;
209-
JSRetainPtr<JSStringRef> searchText = nullptr;
209+
JSRetainPtr<JSStringRef> searchText;
210210
bool visibleOnly = false;
211211
bool immediateDescendantsOnly = false;
212212
if (argumentCount >= 5 && argumentCount <= 6) {

Tools/DumpRenderTree/Bindings/CodeGeneratorDumpRenderTree.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2016 Apple Inc. All rights reserved.
1+
# Copyright (C) 2016-2020 Apple Inc. All rights reserved.
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -431,10 +431,10 @@ sub _platformTypeConstructor
431431
{
432432
my ($self, $type, $argumentName) = @_;
433433

434-
return "JSValueToNullableBoolean(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;
434+
return "toOptionalBool(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;
435435
return "JSValueToBoolean(context, $argumentName)" if $type->name eq "boolean";
436436
return "$argumentName" if $type->name eq "object";
437-
return "adopt(JSValueToStringCopy(context, $argumentName, nullptr))" if $$self{codeGenerator}->IsStringType($type);
437+
return "createJSString(context, $argumentName)" if $$self{codeGenerator}->IsStringType($type);
438438
return "JSValueToNumber(context, $argumentName, nullptr)" if $$self{codeGenerator}->IsPrimitiveType($type);
439439
return "to" . _implementationClassName($type) . "(context, $argumentName)";
440440
}
@@ -472,11 +472,11 @@ sub _returnExpression
472472
my ($self, $returnType, $expression) = @_;
473473

474474
return "JSValueMakeUndefined(context)" if $returnType->name eq "undefined";
475-
return "JSValueMakeBooleanOrNull(context, ${expression})" if $returnType->name eq "boolean" && $returnType->isNullable;
475+
return "makeValue(context, ${expression})" if $returnType->name eq "boolean" && $returnType->isNullable;
476476
return "JSValueMakeBoolean(context, ${expression})" if $returnType->name eq "boolean";
477477
return "${expression}" if $returnType->name eq "object";
478478
return "JSValueMakeNumber(context, ${expression})" if $$self{codeGenerator}->IsPrimitiveType($returnType);
479-
return "JSValueMakeStringOrNull(context, ${expression}.get())" if $$self{codeGenerator}->IsStringType($returnType);
479+
return "makeValue(context, ${expression}.get())" if $$self{codeGenerator}->IsStringType($returnType);
480480
return "toJS(context, WTF::getPtr(${expression}))";
481481
}
482482

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2007 Apple Inc. All rights reserved.
2+
* Copyright (C) 2007-2020 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -29,72 +29,49 @@
2929
#include "config.h"
3030
#include "GCController.h"
3131

32-
#include <JavaScriptCore/JSObjectRef.h>
33-
#include <JavaScriptCore/JSRetainPtr.h>
34-
35-
GCController::GCController()
36-
{
37-
}
38-
39-
GCController::~GCController()
40-
{
41-
}
32+
#include "JSBasics.h"
4233

4334
// Static Functions
4435

4536
static JSValueRef collectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
4637
{
47-
GCController* controller = static_cast<GCController*>(JSObjectGetPrivate(thisObject));
48-
controller->collect();
38+
auto& controller = *static_cast<GCController*>(JSObjectGetPrivate(thisObject));
39+
controller.collect();
4940
return JSValueMakeUndefined(context);
5041
}
5142

5243
static JSValueRef collectOnAlternateThreadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
5344
{
54-
bool waitUntilDone = false;
55-
if (argumentCount > 0)
56-
waitUntilDone = JSValueToBoolean(context, arguments[0]);
57-
58-
GCController* controller = static_cast<GCController*>(JSObjectGetPrivate(thisObject));
59-
controller->collectOnAlternateThread(waitUntilDone);
60-
45+
auto& controller = *static_cast<GCController*>(JSObjectGetPrivate(thisObject));
46+
bool waitUntilDone = argumentCount > 0 && JSValueToBoolean(context, arguments[0]);
47+
controller.collectOnAlternateThread(waitUntilDone);
6148
return JSValueMakeUndefined(context);
6249
}
6350

6451
static JSValueRef getJSObjectCountCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
6552
{
66-
GCController* controller = static_cast<GCController*>(JSObjectGetPrivate(thisObject));
67-
size_t jsObjectCount = controller->getJSObjectCount();
68-
69-
return JSValueMakeNumber(context, jsObjectCount);
53+
auto& controller = *static_cast<GCController*>(JSObjectGetPrivate(thisObject));
54+
return JSValueMakeNumber(context, controller.getJSObjectCount());
7055
}
7156

7257
// Object Creation
7358

74-
void GCController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
59+
void GCController::makeWindowObject(JSContextRef context)
7560
{
76-
auto gcControllerStr = adopt(JSStringCreateWithUTF8CString("GCController"));
77-
78-
JSClassRef classRef = getJSClass();
79-
JSValueRef gcControllerObject = JSObjectMake(context, classRef, this);
80-
JSClassRelease(classRef);
81-
82-
JSObjectSetProperty(context, windowObject, gcControllerStr.get(), gcControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
61+
WTR::setGlobalObjectProperty(context, "GCController", JSObjectMake(context, createJSClass().get(), this));
8362
}
8463

85-
JSClassRef GCController::getJSClass()
64+
JSRetainPtr<JSClassRef> GCController::createJSClass()
8665
{
87-
static JSStaticFunction staticFunctions[] = {
66+
static constexpr JSStaticFunction functions[] = {
8867
{ "collect", collectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
8968
{ "collectOnAlternateThread", collectOnAlternateThreadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
9069
{ "getJSObjectCount", getJSObjectCountCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
9170
{ 0, 0, 0 }
9271
};
93-
94-
static JSClassDefinition classDefinition = {
95-
0, kJSClassAttributeNone, "GCController", 0, 0, staticFunctions,
72+
static const JSClassDefinition definition = {
73+
0, kJSClassAttributeNone, "GCController", 0, 0, functions,
9674
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
9775
};
98-
99-
return JSClassCreate(&classDefinition);
76+
return adopt(JSClassCreate(&definition));
10077
}

Tools/DumpRenderTree/GCController.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,21 @@
2626
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
2828

29-
#ifndef GCController_h
30-
#define GCController_h
29+
#pragma once
3130

32-
#include <JavaScriptCore/JSObjectRef.h>
31+
#include <JavaScriptCore/JSRetainPtr.h>
3332
#include <wtf/FastMalloc.h>
3433

3534
class GCController {
3635
WTF_MAKE_FAST_ALLOCATED;
3736
public:
38-
GCController();
39-
~GCController();
40-
41-
void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);
37+
void makeWindowObject(JSContextRef);
4238

4339
// Controller Methods - platfrom independant implementations
4440
void collect() const;
4541
void collectOnAlternateThread(bool waitUntilDone) const;
4642
size_t getJSObjectCount() const;
4743

4844
private:
49-
static JSClassRef getJSClass();
45+
static JSRetainPtr<JSClassRef> createJSClass();
5046
};
51-
52-
#endif // GCController_h

0 commit comments

Comments
 (0)