[JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
authoryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Oct 2018 18:29:44 +0000 (18:29 +0000)
committeryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Oct 2018 18:29:44 +0000 (18:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190429

Reviewed by Saam Barati.

Source/JavaScriptCore:

Some createXXX functions can fail. But sometimes the caller does not perform error checking.
To make it explicit that these functions can fail, we rename these functions from createXXX
to tryCreateXXX. In this patch, we focus on non-JS-managed factory functions. If the factory
function does not fail, it should return Ref<>. Otherwise, it should be named as tryCreateXXX
and it should return RefPtr<>.

This patch mainly focuses on TypedArray factory functions. Previously, these functions are
`RefPtr<XXXArray> create(...)`. This patch changes them to `RefPtr<XXXArray> tryCreate(...)`.
And we also introduce `Ref<XXXArray> create(...)` function which internally performs
RELEASE_ASSERT on the result of `tryCreate(...)`.

And we also convert OpaqueJSString::create to OpaqueJSString::tryCreate since it can fail.

This change actually finds one place which does not perform any null checkings while it uses
`RefPtr<> create(...)` function.

* API/JSCallbackObjectFunctions.h:
(JSC::JSCallbackObject<Parent>::getOwnPropertySlot):
(JSC::JSCallbackObject<Parent>::put):
(JSC::JSCallbackObject<Parent>::putByIndex):
(JSC::JSCallbackObject<Parent>::deleteProperty):
(JSC::JSCallbackObject<Parent>::callbackGetter):
* API/JSClassRef.h:
(StaticValueEntry::StaticValueEntry):
* API/JSContext.mm:
(-[JSContext evaluateScript:withSourceURL:]):
(-[JSContext setName:]):
* API/JSContextRef.cpp:
(JSGlobalContextCopyName):
(JSContextCreateBacktrace):
* API/JSObjectRef.cpp:
(JSObjectCopyPropertyNames):
* API/JSScriptRef.cpp:
* API/JSStringRef.cpp:
(JSStringCreateWithCharactersNoCopy):
* API/JSValue.mm:
(+[JSValue valueWithNewRegularExpressionFromPattern:flags:inContext:]):
(+[JSValue valueWithNewErrorFromMessage:inContext:]):
(+[JSValue valueWithNewSymbolFromDescription:inContext:]):
(performPropertyOperation):
(-[JSValue invokeMethod:withArguments:]):
(containerValueToObject):
(objectToValueWithoutCopy):
(objectToValue):
* API/JSValueRef.cpp:
(JSValueCreateJSONString):
(JSValueToStringCopy):
* API/OpaqueJSString.cpp:
(OpaqueJSString::tryCreate):
(OpaqueJSString::create): Deleted.
* API/OpaqueJSString.h:
* API/glib/JSCContext.cpp:
(evaluateScriptInContext):
* API/glib/JSCValue.cpp:
(jsc_value_new_string_from_bytes):
* ftl/FTLLazySlowPath.h:
(JSC::FTL::LazySlowPath::createGenerator):
* ftl/FTLLazySlowPathCall.h:
(JSC::FTL::createLazyCallGenerator):
* ftl/FTLOSRExit.cpp:
(JSC::FTL::OSRExitDescriptor::emitOSRExit):
(JSC::FTL::OSRExitDescriptor::emitOSRExitLater):
(JSC::FTL::OSRExitDescriptor::prepareOSRExitHandle):
* ftl/FTLOSRExit.h:
* ftl/FTLPatchpointExceptionHandle.cpp:
(JSC::FTL::PatchpointExceptionHandle::create):
(JSC::FTL::PatchpointExceptionHandle::createHandle):
* ftl/FTLPatchpointExceptionHandle.h:
* heap/EdenGCActivityCallback.h:
(JSC::GCActivityCallback::tryCreateEdenTimer):
(JSC::GCActivityCallback::createEdenTimer): Deleted.
* heap/FullGCActivityCallback.h:
(JSC::GCActivityCallback::tryCreateFullTimer):
(JSC::GCActivityCallback::createFullTimer): Deleted.
* heap/GCActivityCallback.h:
* heap/Heap.cpp:
(JSC::Heap::Heap):
* inspector/AsyncStackTrace.cpp:
(Inspector::AsyncStackTrace::create):
* inspector/AsyncStackTrace.h:
* jsc.cpp:
(fillBufferWithContentsOfFile):
* runtime/ArrayBuffer.h:
* runtime/GenericTypedArrayView.h:
* runtime/GenericTypedArrayViewInlines.h:
(JSC::GenericTypedArrayView<Adaptor>::create):
(JSC::GenericTypedArrayView<Adaptor>::tryCreate):
(JSC::GenericTypedArrayView<Adaptor>::createUninitialized):
(JSC::GenericTypedArrayView<Adaptor>::tryCreateUninitialized):
(JSC::GenericTypedArrayView<Adaptor>::subarray const):
* runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::possiblySharedImpl):
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::JSGenericTypedArrayView<Adaptor>::possiblySharedTypedImpl):
(JSC::JSGenericTypedArrayView<Adaptor>::unsharedTypedImpl):
* wasm/WasmMemory.cpp:
(JSC::Wasm::Memory::create):
(JSC::Wasm::Memory::tryCreate):
* wasm/WasmMemory.h:
* wasm/WasmTable.cpp:
(JSC::Wasm::Table::tryCreate):
(JSC::Wasm::Table::create): Deleted.
* wasm/WasmTable.h:
* wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::create):
* wasm/js/JSWebAssemblyMemory.cpp:
(JSC::JSWebAssemblyMemory::JSWebAssemblyMemory):
* wasm/js/WebAssemblyMemoryConstructor.cpp:
(JSC::constructJSWebAssemblyMemory):
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::link):
* wasm/js/WebAssemblyTableConstructor.cpp:
(JSC::constructJSWebAssemblyTable):

Source/WebCore:

Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.

* Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp:
(WebCore::CDMSessionClearKey::cachedKeyForKeyID const):
* Modules/plugins/QuickTimePluginReplacement.mm:
(WebCore::jsValueWithDictionaryInContext):
* Modules/webaudio/AudioBuffer.cpp:
(WebCore::AudioBuffer::AudioBuffer):
(WebCore::AudioBuffer::getChannelData):
* Modules/webvr/VREyeParameters.cpp:
(WebCore::VREyeParameters::offset const):
* Modules/webvr/VRFrameData.cpp:
(WebCore::matrixToArray):
* Modules/webvr/VRPose.cpp:
(WebCore::optionalFloat3ToJSCArray):
(WebCore::VRPose::position const):
(WebCore::VRPose::orientation const):
* Modules/webvr/VRStageParameters.cpp:
(WebCore::VRStageParameters::sittingToStandingTransform const):
* bindings/js/ReadableStreamDefaultController.h:
(WebCore::ReadableStreamDefaultController::enqueue):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneDeserializer::readArrayBufferView):
* crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:
(WebCore::CryptoKeyRSA::algorithm const):
* crypto/mac/CryptoKeyRSAMac.cpp:
(WebCore::CryptoKeyRSA::algorithm const):
* css/DOMMatrixReadOnly.cpp:
(WebCore::DOMMatrixReadOnly::toFloat32Array const):
(WebCore::DOMMatrixReadOnly::toFloat64Array const):
* css/FontFace.cpp:
(WebCore::FontFace::create):
* dom/TextEncoder.cpp:
(WebCore::TextEncoder::encode const):
* html/ImageData.cpp:
(WebCore::ImageData::ImageData):
* html/ImageData.h:
(WebCore::ImageData::data const):
(): Deleted.
* html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::bufferData):
(WebCore::WebGL2RenderingContext::bufferSubData):
(WebCore::WebGL2RenderingContext::getInternalformatParameter):
(WebCore::WebGL2RenderingContext::getParameter):
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::getParameter):
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::getUniform):
(WebCore::WebGLRenderingContextBase::getVertexAttrib):
(WebCore::WebGLRenderingContextBase::getWebGLFloatArrayParameter):
(WebCore::WebGLRenderingContextBase::getWebGLIntArrayParameter):
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitData):
* platform/graphics/avfoundation/cf/CDMSessionAVFoundationCF.cpp:
(WebCore::CDMSessionAVFoundationCF::generateKeyRequest):
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::AVFWrapper::shouldWaitForLoadingOfResource):
* platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm:
(WebCore::CDMSessionAVContentKeySession::generateKeyRequest):
(WebCore::CDMSessionAVContentKeySession::releaseKeys):
(WebCore::CDMSessionAVContentKeySession::update):
(WebCore::CDMSessionAVContentKeySession::generateKeyReleaseMessage):
* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
(WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
* platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm:
(WebCore::CDMSessionAVStreamSession::generateKeyRequest):
(WebCore::CDMSessionAVStreamSession::releaseKeys):
(WebCore::CDMSessionAVStreamSession::generateKeyReleaseMessage):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
* platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
(WebCore::MediaSampleAVFObjC::getRGBAImageData const):
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID):
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::getImageData):
* platform/graphics/cg/ImageBufferDataCG.cpp:
(WebCore::ImageBufferData::getData const):
* platform/graphics/filters/FEGaussianBlur.cpp:
(WebCore::FEGaussianBlur::platformApplySoftware):
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::unmultipliedResult):
(WebCore::FilterEffect::premultipliedResult):
(WebCore::FilterEffect::copyUnmultipliedResult):
(WebCore::FilterEffect::copyPremultipliedResult):
(WebCore::FilterEffect::createUnmultipliedImageResult):
(WebCore::FilterEffect::createPremultipliedImageResult):
* platform/graphics/win/ImageBufferDataDirect2D.cpp:
(WebCore::ImageBufferData::getData const):
* platform/mac/SerializedPlatformRepresentationMac.mm:
(WebCore::jsValueWithDictionaryInContext):
* platform/mock/mediasource/MockBox.cpp:
(WebCore::MockBox::peekType):
(WebCore::MockBox::peekLength):
(WebCore::MockTrackBox::MockTrackBox):
(WebCore::MockInitializationBox::MockInitializationBox):
(WebCore::MockSampleBox::MockSampleBox):
* rendering/shapes/Shape.cpp:
(WebCore::Shape::createRasterShape):
* testing/LegacyMockCDM.cpp:
(WebCore::initDataPrefix):
(WebCore::keyPrefix):
(WebCore::keyRequest):

Source/WebKit:

Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.

* Shared/API/c/WKString.cpp:
(WKStringCopyJSString):
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::toJSValue):
(WebKit::callPropertyFunction):
(WebKit::WebAutomationSessionProxy::scriptObjectForFrame):
(WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction):
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::runScriptsInPDFDocument):

Source/WebKitLegacy/ios:

Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.

* WebView/WebPDFViewIOS.mm:
(-[WebPDFView finishedLoadingWithDataSource:]):
* WebView/WebPDFViewPlaceholder.mm:
(-[WebPDFViewPlaceholder _evaluateJSForDocument:]):

Source/WebKitLegacy/mac:

Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.

* WebView/WebPDFRepresentation.mm:
(-[WebPDFRepresentation finishedLoadingWithDataSource:]):

Tools:

* TestWebKitAPI/Tests/WebCore/mac/GPUBuffer.mm:
(TestWebKitAPI::TEST_F):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237009 268f45cc-cd09-0410-ab3c-d52691b4dbfc

90 files changed:
Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
Source/JavaScriptCore/API/JSClassRef.h
Source/JavaScriptCore/API/JSContext.mm
Source/JavaScriptCore/API/JSContextRef.cpp
Source/JavaScriptCore/API/JSObjectRef.cpp
Source/JavaScriptCore/API/JSScriptRef.cpp
Source/JavaScriptCore/API/JSStringRef.cpp
Source/JavaScriptCore/API/JSValue.mm
Source/JavaScriptCore/API/JSValueRef.cpp
Source/JavaScriptCore/API/OpaqueJSString.cpp
Source/JavaScriptCore/API/OpaqueJSString.h
Source/JavaScriptCore/API/glib/JSCContext.cpp
Source/JavaScriptCore/API/glib/JSCValue.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/ftl/FTLLazySlowPath.h
Source/JavaScriptCore/ftl/FTLLazySlowPathCall.h
Source/JavaScriptCore/ftl/FTLOSRExit.cpp
Source/JavaScriptCore/ftl/FTLOSRExit.h
Source/JavaScriptCore/ftl/FTLPatchpointExceptionHandle.cpp
Source/JavaScriptCore/ftl/FTLPatchpointExceptionHandle.h
Source/JavaScriptCore/heap/EdenGCActivityCallback.h
Source/JavaScriptCore/heap/FullGCActivityCallback.h
Source/JavaScriptCore/heap/GCActivityCallback.h
Source/JavaScriptCore/heap/Heap.cpp
Source/JavaScriptCore/inspector/AsyncStackTrace.cpp
Source/JavaScriptCore/inspector/AsyncStackTrace.h
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/ArrayBuffer.h
Source/JavaScriptCore/runtime/GenericTypedArrayView.h
Source/JavaScriptCore/runtime/GenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/JSArrayBufferView.cpp
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h
Source/JavaScriptCore/wasm/WasmMemory.cpp
Source/JavaScriptCore/wasm/WasmMemory.h
Source/JavaScriptCore/wasm/WasmTable.cpp
Source/JavaScriptCore/wasm/WasmTable.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp
Source/WebCore/Modules/plugins/QuickTimePluginReplacement.mm
Source/WebCore/Modules/webaudio/AudioBuffer.cpp
Source/WebCore/Modules/webvr/VREyeParameters.cpp
Source/WebCore/Modules/webvr/VRFrameData.cpp
Source/WebCore/Modules/webvr/VRPose.cpp
Source/WebCore/Modules/webvr/VRStageParameters.cpp
Source/WebCore/bindings/js/ReadableStreamDefaultController.h
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp
Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp
Source/WebCore/css/DOMMatrixReadOnly.cpp
Source/WebCore/css/FontFace.cpp
Source/WebCore/dom/TextEncoder.cpp
Source/WebCore/html/ImageData.cpp
Source/WebCore/html/ImageData.h
Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
Source/WebCore/platform/graphics/avfoundation/cf/CDMSessionAVFoundationCF.cpp
Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp
Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm
Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp
Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp
Source/WebCore/platform/graphics/filters/FilterEffect.cpp
Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp
Source/WebCore/platform/mac/SerializedPlatformRepresentationMac.mm
Source/WebCore/platform/mock/mediasource/MockBox.cpp
Source/WebCore/rendering/shapes/Shape.cpp
Source/WebCore/testing/LegacyMockCDM.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/API/c/WKString.cpp
Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp
Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
Source/WebKitLegacy/ios/ChangeLog
Source/WebKitLegacy/ios/WebView/WebPDFViewIOS.mm
Source/WebKitLegacy/ios/WebView/WebPDFViewPlaceholder.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebPDFRepresentation.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/mac/GPUBuffer.mm

index 15b8608..4f4b7d7 100644 (file)
@@ -155,7 +155,7 @@ bool JSCallbackObject<Parent>::getOwnPropertySlot(JSObject* object, ExecState* e
             // optional optimization to bypass getProperty in cases when we only need to know if the property exists
             if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
                 if (!propertyNameRef)
-                    propertyNameRef = OpaqueJSString::create(name);
+                    propertyNameRef = OpaqueJSString::tryCreate(name);
                 JSLock::DropAllLocks dropAllLocks(exec);
                 if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
                     slot.setCustom(thisObject, PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum, callbackGetter);
@@ -163,7 +163,7 @@ bool JSCallbackObject<Parent>::getOwnPropertySlot(JSObject* object, ExecState* e
                 }
             } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
                 if (!propertyNameRef)
-                    propertyNameRef = OpaqueJSString::create(name);
+                    propertyNameRef = OpaqueJSString::tryCreate(name);
                 JSValueRef exception = 0;
                 JSValueRef value;
                 {
@@ -252,7 +252,7 @@ bool JSCallbackObject<Parent>::put(JSCell* cell, ExecState* exec, PropertyName p
         for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
             if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
                 if (!propertyNameRef)
-                    propertyNameRef = OpaqueJSString::create(name);
+                    propertyNameRef = OpaqueJSString::tryCreate(name);
                 JSValueRef exception = 0;
                 bool result;
                 {
@@ -316,7 +316,7 @@ bool JSCallbackObject<Parent>::putByIndex(JSCell* cell, ExecState* exec, unsigne
     for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
         if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
             if (!propertyNameRef)
-                propertyNameRef = OpaqueJSString::create(propertyName.impl());
+                propertyNameRef = OpaqueJSString::tryCreate(propertyName.impl());
             JSValueRef exception = 0;
             bool result;
             {
@@ -375,7 +375,7 @@ bool JSCallbackObject<Parent>::deleteProperty(JSCell* cell, ExecState* exec, Pro
         for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
             if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
                 if (!propertyNameRef)
-                    propertyNameRef = OpaqueJSString::create(name);
+                    propertyNameRef = OpaqueJSString::tryCreate(name);
                 JSValueRef exception = 0;
                 bool result;
                 {
@@ -679,7 +679,7 @@ EncodedJSValue JSCallbackObject<Parent>::callbackGetter(ExecState* exec, Encoded
         for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
             if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
                 if (!propertyNameRef)
-                    propertyNameRef = OpaqueJSString::create(name);
+                    propertyNameRef = OpaqueJSString::tryCreate(name);
                 JSValueRef exception = 0;
                 JSValueRef value;
                 {
index fa024d3..90c4f53 100644 (file)
@@ -37,7 +37,10 @@ struct StaticValueEntry {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes, String& propertyName)
-    : getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes), propertyNameRef(OpaqueJSString::create(propertyName))
+        : getProperty(_getProperty)
+        , setProperty(_setProperty)
+        , attributes(_attributes)
+        , propertyNameRef(OpaqueJSString::tryCreate(propertyName))
     {
     }
     
index 7f85696..27566f4 100644 (file)
 - (JSValue *)evaluateScript:(NSString *)script withSourceURL:(NSURL *)sourceURL
 {
     JSValueRef exceptionValue = nullptr;
-    auto scriptJS = OpaqueJSString::create(script);
-    auto sourceURLJS = OpaqueJSString::create([sourceURL absoluteString]);
+    auto scriptJS = OpaqueJSString::tryCreate(script);
+    auto sourceURLJS = OpaqueJSString::tryCreate([sourceURL absoluteString]);
     JSValueRef result = JSEvaluateScript(m_context, scriptJS.get(), nullptr, sourceURLJS.get(), 0, &exceptionValue);
 
     if (exceptionValue)
 
 - (void)setName:(NSString *)name
 {
-    JSGlobalContextSetName(m_context, OpaqueJSString::create(name).get());
+    JSGlobalContextSetName(m_context, OpaqueJSString::tryCreate(name).get());
 }
 
 - (BOOL)_remoteInspectionEnabled
index f3c0fd1..e18dfd2 100644 (file)
@@ -232,7 +232,7 @@ JSStringRef JSGlobalContextCopyName(JSGlobalContextRef ctx)
     if (name.isNull())
         return 0;
 
-    return OpaqueJSString::create(name).leakRef();
+    return OpaqueJSString::tryCreate(name).leakRef();
 }
 
 void JSGlobalContextSetName(JSGlobalContextRef ctx, JSStringRef name)
@@ -316,7 +316,7 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
     BacktraceFunctor functor(builder, maxStackSize);
     frame->iterate(functor);
 
-    return OpaqueJSString::create(builder.toString()).leakRef();
+    return OpaqueJSString::tryCreate(builder.toString()).leakRef();
 }
 
 bool JSGlobalContextGetRemoteInspectionEnabled(JSGlobalContextRef ctx)
index d8d2df1..51169c4 100644 (file)
@@ -820,7 +820,7 @@ JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef o
     size_t size = array.size();
     propertyNames->array.reserveInitialCapacity(size);
     for (size_t i = 0; i < size; ++i)
-        propertyNames->array.uncheckedAppend(OpaqueJSString::create(array[i].string()).releaseNonNull());
+        propertyNames->array.uncheckedAppend(OpaqueJSString::tryCreate(array[i].string()).releaseNonNull());
 
     return JSPropertyNameArrayRetain(propertyNames);
 }
index 33f59a3..bb720db 100644 (file)
@@ -99,7 +99,7 @@ JSScriptRef JSScriptCreateReferencingImmortalASCIIText(JSContextGroupRef context
     ParserError error;
     if (!parseScript(vm, SourceCode(result.copyRef()), error)) {
         if (errorMessage)
-            *errorMessage = OpaqueJSString::create(error.message()).leakRef();
+            *errorMessage = OpaqueJSString::tryCreate(error.message()).leakRef();
         if (errorLine)
             *errorLine = error.line();
         return nullptr;
@@ -121,7 +121,7 @@ JSScriptRef JSScriptCreateFromString(JSContextGroupRef contextGroup, JSStringRef
     ParserError error;
     if (!parseScript(vm, SourceCode(result.copyRef()), error)) {
         if (errorMessage)
-            *errorMessage = OpaqueJSString::create(error.message()).leakRef();
+            *errorMessage = OpaqueJSString::tryCreate(error.message()).leakRef();
         if (errorLine)
             *errorLine = error.line();
         return nullptr;
index 1683aae..e644f1a 100644 (file)
@@ -62,7 +62,7 @@ JSStringRef JSStringCreateWithUTF8CString(const char* string)
 JSStringRef JSStringCreateWithCharactersNoCopy(const JSChar* chars, size_t numChars)
 {
     initializeThreading();
-    return OpaqueJSString::create(StringImpl::createWithoutCopying(reinterpret_cast<const UChar*>(chars), numChars)).leakRef();
+    return OpaqueJSString::tryCreate(StringImpl::createWithoutCopying(reinterpret_cast<const UChar*>(chars), numChars)).leakRef();
 }
 
 JSStringRef JSStringRetain(JSStringRef string)
index d79742a..9e534b0 100644 (file)
@@ -126,15 +126,15 @@ NSString * const JSPropertyDescriptorSetKey = @"set";
 
 + (JSValue *)valueWithNewRegularExpressionFromPattern:(NSString *)pattern flags:(NSString *)flags inContext:(JSContext *)context
 {
-    auto patternString = OpaqueJSString::create(pattern);
-    auto flagsString = OpaqueJSString::create(flags);
+    auto patternString = OpaqueJSString::tryCreate(pattern);
+    auto flagsString = OpaqueJSString::tryCreate(flags);
     JSValueRef arguments[2] = { JSValueMakeString([context JSGlobalContextRef], patternString.get()), JSValueMakeString([context JSGlobalContextRef], flagsString.get()) };
     return [JSValue valueWithJSValueRef:JSObjectMakeRegExp([context JSGlobalContextRef], 2, arguments, 0) inContext:context];
 }
 
 + (JSValue *)valueWithNewErrorFromMessage:(NSString *)message inContext:(JSContext *)context
 {
-    auto string = OpaqueJSString::create(message);
+    auto string = OpaqueJSString::tryCreate(message);
     JSValueRef argument = JSValueMakeString([context JSGlobalContextRef], string.get());
     return [JSValue valueWithJSValueRef:JSObjectMakeError([context JSGlobalContextRef], 1, &argument, 0) inContext:context];
 }
@@ -151,7 +151,7 @@ NSString * const JSPropertyDescriptorSetKey = @"set";
 
 + (JSValue *)valueWithNewSymbolFromDescription:(NSString *)description inContext:(JSContext *)context
 {
-    auto string = OpaqueJSString::create(description);
+    auto string = OpaqueJSString::tryCreate(description);
     return [JSValue valueWithJSValueRef:JSValueMakeSymbol([context JSGlobalContextRef], string.get()) inContext:context];
 }
 
@@ -292,7 +292,7 @@ inline Expected<Result, JSValueRef> performPropertyOperation(NSStringFunction st
     Result result;
     // If it's a NSString already, reduce indirection and just pass the NSString.
     if ([propertyKey isKindOfClass:[NSString class]]) {
-        auto name = OpaqueJSString::create((NSString *)propertyKey);
+        auto name = OpaqueJSString::tryCreate((NSString *)propertyKey);
         result = stringFunction([context JSGlobalContextRef], object, name.get(), arguments..., &exception);
     } else
         result = jsFunction([context JSGlobalContextRef], object, [[JSValue valueWithObject:propertyKey inContext:context] JSValueRef], arguments..., &exception);
@@ -520,7 +520,7 @@ inline Expected<Result, JSValueRef> performPropertyOperation(NSStringFunction st
     if (exception)
         return [_context valueFromNotifyException:exception];
 
-    auto name = OpaqueJSString::create(method);
+    auto name = OpaqueJSString::tryCreate(method);
     JSValueRef function = JSObjectGetProperty([_context JSGlobalContextRef], thisObject, name.get(), &exception);
     if (exception)
         return [_context valueFromNotifyException:exception];
@@ -774,7 +774,7 @@ static id containerValueToObject(JSGlobalContextRef context, JSContainerConverto
             ASSERT([current.objc isKindOfClass:[NSMutableArray class]]);
             NSMutableArray *array = (NSMutableArray *)current.objc;
         
-            auto lengthString = OpaqueJSString::create("length"_s);
+            auto lengthString = OpaqueJSString::tryCreate("length"_s);
             unsigned length = JSC::toUInt32(JSValueToNumber(context, JSObjectGetProperty(context, js, lengthString.get(), 0), 0));
 
             for (unsigned i = 0; i < length; ++i) {
@@ -984,7 +984,7 @@ static ObjcContainerConvertor::Task objectToValueWithoutCopy(JSContext *context,
             return { object, ((JSValue *)object)->m_value, ContainerNone };
 
         if ([object isKindOfClass:[NSString class]]) {
-            auto string = OpaqueJSString::create((NSString *)object);
+            auto string = OpaqueJSString::tryCreate((NSString *)object);
             return { object, JSValueMakeString(contextRef, string.get()), ContainerNone };
         }
 
@@ -1041,7 +1041,7 @@ JSValueRef objectToValue(JSContext *context, id object)
             NSDictionary *dictionary = (NSDictionary *)current.objc;
             for (id key in [dictionary keyEnumerator]) {
                 if ([key isKindOfClass:[NSString class]]) {
-                    auto propertyName = OpaqueJSString::create((NSString *)key);
+                    auto propertyName = OpaqueJSString::tryCreate((NSString *)key);
                     JSObjectSetProperty(contextRef, js, propertyName.get(), convertor.convert([dictionary objectForKey:key]), 0, 0);
                 }
             }
index 23f17bc..4c12b96 100644 (file)
@@ -386,7 +386,7 @@ JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsig
         *exception = 0;
     if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
         return 0;
-    return OpaqueJSString::create(result).leakRef();
+    return OpaqueJSString::tryCreate(result).leakRef();
 }
 
 bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
@@ -434,7 +434,7 @@ JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef*
 
     JSValue jsValue = toJS(exec, value);
     
-    auto stringRef(OpaqueJSString::create(jsValue.toWTFString(exec)));
+    auto stringRef(OpaqueJSString::tryCreate(jsValue.toWTFString(exec)));
     if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
         stringRef = nullptr;
     return stringRef.leakRef();
index 981dc85..77a2e1c 100644 (file)
@@ -34,7 +34,7 @@
 
 using namespace JSC;
 
-RefPtr<OpaqueJSString> OpaqueJSString::create(const String& string)
+RefPtr<OpaqueJSString> OpaqueJSString::tryCreate(const String& string)
 {
     if (string.isNull())
         return nullptr;
@@ -42,7 +42,7 @@ RefPtr<OpaqueJSString> OpaqueJSString::create(const String& string)
     return adoptRef(new OpaqueJSString(string));
 }
 
-RefPtr<OpaqueJSString> OpaqueJSString::create(String&& string)
+RefPtr<OpaqueJSString> OpaqueJSString::tryCreate(String&& string)
 {
     if (string.isNull())
         return nullptr;
index ad2ffcd..4a4b5ed 100644 (file)
@@ -51,8 +51,8 @@ struct OpaqueJSString : public ThreadSafeRefCounted<OpaqueJSString> {
         return adoptRef(*new OpaqueJSString(characters, length));
     }
 
-    JS_EXPORT_PRIVATE static RefPtr<OpaqueJSString> create(const String&);
-    JS_EXPORT_PRIVATE static RefPtr<OpaqueJSString> create(String&&);
+    JS_EXPORT_PRIVATE static RefPtr<OpaqueJSString> tryCreate(const String&);
+    JS_EXPORT_PRIVATE static RefPtr<OpaqueJSString> tryCreate(String&&);
 
     JS_EXPORT_PRIVATE ~OpaqueJSString();
 
index b548efb..40ea5c1 100644 (file)
@@ -819,7 +819,7 @@ JSCValue* jsc_context_evaluate(JSCContext* context, const char* code, gssize len
 
 static JSValueRef evaluateScriptInContext(JSGlobalContextRef jsContext, String&& script, const char* uri, unsigned lineNumber, JSValueRef* exception)
 {
-    JSRetainPtr<JSStringRef> scriptJS(Adopt, OpaqueJSString::create(WTFMove(script)).leakRef());
+    JSRetainPtr<JSStringRef> scriptJS(Adopt, OpaqueJSString::tryCreate(WTFMove(script)).leakRef());
     JSRetainPtr<JSStringRef> sourceURI = uri ? adopt(JSStringCreateWithUTF8CString(uri)) : nullptr;
     return JSEvaluateScript(jsContext, scriptJS.get(), nullptr, sourceURI.get(), lineNumber, exception);
 }
index 79e5316..6e274f8 100644 (file)
@@ -367,7 +367,7 @@ JSCValue* jsc_value_new_string_from_bytes(JSCContext* context, GBytes* bytes)
     gsize dataSize;
     const auto* data = static_cast<const char*>(g_bytes_get_data(bytes, &dataSize));
     auto string = String::fromUTF8(data, dataSize);
-    JSRetainPtr<JSStringRef> jsString(Adopt, OpaqueJSString::create(WTFMove(string)).leakRef());
+    JSRetainPtr<JSStringRef> jsString(Adopt, OpaqueJSString::tryCreate(WTFMove(string)).leakRef());
     return jscContextGetOrCreateValue(context, JSValueMakeString(jscContextGetJSContext(context), jsString.get())).leakRef();
 }
 
index 95dda77..7deabbc 100644 (file)
@@ -1,3 +1,124 @@
+2018-10-10  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=190429
+
+        Reviewed by Saam Barati.
+
+        Some createXXX functions can fail. But sometimes the caller does not perform error checking.
+        To make it explicit that these functions can fail, we rename these functions from createXXX
+        to tryCreateXXX. In this patch, we focus on non-JS-managed factory functions. If the factory
+        function does not fail, it should return Ref<>. Otherwise, it should be named as tryCreateXXX
+        and it should return RefPtr<>.
+
+        This patch mainly focuses on TypedArray factory functions. Previously, these functions are
+        `RefPtr<XXXArray> create(...)`. This patch changes them to `RefPtr<XXXArray> tryCreate(...)`.
+        And we also introduce `Ref<XXXArray> create(...)` function which internally performs
+        RELEASE_ASSERT on the result of `tryCreate(...)`.
+
+        And we also convert OpaqueJSString::create to OpaqueJSString::tryCreate since it can fail.
+
+        This change actually finds one place which does not perform any null checkings while it uses
+        `RefPtr<> create(...)` function.
+
+        * API/JSCallbackObjectFunctions.h:
+        (JSC::JSCallbackObject<Parent>::getOwnPropertySlot):
+        (JSC::JSCallbackObject<Parent>::put):
+        (JSC::JSCallbackObject<Parent>::putByIndex):
+        (JSC::JSCallbackObject<Parent>::deleteProperty):
+        (JSC::JSCallbackObject<Parent>::callbackGetter):
+        * API/JSClassRef.h:
+        (StaticValueEntry::StaticValueEntry):
+        * API/JSContext.mm:
+        (-[JSContext evaluateScript:withSourceURL:]):
+        (-[JSContext setName:]):
+        * API/JSContextRef.cpp:
+        (JSGlobalContextCopyName):
+        (JSContextCreateBacktrace):
+        * API/JSObjectRef.cpp:
+        (JSObjectCopyPropertyNames):
+        * API/JSScriptRef.cpp:
+        * API/JSStringRef.cpp:
+        (JSStringCreateWithCharactersNoCopy):
+        * API/JSValue.mm:
+        (+[JSValue valueWithNewRegularExpressionFromPattern:flags:inContext:]):
+        (+[JSValue valueWithNewErrorFromMessage:inContext:]):
+        (+[JSValue valueWithNewSymbolFromDescription:inContext:]):
+        (performPropertyOperation):
+        (-[JSValue invokeMethod:withArguments:]):
+        (containerValueToObject):
+        (objectToValueWithoutCopy):
+        (objectToValue):
+        * API/JSValueRef.cpp:
+        (JSValueCreateJSONString):
+        (JSValueToStringCopy):
+        * API/OpaqueJSString.cpp:
+        (OpaqueJSString::tryCreate):
+        (OpaqueJSString::create): Deleted.
+        * API/OpaqueJSString.h:
+        * API/glib/JSCContext.cpp:
+        (evaluateScriptInContext):
+        * API/glib/JSCValue.cpp:
+        (jsc_value_new_string_from_bytes):
+        * ftl/FTLLazySlowPath.h:
+        (JSC::FTL::LazySlowPath::createGenerator):
+        * ftl/FTLLazySlowPathCall.h:
+        (JSC::FTL::createLazyCallGenerator):
+        * ftl/FTLOSRExit.cpp:
+        (JSC::FTL::OSRExitDescriptor::emitOSRExit):
+        (JSC::FTL::OSRExitDescriptor::emitOSRExitLater):
+        (JSC::FTL::OSRExitDescriptor::prepareOSRExitHandle):
+        * ftl/FTLOSRExit.h:
+        * ftl/FTLPatchpointExceptionHandle.cpp:
+        (JSC::FTL::PatchpointExceptionHandle::create):
+        (JSC::FTL::PatchpointExceptionHandle::createHandle):
+        * ftl/FTLPatchpointExceptionHandle.h:
+        * heap/EdenGCActivityCallback.h:
+        (JSC::GCActivityCallback::tryCreateEdenTimer):
+        (JSC::GCActivityCallback::createEdenTimer): Deleted.
+        * heap/FullGCActivityCallback.h:
+        (JSC::GCActivityCallback::tryCreateFullTimer):
+        (JSC::GCActivityCallback::createFullTimer): Deleted.
+        * heap/GCActivityCallback.h:
+        * heap/Heap.cpp:
+        (JSC::Heap::Heap):
+        * inspector/AsyncStackTrace.cpp:
+        (Inspector::AsyncStackTrace::create):
+        * inspector/AsyncStackTrace.h:
+        * jsc.cpp:
+        (fillBufferWithContentsOfFile):
+        * runtime/ArrayBuffer.h:
+        * runtime/GenericTypedArrayView.h:
+        * runtime/GenericTypedArrayViewInlines.h:
+        (JSC::GenericTypedArrayView<Adaptor>::create):
+        (JSC::GenericTypedArrayView<Adaptor>::tryCreate):
+        (JSC::GenericTypedArrayView<Adaptor>::createUninitialized):
+        (JSC::GenericTypedArrayView<Adaptor>::tryCreateUninitialized):
+        (JSC::GenericTypedArrayView<Adaptor>::subarray const):
+        * runtime/JSArrayBufferView.cpp:
+        (JSC::JSArrayBufferView::possiblySharedImpl):
+        * runtime/JSGenericTypedArrayViewInlines.h:
+        (JSC::JSGenericTypedArrayView<Adaptor>::possiblySharedTypedImpl):
+        (JSC::JSGenericTypedArrayView<Adaptor>::unsharedTypedImpl):
+        * wasm/WasmMemory.cpp:
+        (JSC::Wasm::Memory::create):
+        (JSC::Wasm::Memory::tryCreate):
+        * wasm/WasmMemory.h:
+        * wasm/WasmTable.cpp:
+        (JSC::Wasm::Table::tryCreate):
+        (JSC::Wasm::Table::create): Deleted.
+        * wasm/WasmTable.h:
+        * wasm/js/JSWebAssemblyInstance.cpp:
+        (JSC::JSWebAssemblyInstance::create):
+        * wasm/js/JSWebAssemblyMemory.cpp:
+        (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory):
+        * wasm/js/WebAssemblyMemoryConstructor.cpp:
+        (JSC::constructJSWebAssemblyMemory):
+        * wasm/js/WebAssemblyModuleRecord.cpp:
+        (JSC::WebAssemblyModuleRecord::link):
+        * wasm/js/WebAssemblyTableConstructor.cpp:
+        (JSC::constructJSWebAssemblyTable):
+
 2018-10-09  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: show redirect requests in Network and Timelines tabs
index 9a6e601..a5b3a72 100644 (file)
@@ -59,7 +59,7 @@ public:
     typedef SharedTask<GeneratorFunction> Generator;
 
     template<typename Functor>
-    static RefPtr<Generator> createGenerator(const Functor& functor)
+    static Ref<Generator> createGenerator(const Functor& functor)
     {
         return createSharedTask<GeneratorFunction>(functor);
     }
index bfb2ace..74fd6ec 100644 (file)
@@ -37,7 +37,7 @@
 namespace JSC { namespace FTL {
 
 template<typename ResultType, typename... ArgumentTypes>
-RefPtr<LazySlowPath::Generator> createLazyCallGenerator(
+Ref<LazySlowPath::Generator> createLazyCallGenerator(
     VM& vm, FunctionPtr<CFunctionPtrTag> function, ResultType result, ArgumentTypes... arguments)
 {
     return LazySlowPath::createGenerator(
index 328f0c8..09958d2 100644 (file)
@@ -63,17 +63,17 @@ void OSRExitDescriptor::validateReferences(const TrackedReferences& trackedRefer
         materialization->validateReferences(trackedReferences);
 }
 
-RefPtr<OSRExitHandle> OSRExitDescriptor::emitOSRExit(
+Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExit(
     State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, CCallHelpers& jit,
     const StackmapGenerationParams& params, unsigned offset)
 {
-    RefPtr<OSRExitHandle> handle =
+    Ref<OSRExitHandle> handle =
         prepareOSRExitHandle(state, exitKind, nodeOrigin, params, offset);
     handle->emitExitThunk(state, jit);
     return handle;
 }
 
-RefPtr<OSRExitHandle> OSRExitDescriptor::emitOSRExitLater(
+Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExitLater(
     State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin,
     const StackmapGenerationParams& params, unsigned offset)
 {
@@ -83,17 +83,17 @@ RefPtr<OSRExitHandle> OSRExitDescriptor::emitOSRExitLater(
         [handle, &state] (CCallHelpers& jit) {
             handle->emitExitThunk(state, jit);
         });
-    return handle;
+    return handle.releaseNonNull();
 }
 
-RefPtr<OSRExitHandle> OSRExitDescriptor::prepareOSRExitHandle(
+Ref<OSRExitHandle> OSRExitDescriptor::prepareOSRExitHandle(
     State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin,
     const StackmapGenerationParams& params, unsigned offset)
 {
     unsigned index = state.jitCode->osrExit.size();
     OSRExit& exit = state.jitCode->osrExit.alloc(
         this, exitKind, nodeOrigin.forExit, nodeOrigin.semantic, nodeOrigin.wasHoisted);
-    RefPtr<OSRExitHandle> handle = adoptRef(new OSRExitHandle(index, exit));
+    Ref<OSRExitHandle> handle = adoptRef(*new OSRExitHandle(index, exit));
     for (unsigned i = offset; i < params.size(); ++i)
         exit.m_valueReps.append(params[i]);
     exit.m_valueReps.shrinkToFit();
index 7c02fb1..da87ccf 100644 (file)
@@ -90,7 +90,7 @@ struct OSRExitDescriptor {
     // up to the OSRExit object, which this creates. Note that it's OK to drop the OSRExitHandle object
     // on the ground. It contains information that is mostly not useful if you use this API, since after
     // this call, the OSRExit is simply ready to go.
-    RefPtr<OSRExitHandle> emitOSRExit(
+    Ref<OSRExitHandle> emitOSRExit(
         State&, ExitKind, const DFG::NodeOrigin&, CCallHelpers&, const B3::StackmapGenerationParams&,
         unsigned offset = 0);
 
@@ -102,7 +102,7 @@ struct OSRExitDescriptor {
     // This API is meant to be used for things like exception handling, where some patchpoint wants to
     // have a place to jump to for OSR exit. It doesn't care where that OSR exit is emitted so long as it
     // eventually gets access to its label.
-    RefPtr<OSRExitHandle> emitOSRExitLater(
+    Ref<OSRExitHandle> emitOSRExitLater(
         State&, ExitKind, const DFG::NodeOrigin&, const B3::StackmapGenerationParams&,
         unsigned offset = 0);
 
@@ -110,7 +110,7 @@ private:
     // This is the low-level interface. It will create a handle representing the desire to emit code for
     // an OSR exit. You can call OSRExitHandle::emitExitThunk() once you have a place to emit it. Note
     // that the above two APIs are written in terms of this and OSRExitHandle::emitExitThunk().
-    RefPtr<OSRExitHandle> prepareOSRExitHandle(
+    Ref<OSRExitHandle> prepareOSRExitHandle(
         State&, ExitKind, const DFG::NodeOrigin&, const B3::StackmapGenerationParams&,
         unsigned offset = 0);
 };
index 7294b1b..faef417 100644 (file)
@@ -38,11 +38,11 @@ namespace JSC { namespace FTL {
 
 using namespace DFG;
 
-RefPtr<PatchpointExceptionHandle> PatchpointExceptionHandle::create(
+Ref<PatchpointExceptionHandle> PatchpointExceptionHandle::create(
     State& state, OSRExitDescriptor* descriptor, NodeOrigin origin, unsigned offset,
     const HandlerInfo& handler)
 {
-    return adoptRef(new PatchpointExceptionHandle(state, descriptor, origin, offset, handler));
+    return adoptRef(*new PatchpointExceptionHandle(state, descriptor, origin, offset, handler));
 }
 
 RefPtr<PatchpointExceptionHandle> PatchpointExceptionHandle::defaultHandle(State& state)
@@ -108,7 +108,7 @@ PatchpointExceptionHandle::PatchpointExceptionHandle(
 {
 }
 
-RefPtr<OSRExitHandle> PatchpointExceptionHandle::createHandle(
+Ref<OSRExitHandle> PatchpointExceptionHandle::createHandle(
     ExitKind kind, const B3::StackmapGenerationParams& params)
 {
     return m_descriptor->emitOSRExitLater(
index 1b266d2..448e1cf 100644 (file)
@@ -51,7 +51,7 @@ struct OSRExitHandle;
 
 class PatchpointExceptionHandle : public ThreadSafeRefCounted<PatchpointExceptionHandle> {
 public:
-    static RefPtr<PatchpointExceptionHandle> create(
+    static Ref<PatchpointExceptionHandle> create(
         State&, OSRExitDescriptor*, DFG::NodeOrigin, unsigned offset, const HandlerInfo&);
 
     static RefPtr<PatchpointExceptionHandle> defaultHandle(State&);
@@ -89,7 +89,7 @@ private:
     PatchpointExceptionHandle(
         State&, OSRExitDescriptor*, DFG::NodeOrigin, unsigned offset, const HandlerInfo&);
 
-    RefPtr<OSRExitHandle> createHandle(ExitKind, const B3::StackmapGenerationParams&);
+    Ref<OSRExitHandle> createHandle(ExitKind, const B3::StackmapGenerationParams&);
 
     State& m_state;
     OSRExitDescriptor* m_descriptor;
index 52e0a28..05cf282 100644 (file)
@@ -41,7 +41,7 @@ protected:
     double deathRate(Heap&) override;
 };
 
-inline RefPtr<GCActivityCallback> GCActivityCallback::createEdenTimer(Heap* heap)
+inline RefPtr<GCActivityCallback> GCActivityCallback::tryCreateEdenTimer(Heap* heap)
 {
     return s_shouldCreateGCTimer ? adoptRef(new EdenGCActivityCallback(heap)) : nullptr;
 }
index 5ce034a..650ae13 100644 (file)
@@ -46,7 +46,7 @@ protected:
     bool m_didGCRecently { false };
 };
 
-inline RefPtr<FullGCActivityCallback> GCActivityCallback::createFullTimer(Heap* heap)
+inline RefPtr<FullGCActivityCallback> GCActivityCallback::tryCreateFullTimer(Heap* heap)
 {
     return s_shouldCreateGCTimer ? adoptRef(new FullGCActivityCallback(heap)) : nullptr;
 }
index 9dfdd0f..c371f77 100644 (file)
@@ -43,8 +43,8 @@ class Heap;
 class JS_EXPORT_PRIVATE GCActivityCallback : public JSRunLoopTimer {
 public:
     using Base = JSRunLoopTimer;
-    static RefPtr<FullGCActivityCallback> createFullTimer(Heap*);
-    static RefPtr<GCActivityCallback> createEdenTimer(Heap*);
+    static RefPtr<FullGCActivityCallback> tryCreateFullTimer(Heap*);
+    static RefPtr<GCActivityCallback> tryCreateEdenTimer(Heap*);
 
     GCActivityCallback(Heap*);
 
index cc4a336..f468d41 100644 (file)
@@ -304,8 +304,8 @@ Heap::Heap(VM* vm, HeapType heapType)
     // schedule the timer if we've never done a collection.
     , m_lastFullGCLength(0.01)
     , m_lastEdenGCLength(0.01)
-    , m_fullActivityCallback(GCActivityCallback::createFullTimer(this))
-    , m_edenActivityCallback(GCActivityCallback::createEdenTimer(this))
+    , m_fullActivityCallback(GCActivityCallback::tryCreateFullTimer(this))
+    , m_edenActivityCallback(GCActivityCallback::tryCreateEdenTimer(this))
     , m_sweeper(adoptRef(new IncrementalSweeper(this)))
     , m_stopIfNecessaryTimer(adoptRef(new StopIfNecessaryTimer(vm)))
     , m_deferralDepth(0)
index 314b87c..8cb0979 100644 (file)
@@ -31,7 +31,7 @@
 
 namespace Inspector {
 
-RefPtr<AsyncStackTrace> AsyncStackTrace::create(Ref<ScriptCallStack>&& callStack, bool singleShot, RefPtr<AsyncStackTrace> parent)
+Ref<AsyncStackTrace> AsyncStackTrace::create(Ref<ScriptCallStack>&& callStack, bool singleShot, RefPtr<AsyncStackTrace> parent)
 {
     ASSERT(callStack->size());
     return adoptRef(*new AsyncStackTrace(WTFMove(callStack), singleShot, WTFMove(parent)));
index 1c3ccf4..22b3fe7 100644 (file)
@@ -42,7 +42,7 @@ public:
         Canceled,
     };
 
-    static RefPtr<AsyncStackTrace> create(Ref<ScriptCallStack>&&, bool singleShot, RefPtr<AsyncStackTrace> parent);
+    static Ref<AsyncStackTrace> create(Ref<ScriptCallStack>&&, bool singleShot, RefPtr<AsyncStackTrace> parent);
 
     bool isPending() const;
     bool isLocked() const;
index 38a00a7..92a5f20 100644 (file)
@@ -887,7 +887,9 @@ static RefPtr<Uint8Array> fillBufferWithContentsOfFile(FILE* file)
         return nullptr;
     if (fseek(file, 0, SEEK_SET) == -1)
         return nullptr;
-    RefPtr<Uint8Array> result = Uint8Array::create(bufferCapacity);
+    auto result = Uint8Array::tryCreate(bufferCapacity);
+    if (!result)
+        return nullptr;
     size_t readSize = fread(result->data(), 1, bufferCapacity, file);
     if (readSize != static_cast<size_t>(bufferCapacity))
         return nullptr;
index deea254..eb367c1 100644 (file)
@@ -111,7 +111,7 @@ public:
     JS_EXPORT_PRIVATE static RefPtr<ArrayBuffer> tryCreate(ArrayBuffer&);
     JS_EXPORT_PRIVATE static RefPtr<ArrayBuffer> tryCreate(const void* source, unsigned byteLength);
 
-    // Only for use by Uint8ClampedArray::createUninitialized and SharedBuffer::tryCreateArrayBuffer.
+    // Only for use by Uint8ClampedArray::tryCreateUninitialized and SharedBuffer::tryCreateArrayBuffer.
     JS_EXPORT_PRIVATE static Ref<ArrayBuffer> createUninitialized(unsigned numElements, unsigned elementByteSize);
     JS_EXPORT_PRIVATE static RefPtr<ArrayBuffer> tryCreateUninitialized(unsigned numElements, unsigned elementByteSize);
 
index e5fd4bb..ef2e80f 100644 (file)
@@ -36,11 +36,15 @@ protected:
     GenericTypedArrayView(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
 
 public:
-    static RefPtr<GenericTypedArrayView> create(unsigned length);
-    static RefPtr<GenericTypedArrayView> create(const typename Adaptor::Type* array, unsigned length);
-    static RefPtr<GenericTypedArrayView> create(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
+    static Ref<GenericTypedArrayView> create(unsigned length);
+    static Ref<GenericTypedArrayView> create(const typename Adaptor::Type* array, unsigned length);
+    static Ref<GenericTypedArrayView> create(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
+    static RefPtr<GenericTypedArrayView> tryCreate(unsigned length);
+    static RefPtr<GenericTypedArrayView> tryCreate(const typename Adaptor::Type* array, unsigned length);
+    static RefPtr<GenericTypedArrayView> tryCreate(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
     
-    static RefPtr<GenericTypedArrayView> createUninitialized(unsigned length);
+    static Ref<GenericTypedArrayView> createUninitialized(unsigned length);
+    static RefPtr<GenericTypedArrayView> tryCreateUninitialized(unsigned length);
     
     typename Adaptor::Type* data() const { return static_cast<typename Adaptor::Type*>(baseAddress()); }
     
index 1b6da56..e660cfc 100644 (file)
@@ -39,25 +39,53 @@ GenericTypedArrayView<Adaptor>::GenericTypedArrayView(
 }
 
 template<typename Adaptor>
-RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(unsigned length)
+Ref<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(unsigned length)
+{
+    auto result = tryCreate(length);
+    RELEASE_ASSERT(result);
+    return result.releaseNonNull();
+}
+
+template<typename Adaptor>
+Ref<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(
+    const typename Adaptor::Type* array, unsigned length)
+{
+    auto result = tryCreate(array, length);
+    RELEASE_ASSERT(result);
+    return result.releaseNonNull();
+}
+
+template<typename Adaptor>
+Ref<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(
+    RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned length)
+{
+    auto result = tryCreate(WTFMove(buffer), byteOffset, length);
+    RELEASE_ASSERT(result);
+    return result.releaseNonNull();
+}
+
+template<typename Adaptor>
+RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::tryCreate(unsigned length)
 {
     auto buffer = ArrayBuffer::tryCreate(length, sizeof(typename Adaptor::Type));
     if (!buffer)
         return nullptr;
-    return create(WTFMove(buffer), 0, length);
+    return tryCreate(WTFMove(buffer), 0, length);
 }
 
 template<typename Adaptor>
-RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(
+RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::tryCreate(
     const typename Adaptor::Type* array, unsigned length)
 {
-    RefPtr<GenericTypedArrayView> result = create(length);
+    RefPtr<GenericTypedArrayView> result = tryCreate(length);
+    if (!result)
+        return nullptr;
     memcpy(result->data(), array, length * sizeof(typename Adaptor::Type));
     return result;
 }
 
 template<typename Adaptor>
-RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(
+RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::tryCreate(
     RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned length)
 {
     ASSERT(buffer);
@@ -70,14 +98,23 @@ RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(
 }
 
 template<typename Adaptor>
-RefPtr<GenericTypedArrayView<Adaptor>>
+Ref<GenericTypedArrayView<Adaptor>>
 GenericTypedArrayView<Adaptor>::createUninitialized(unsigned length)
 {
+    auto result = tryCreateUninitialized(length);
+    RELEASE_ASSERT(result);
+    return result.releaseNonNull();
+}
+
+template<typename Adaptor>
+RefPtr<GenericTypedArrayView<Adaptor>>
+GenericTypedArrayView<Adaptor>::tryCreateUninitialized(unsigned length)
+{
     RefPtr<ArrayBuffer> buffer =
         ArrayBuffer::tryCreateUninitialized(length, sizeof(typename Adaptor::Type));
     if (!buffer)
         return nullptr;
-    return create(WTFMove(buffer), 0, length);
+    return tryCreate(WTFMove(buffer), 0, length);
 }
 
 template<typename Adaptor>
@@ -96,7 +133,7 @@ GenericTypedArrayView<Adaptor>::subarray(int start, int end) const
     ArrayBuffer* buffer = possiblySharedBuffer();
     ASSERT(buffer);
     clampOffsetAndNumElements<Adaptor::Type>(*buffer, byteOffset(), &offset, &length);
-    return create(buffer, offset, length);
+    return tryCreate(buffer, offset, length);
 }
 
 template<typename Adaptor>
index b3039a2..c2de003 100644 (file)
@@ -302,7 +302,7 @@ RefPtr<ArrayBufferView> JSArrayBufferView::possiblySharedImpl()
     switch (type()) {
 #define FACTORY(type) \
     case type ## ArrayType: \
-        return type ## Array::create(buffer, byteOffset, length);
+        return type ## Array::tryCreate(buffer, byteOffset, length);
     FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
 #undef FACTORY
     case DataViewType:
index ca18844..2e56ce1 100644 (file)
@@ -314,13 +314,13 @@ bool JSGenericTypedArrayView<Adaptor>::set(
 template<typename Adaptor>
 RefPtr<typename Adaptor::ViewType> JSGenericTypedArrayView<Adaptor>::possiblySharedTypedImpl()
 {
-    return Adaptor::ViewType::create(possiblySharedBuffer(), byteOffset(), length());
+    return Adaptor::ViewType::tryCreate(possiblySharedBuffer(), byteOffset(), length());
 }
 
 template<typename Adaptor>
 RefPtr<typename Adaptor::ViewType> JSGenericTypedArrayView<Adaptor>::unsharedTypedImpl()
 {
-    return Adaptor::ViewType::create(unsharedBuffer(), byteOffset(), length());
+    return Adaptor::ViewType::tryCreate(unsharedBuffer(), byteOffset(), length());
 }
 
 template<typename Adaptor>
index a685f0e..38bbe89 100644 (file)
@@ -269,12 +269,12 @@ Memory::Memory(void* memory, PageCount initial, PageCount maximum, size_t mapped
     dataLogLnIf(verbose, "Memory::Memory allocating ", *this);
 }
 
-RefPtr<Memory> Memory::create()
+Ref<Memory> Memory::create()
 {
-    return adoptRef(new Memory());
+    return adoptRef(*new Memory());
 }
 
-RefPtr<Memory> Memory::create(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
+RefPtr<Memory> Memory::tryCreate(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
 {
     ASSERT(initial);
     RELEASE_ASSERT(!maximum || maximum >= initial); // This should be guaranteed by our caller.
index c36580f..00737fc 100644 (file)
@@ -59,8 +59,8 @@ public:
     enum SyncTryToReclaim { SyncTryToReclaimTag };
     enum GrowSuccess { GrowSuccessTag };
 
-    static RefPtr<Memory> create();
-    static RefPtr<Memory> create(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
+    static Ref<Memory> create();
+    static RefPtr<Memory> tryCreate(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
 
     ~Memory();
 
index 04ac065..ebb6325 100644 (file)
@@ -47,7 +47,7 @@ void Table::setLength(uint32_t length)
     ASSERT(m_mask == WTF::maskForSize(allocatedLength(length)));
 }
 
-RefPtr<Table> Table::create(uint32_t initial, std::optional<uint32_t> maximum)
+RefPtr<Table> Table::tryCreate(uint32_t initial, std::optional<uint32_t> maximum)
 {
     if (!isValidLength(initial))
         return nullptr;
index 4e15e29..2f5483c 100644 (file)
@@ -40,7 +40,7 @@ class Instance;
 
 class Table : public ThreadSafeRefCounted<Table> {
 public:
-    static RefPtr<Table> create(uint32_t initial, std::optional<uint32_t> maximum);
+    static RefPtr<Table> tryCreate(uint32_t initial, std::optional<uint32_t> maximum);
 
     JS_EXPORT_PRIVATE ~Table();
 
index abc7fae..bd703fd 100644 (file)
@@ -281,7 +281,7 @@ JSWebAssemblyInstance* JSWebAssemblyInstance::create(VM& vm, ExecState* exec, co
             auto* jsMemory = JSWebAssemblyMemory::create(exec, vm, globalObject->WebAssemblyMemoryStructure());
             RETURN_IF_EXCEPTION(throwScope, nullptr);
 
-            RefPtr<Wasm::Memory> memory = Wasm::Memory::create(moduleInformation.memory.initial(), moduleInformation.memory.maximum(),
+            RefPtr<Wasm::Memory> memory = Wasm::Memory::tryCreate(moduleInformation.memory.initial(), moduleInformation.memory.maximum(),
                 [&vm] (Wasm::Memory::NotifyPressure) { vm.heap.collectAsync(CollectionScope::Full); },
                 [&vm] (Wasm::Memory::SyncTryToReclaim) { vm.heap.collectSync(CollectionScope::Full); },
                 [&vm, jsMemory] (Wasm::Memory::GrowSuccess, Wasm::PageCount oldPageCount, Wasm::PageCount newPageCount) { jsMemory->growSuccessCallback(vm, oldPageCount, newPageCount); });
@@ -297,7 +297,7 @@ JSWebAssemblyInstance* JSWebAssemblyInstance::create(VM& vm, ExecState* exec, co
     if (!jsInstance->memory()) {
         // Make sure we have a dummy memory, so that wasm -> wasm thunks avoid checking for a nullptr Memory when trying to set pinned registers.
         auto* jsMemory = JSWebAssemblyMemory::create(exec, vm, globalObject->WebAssemblyMemoryStructure());
-        jsMemory->adopt(Wasm::Memory::create().releaseNonNull());
+        jsMemory->adopt(Wasm::Memory::create());
         jsInstance->setMemory(vm, jsMemory);
         RETURN_IF_EXCEPTION(throwScope, nullptr);
     }
index 5656252..7a6a5f0 100644 (file)
@@ -69,7 +69,7 @@ Structure* JSWebAssemblyMemory::createStructure(VM& vm, JSGlobalObject* globalOb
 
 JSWebAssemblyMemory::JSWebAssemblyMemory(VM& vm, Structure* structure)
     : Base(vm, structure)
-    , m_memory(Wasm::Memory::create().releaseNonNull())
+    , m_memory(Wasm::Memory::create())
 {
 }
 
index 4f26024..1404e67 100644 (file)
@@ -99,7 +99,7 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyMemory(ExecState* exec
     auto* jsMemory = JSWebAssemblyMemory::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyMemoryStructure());
     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
 
-    RefPtr<Wasm::Memory> memory = Wasm::Memory::create(initialPageCount, maximumPageCount,
+    RefPtr<Wasm::Memory> memory = Wasm::Memory::tryCreate(initialPageCount, maximumPageCount,
         [&vm] (Wasm::Memory::NotifyPressure) { vm.heap.collectAsync(CollectionScope::Full); },
         [&vm] (Wasm::Memory::SyncTryToReclaim) { vm.heap.collectSync(CollectionScope::Full); },
         [&vm, jsMemory] (Wasm::Memory::GrowSuccess, Wasm::PageCount oldPageCount, Wasm::PageCount newPageCount) { jsMemory->growSuccessCallback(vm, oldPageCount, newPageCount); });
index e8ca58c..39a66fa 100644 (file)
@@ -298,7 +298,7 @@ void WebAssemblyModuleRecord::link(ExecState* exec, JSValue, JSObject* importObj
         if (!!moduleInformation.tableInformation && !hasTableImport) {
             RELEASE_ASSERT(!moduleInformation.tableInformation.isImport());
             // We create a Table when it's a Table definition.
-            RefPtr<Wasm::Table> wasmTable = Wasm::Table::create(moduleInformation.tableInformation.initial(), moduleInformation.tableInformation.maximum());
+            RefPtr<Wasm::Table> wasmTable = Wasm::Table::tryCreate(moduleInformation.tableInformation.initial(), moduleInformation.tableInformation.maximum());
             if (!wasmTable)
                 return exception(createJSWebAssemblyLinkError(exec, vm, "couldn't create Table"));
             JSWebAssemblyTable* table = JSWebAssemblyTable::create(exec, vm, globalObject->WebAssemblyTableStructure(), wasmTable.releaseNonNull());
index 076c787..5a69520 100644 (file)
@@ -90,7 +90,7 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyTable(ExecState* exec)
         }
     }
 
-    RefPtr<Wasm::Table> wasmTable = Wasm::Table::create(initial, maximum);
+    RefPtr<Wasm::Table> wasmTable = Wasm::Table::tryCreate(initial, maximum);
     if (!wasmTable) {
         return JSValue::encode(throwException(exec, throwScope,
             createRangeError(exec, "couldn't create Table"_s)));
index ea3abc8..553b709 100644 (file)
@@ -1,3 +1,114 @@
+2018-10-10  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=190429
+
+        Reviewed by Saam Barati.
+
+        Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.
+
+        * Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp:
+        (WebCore::CDMSessionClearKey::cachedKeyForKeyID const):
+        * Modules/plugins/QuickTimePluginReplacement.mm:
+        (WebCore::jsValueWithDictionaryInContext):
+        * Modules/webaudio/AudioBuffer.cpp:
+        (WebCore::AudioBuffer::AudioBuffer):
+        (WebCore::AudioBuffer::getChannelData):
+        * Modules/webvr/VREyeParameters.cpp:
+        (WebCore::VREyeParameters::offset const):
+        * Modules/webvr/VRFrameData.cpp:
+        (WebCore::matrixToArray):
+        * Modules/webvr/VRPose.cpp:
+        (WebCore::optionalFloat3ToJSCArray):
+        (WebCore::VRPose::position const):
+        (WebCore::VRPose::orientation const):
+        * Modules/webvr/VRStageParameters.cpp:
+        (WebCore::VRStageParameters::sittingToStandingTransform const):
+        * bindings/js/ReadableStreamDefaultController.h:
+        (WebCore::ReadableStreamDefaultController::enqueue):
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneDeserializer::readArrayBufferView):
+        * crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:
+        (WebCore::CryptoKeyRSA::algorithm const):
+        * crypto/mac/CryptoKeyRSAMac.cpp:
+        (WebCore::CryptoKeyRSA::algorithm const):
+        * css/DOMMatrixReadOnly.cpp:
+        (WebCore::DOMMatrixReadOnly::toFloat32Array const):
+        (WebCore::DOMMatrixReadOnly::toFloat64Array const):
+        * css/FontFace.cpp:
+        (WebCore::FontFace::create):
+        * dom/TextEncoder.cpp:
+        (WebCore::TextEncoder::encode const):
+        * html/ImageData.cpp:
+        (WebCore::ImageData::ImageData):
+        * html/ImageData.h:
+        (WebCore::ImageData::data const):
+        (): Deleted.
+        * html/canvas/WebGL2RenderingContext.cpp:
+        (WebCore::WebGL2RenderingContext::bufferData):
+        (WebCore::WebGL2RenderingContext::bufferSubData):
+        (WebCore::WebGL2RenderingContext::getInternalformatParameter):
+        (WebCore::WebGL2RenderingContext::getParameter):
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::getParameter):
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::getUniform):
+        (WebCore::WebGLRenderingContextBase::getVertexAttrib):
+        (WebCore::WebGLRenderingContextBase::getWebGLFloatArrayParameter):
+        (WebCore::WebGLRenderingContextBase::getWebGLIntArrayParameter):
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
+        (WebCore::MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitData):
+        * platform/graphics/avfoundation/cf/CDMSessionAVFoundationCF.cpp:
+        (WebCore::CDMSessionAVFoundationCF::generateKeyRequest):
+        * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
+        (WebCore::AVFWrapper::shouldWaitForLoadingOfResource):
+        * platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm:
+        (WebCore::CDMSessionAVContentKeySession::generateKeyRequest):
+        (WebCore::CDMSessionAVContentKeySession::releaseKeys):
+        (WebCore::CDMSessionAVContentKeySession::update):
+        (WebCore::CDMSessionAVContentKeySession::generateKeyReleaseMessage):
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
+        (WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
+        * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm:
+        (WebCore::CDMSessionAVStreamSession::generateKeyRequest):
+        (WebCore::CDMSessionAVStreamSession::releaseKeys):
+        (WebCore::CDMSessionAVStreamSession::generateKeyReleaseMessage):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
+        * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm:
+        (WebCore::MediaSampleAVFObjC::getRGBAImageData const):
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (WebCore::SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID):
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::getImageData):
+        * platform/graphics/cg/ImageBufferDataCG.cpp:
+        (WebCore::ImageBufferData::getData const):
+        * platform/graphics/filters/FEGaussianBlur.cpp:
+        (WebCore::FEGaussianBlur::platformApplySoftware):
+        * platform/graphics/filters/FilterEffect.cpp:
+        (WebCore::FilterEffect::unmultipliedResult):
+        (WebCore::FilterEffect::premultipliedResult):
+        (WebCore::FilterEffect::copyUnmultipliedResult):
+        (WebCore::FilterEffect::copyPremultipliedResult):
+        (WebCore::FilterEffect::createUnmultipliedImageResult):
+        (WebCore::FilterEffect::createPremultipliedImageResult):
+        * platform/graphics/win/ImageBufferDataDirect2D.cpp:
+        (WebCore::ImageBufferData::getData const):
+        * platform/mac/SerializedPlatformRepresentationMac.mm:
+        (WebCore::jsValueWithDictionaryInContext):
+        * platform/mock/mediasource/MockBox.cpp:
+        (WebCore::MockBox::peekType):
+        (WebCore::MockBox::peekLength):
+        (WebCore::MockTrackBox::MockTrackBox):
+        (WebCore::MockInitializationBox::MockInitializationBox):
+        (WebCore::MockSampleBox::MockSampleBox):
+        * rendering/shapes/Shape.cpp:
+        (WebCore::Shape::createRasterShape):
+        * testing/LegacyMockCDM.cpp:
+        (WebCore::initDataPrefix):
+        (WebCore::keyPrefix):
+        (WebCore::keyRequest):
+
 2018-10-10  Daniel Bates  <dabates@apple.com>
 
         [iOS] Compare input string to UIKeyInput constants using string comparison instead of pointer comparison
index 476d2e5..d0fb3e0 100644 (file)
@@ -194,7 +194,7 @@ RefPtr<ArrayBuffer> CDMSessionClearKey::cachedKeyForKeyID(const String& keyId) c
         return nullptr;
 
     auto keyData = m_cachedKeys.get(keyId);
-    RefPtr<Uint8Array> keyDataArray = Uint8Array::create(keyData.data(), keyData.size());
+    auto keyDataArray = Uint8Array::create(keyData.data(), keyData.size());
     return keyDataArray->unsharedBuffer();
 }
 
index 79ec891..62b3192 100644 (file)
@@ -308,7 +308,7 @@ static JSValue *jsValueWithDictionaryInContext(NSDictionary *dictionary, JSConte
         if (!value)
             continue;
 
-        auto name = OpaqueJSString::create(key);
+        auto name = OpaqueJSString::tryCreate(key);
         JSObjectSetProperty([context JSGlobalContextRef], resultObject, name.get(), [value JSValueRef], 0, &exception);
         if (exception)
             continue;
index 9f0a25f..56a13ca 100644 (file)
@@ -67,7 +67,7 @@ AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
     m_channels.reserveCapacity(numberOfChannels);
 
     for (unsigned i = 0; i < numberOfChannels; ++i) {
-        auto channelDataArray = Float32Array::create(m_length);
+        auto channelDataArray = Float32Array::tryCreate(m_length);
         if (!channelDataArray) {
             invalidate();
             break;
@@ -86,7 +86,7 @@ AudioBuffer::AudioBuffer(AudioBus& bus)
     unsigned numberOfChannels = bus.numberOfChannels();
     m_channels.reserveCapacity(numberOfChannels);
     for (unsigned i = 0; i < numberOfChannels; ++i) {
-        auto channelDataArray = Float32Array::create(m_length);
+        auto channelDataArray = Float32Array::tryCreate(m_length);
         if (!channelDataArray) {
             invalidate();
             break;
@@ -115,9 +115,7 @@ ExceptionOr<Ref<Float32Array>> AudioBuffer::getChannelData(unsigned channelIndex
     if (channelIndex >= m_channels.size())
         return Exception { SyntaxError };
     auto& channelData = *m_channels[channelIndex];
-    auto array = Float32Array::create(channelData.unsharedBuffer(), channelData.byteOffset(), channelData.length());
-    RELEASE_ASSERT(array);
-    return array.releaseNonNull();
+    return Float32Array::create(channelData.unsharedBuffer(), channelData.byteOffset(), channelData.length());
 }
 
 Float32Array* AudioBuffer::channelData(unsigned channelIndex)
index 25fb8e8..01264bd 100644 (file)
@@ -39,12 +39,11 @@ VREyeParameters::VREyeParameters(const FloatPoint3D& offset, const VRPlatformDis
 Ref<Float32Array> VREyeParameters::offset() const
 {
     auto offset = Float32Array::create(3);
-    RELEASE_ASSERT(offset);
     float* offsetData = offset->data();
     offsetData[0] = m_offset.x();
     offsetData[1] = m_offset.y();
     offsetData[2] = m_offset.z();
-    return offset.releaseNonNull();
+    return offset;
 }
 
 const VRFieldOfView& VREyeParameters::fieldOfView() const
index 65c3dba..b215b55 100644 (file)
@@ -39,7 +39,7 @@ VRFrameData::VRFrameData()
 static Ref<Float32Array> matrixToArray(const TransformationMatrix& matrix)
 {
     auto columnMajorMatrix = matrix.toColumnMajorFloatArray();
-    return Float32Array::create(columnMajorMatrix.data(), 16).releaseNonNull();
+    return Float32Array::create(columnMajorMatrix.data(), 16);
 }
 
 Ref<Float32Array> VRFrameData::leftProjectionMatrix() const
index 8e3baf5..1686b9a 100644 (file)
@@ -32,7 +32,7 @@ static RefPtr<Float32Array> optionalFloat3ToJSCArray(const std::optional<VRPlatf
     if (!data)
         return nullptr;
 
-    return Float32Array::create(data->data, 3).releaseNonNull();
+    return Float32Array::create(data->data, 3);
 }
 
 RefPtr<Float32Array> VRPose::position() const
@@ -42,7 +42,7 @@ RefPtr<Float32Array> VRPose::position() const
 
     auto& position = *m_trackingInfo.position;
     float positionData[3] = { position.x(), position.y(), position.z() };
-    return Float32Array::create(positionData, 3).releaseNonNull();
+    return Float32Array::create(positionData, 3);
 }
 
 RefPtr<Float32Array> VRPose::linearVelocity() const
@@ -62,7 +62,7 @@ RefPtr<Float32Array> VRPose::orientation() const
 
     auto& orientation = *m_trackingInfo.orientation;
     float orientationData[4] = { orientation.x, orientation.y, orientation.z, orientation.w };
-    return Float32Array::create(orientationData, 4).releaseNonNull();
+    return Float32Array::create(orientationData, 4);
 }
 
 RefPtr<Float32Array> VRPose::angularVelocity() const
index 2da0743..b6e5732 100644 (file)
@@ -41,7 +41,7 @@ VRStageParameters::VRStageParameters(const TransformationMatrix& sittingToStandi
 Ref<Float32Array> VRStageParameters::sittingToStandingTransform() const
 {
     auto columnMajorMatrix = m_sittingToStandingTransform.toColumnMajorFloatArray();
-    return Float32Array::create(columnMajorMatrix.data(), 16).releaseNonNull();
+    return Float32Array::create(columnMajorMatrix.data(), 16);
 }
 
 float VRStageParameters::sizeX() const
index 64cedc1..484c8d8 100644 (file)
@@ -99,8 +99,7 @@ inline bool ReadableStreamDefaultController::enqueue(RefPtr<JSC::ArrayBuffer>&&
     }
     auto length = buffer->byteLength();
     auto chunk = JSC::Uint8Array::create(WTFMove(buffer), 0, length);
-    ASSERT(chunk);
-    enqueue(state, toJS(&state, &globalObject, chunk.get()));
+    enqueue(state, toJS(&state, &globalObject, chunk.ptr()));
     scope.assertNoException();
     return true;
 }
index ba945cd..af7ab3a 100644 (file)
@@ -2096,31 +2096,31 @@ private:
             arrayBufferView = getJSValue(DataView::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Int8ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Int8Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Int8Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint8ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint8Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint8Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint8ClampedArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint8ClampedArray::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint8ClampedArray::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Int16ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Int16Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Int16Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint16ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint16Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint16Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Int32ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Int32Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Int32Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint32ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint32Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint32Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Float32ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Float32Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Float32Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Float64ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Float64Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Float64Array::tryCreate(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         default:
             return false;
index 0802099..3d8002c 100644 (file)
@@ -629,7 +629,7 @@ auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
         CryptoRsaHashedKeyAlgorithm result;
         result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
         result.modulusLength = modulusLength;
-        result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+        result.publicExponent = Uint8Array::tryCreate(publicExponent.data(), publicExponent.size());
         result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash);
         return result;
     }
@@ -637,7 +637,7 @@ auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
     CryptoRsaKeyAlgorithm result;
     result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
     result.modulusLength = modulusLength;
-    result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+    result.publicExponent = Uint8Array::tryCreate(publicExponent.data(), publicExponent.size());
     return result;
 }
 
index e8eb84e..94fc1a7 100644 (file)
@@ -222,7 +222,7 @@ auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
         CryptoRsaKeyAlgorithm result;
         result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
         result.modulusLength = 0;
-        result.publicExponent = Uint8Array::create(0);
+        result.publicExponent = Uint8Array::tryCreate(0);
         return result;
     }
 
@@ -232,7 +232,7 @@ auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
         CryptoRsaHashedKeyAlgorithm result;
         result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
         result.modulusLength = modulusLength;
-        result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+        result.publicExponent = Uint8Array::tryCreate(publicExponent.data(), publicExponent.size());
         result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash);
         return result;
     }
@@ -240,7 +240,7 @@ auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
     CryptoRsaKeyAlgorithm result;
     result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
     result.modulusLength = modulusLength;
-    result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+    result.publicExponent = Uint8Array::tryCreate(publicExponent.data(), publicExponent.size());
     return result;
 }
 
index deaadfa..731754e 100644 (file)
@@ -345,7 +345,7 @@ Ref<DOMPoint> DOMMatrixReadOnly::transformPoint(DOMPointInit&& pointInit)
 
 ExceptionOr<Ref<Float32Array>> DOMMatrixReadOnly::toFloat32Array() const
 {
-    auto array32 = Float32Array::createUninitialized(16);
+    auto array32 = Float32Array::tryCreateUninitialized(16);
     if (!array32)
         return Exception { UnknownError, "Out of memory"_s };
 
@@ -371,7 +371,7 @@ ExceptionOr<Ref<Float32Array>> DOMMatrixReadOnly::toFloat32Array() const
 
 ExceptionOr<Ref<Float64Array>> DOMMatrixReadOnly::toFloat64Array() const
 {
-    auto array64 = Float64Array::createUninitialized(16);
+    auto array64 = Float64Array::tryCreateUninitialized(16);
     if (!array64)
         return Exception { UnknownError, "Out of memory"_s };
 
index 2eb41c9..a24a536 100644 (file)
@@ -78,7 +78,7 @@ ExceptionOr<Ref<FontFace>> FontFace::create(Document& document, const String& fa
         [&] (RefPtr<ArrayBuffer>& arrayBuffer) -> ExceptionOr<void> {
             unsigned byteLength = arrayBuffer->byteLength();
             auto arrayBufferView = JSC::Uint8Array::create(WTFMove(arrayBuffer), 0, byteLength);
-            dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull());
+            dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), WTFMove(arrayBufferView));
             return { };
         }
     );
index 9eeb779..b049cc1 100644 (file)
@@ -40,7 +40,7 @@ RefPtr<Uint8Array> TextEncoder::encode(String&& input) const
 {
     // FIXME: We should not need to allocate a CString to encode into a Uint8Array.
     CString utf8 = input.utf8();
-    return Uint8Array::create(reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());
+    return Uint8Array::tryCreate(reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());
 }
 
 }
index 9ffc408..3b2a236 100644 (file)
@@ -99,15 +99,13 @@ ImageData::ImageData(const IntSize& size)
     : m_size(size)
     , m_data(Uint8ClampedArray::createUninitialized((size.area() * 4).unsafeGet()))
 {
-    ASSERT(m_data);
 }
 
 ImageData::ImageData(const IntSize& size, Ref<Uint8ClampedArray>&& byteArray)
     : m_size(size)
     , m_data(WTFMove(byteArray))
 {
-    ASSERT(m_data);
-    ASSERT_WITH_SECURITY_IMPLICATION(!m_data || (size.area() * 4).unsafeGet() <= m_data->length());
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((size.area() * 4).unsafeGet() <= m_data->length());
 }
 
 }
index 98b1f10..a0ffa29 100644 (file)
 
 namespace WebCore {
 
-class WEBCORE_EXPORT ImageData : public RefCounted<ImageData> {
+class ImageData : public RefCounted<ImageData> {
 public:
-    static ExceptionOr<Ref<ImageData>> create(unsigned sw, unsigned sh);
-    static RefPtr<ImageData> create(const IntSize&);
-    static RefPtr<ImageData> create(const IntSize&, Ref<Uint8ClampedArray>&&);
-    static ExceptionOr<RefPtr<ImageData>> create(Ref<Uint8ClampedArray>&&, unsigned sw, std::optional<unsigned> sh);
+    WEBCORE_EXPORT static ExceptionOr<Ref<ImageData>> create(unsigned sw, unsigned sh);
+    WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&);
+    WEBCORE_EXPORT static RefPtr<ImageData> create(const IntSize&, Ref<Uint8ClampedArray>&&);
+    WEBCORE_EXPORT static ExceptionOr<RefPtr<ImageData>> create(Ref<Uint8ClampedArray>&&, unsigned sw, std::optional<unsigned> sh);
 
     IntSize size() const { return m_size; }
     int width() const { return m_size.width(); }
     int height() const { return m_size.height(); }
 
-    Uint8ClampedArray* data() const { return m_data.get(); }
+    Uint8ClampedArray* data() const { return m_data.ptr(); }
 
 private:
     explicit ImageData(const IntSize&);
     ImageData(const IntSize&, Ref<Uint8ClampedArray>&&);
 
     IntSize m_size;
-    RefPtr<Uint8ClampedArray> m_data;
+    Ref<Uint8ClampedArray> m_data;
 };
 
 } // namespace WebCore
index 7c04555..0766835 100644 (file)
@@ -156,7 +156,7 @@ void WebGL2RenderingContext::bufferData(GC3Denum target, const ArrayBufferView&
         return;
     }
 
-    auto slice = Uint8Array::create(data.possiblySharedBuffer(), data.byteOffset() + checkedByteSrcOffset.unsafeGet(), checkedByteLength.unsafeGet());
+    auto slice = Uint8Array::tryCreate(data.possiblySharedBuffer(), data.byteOffset() + checkedByteSrcOffset.unsafeGet(), checkedByteLength.unsafeGet());
     if (!slice) {
         synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "bufferData", "Could not create intermediate ArrayBufferView");
         return;
@@ -187,7 +187,7 @@ void WebGL2RenderingContext::bufferSubData(GC3Denum target, long long offset, co
         return;
     }
 
-    auto slice = Uint8Array::create(data.possiblySharedBuffer(), data.byteOffset() + checkedByteSrcOffset.unsafeGet(), checkedByteLength.unsafeGet());
+    auto slice = Uint8Array::tryCreate(data.possiblySharedBuffer(), data.byteOffset() + checkedByteSrcOffset.unsafeGet(), checkedByteLength.unsafeGet());
     if (!slice) {
         synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "bufferSubData", "Could not create intermediate ArrayBufferView");
         return;
@@ -412,7 +412,7 @@ WebGLAny WebGL2RenderingContext::getInternalformatParameter(GC3Denum target, GC3
         params[i] = samples[i];
 #endif
 
-    return Int32Array::create(params, numValues);
+    return Int32Array::tryCreate(params, numValues);
 }
 
 void WebGL2RenderingContext::invalidateFramebuffer(GC3Denum, const Vector<GC3Denum>&)
@@ -1794,7 +1794,7 @@ WebGLAny WebGL2RenderingContext::getParameter(GC3Denum pname)
     case GraphicsContext3D::COLOR_WRITEMASK:
         return getBooleanArrayParameter(pname);
     case GraphicsContext3D::COMPRESSED_TEXTURE_FORMATS:
-        return Uint32Array::create(m_compressedTextureFormats.data(), m_compressedTextureFormats.size());
+        return Uint32Array::tryCreate(m_compressedTextureFormats.data(), m_compressedTextureFormats.size());
     case GraphicsContext3D::CULL_FACE:
         return getBooleanParameter(pname);
     case GraphicsContext3D::CULL_FACE_MODE:
index 620bdb3..af7a77f 100644 (file)
@@ -444,7 +444,7 @@ WebGLAny WebGLRenderingContext::getParameter(GC3Denum pname)
     case GraphicsContext3D::COLOR_WRITEMASK:
         return getBooleanArrayParameter(pname);
     case GraphicsContext3D::COMPRESSED_TEXTURE_FORMATS:
-        return Uint32Array::create(m_compressedTextureFormats.data(), m_compressedTextureFormats.size());
+        return Uint32Array::tryCreate(m_compressedTextureFormats.data(), m_compressedTextureFormats.size());
     case GraphicsContext3D::CULL_FACE:
         return getBooleanParameter(pname);
     case GraphicsContext3D::CULL_FACE_MODE:
index 8574fce..f18a8fb 100644 (file)
@@ -2922,7 +2922,7 @@ WebGLAny WebGLRenderingContextBase::getUniform(WebGLProgram* program, const WebG
             m_context->getUniformfv(objectOrZero(program), location, value);
         if (length == 1)
             return value[0];
-        return Float32Array::create(value, length);
+        return Float32Array::tryCreate(value, length);
     }
     case GraphicsContext3D::INT: {
         GC3Dint value[4] = {0};
@@ -2932,7 +2932,7 @@ WebGLAny WebGLRenderingContextBase::getUniform(WebGLProgram* program, const WebG
             m_context->getUniformiv(objectOrZero(program), location, value);
         if (length == 1)
             return value[0];
-        return Int32Array::create(value, length);
+        return Int32Array::tryCreate(value, length);
     }
     case GraphicsContext3D::BOOL: {
         GC3Dint value[4] = {0};
@@ -3028,7 +3028,7 @@ WebGLAny WebGLRenderingContextBase::getVertexAttrib(GC3Duint index, GC3Denum pna
     case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_TYPE:
         return state.type;
     case GraphicsContext3D::CURRENT_VERTEX_ATTRIB:
-        return Float32Array::create(m_vertexAttribValue[index].value, 4);
+        return Float32Array::tryCreate(m_vertexAttribValue[index].value, 4);
     default:
         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getVertexAttrib", "invalid parameter name");
         return nullptr;
@@ -5235,7 +5235,7 @@ RefPtr<Float32Array> WebGLRenderingContextBase::getWebGLFloatArrayParameter(GC3D
     default:
         notImplemented();
     }
-    return Float32Array::create(value, length);
+    return Float32Array::tryCreate(value, length);
 }
 
 RefPtr<Int32Array> WebGLRenderingContextBase::getWebGLIntArrayParameter(GC3Denum pname)
@@ -5254,7 +5254,7 @@ RefPtr<Int32Array> WebGLRenderingContextBase::getWebGLIntArrayParameter(GC3Denum
     default:
         notImplemented();
     }
-    return Int32Array::create(value, length);
+    return Int32Array::tryCreate(value, length);
 }
 
 bool WebGLRenderingContextBase::checkTextureCompleteness(const char* functionName, bool prepareToDraw)
index 5915a77..b340463 100644 (file)
@@ -1014,7 +1014,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     RefPtr<ArrayBuffer> initDataBuffer = initData->unsharedBuffer();
 
     // Use a DataView to read uint32 values from the buffer, as Uint32Array requires the reads be aligned on 4-byte boundaries. 
-    RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, initDataBuffer->byteLength());
+    auto initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, initDataBuffer->byteLength());
     uint32_t offset = 0;
     bool status = true;
 
@@ -1023,7 +1023,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     if (!status || offset + keyURILength > initData->length())
         return false;
 
-    RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), offset, keyURILength);
+    auto keyURIArray = Uint16Array::tryCreate(initDataBuffer.copyRef(), offset, keyURILength);
     if (!keyURIArray)
         return false;
 
@@ -1035,7 +1035,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     if (!status || offset + keyIDLength > initData->length())
         return false;
 
-    RefPtr<Uint8Array> keyIDArray = Uint8Array::create(initDataBuffer.copyRef(), offset, keyIDLength);
+    auto keyIDArray = Uint8Array::tryCreate(initDataBuffer.copyRef(), offset, keyIDLength);
     if (!keyIDArray)
         return false;
 
@@ -1047,7 +1047,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     if (!status || offset + certificateLength > initData->length())
         return false;
 
-    certificate = Uint8Array::create(WTFMove(initDataBuffer), offset, certificateLength);
+    certificate = Uint8Array::tryCreate(WTFMove(initDataBuffer), offset, certificateLength);
     if (!certificate)
         return false;
 
index 3232b73..709c080 100644 (file)
@@ -99,7 +99,7 @@ RefPtr<Uint8Array> CDMSessionAVFoundationCF::generateKeyRequest(const String&, U
     destinationURL = String();
 
     auto keyRequestBuffer = ArrayBuffer::create(CFDataGetBytePtr(keyRequest.get()), CFDataGetLength(keyRequest.get()));
-    return Uint8Array::create(WTFMove(keyRequestBuffer), 0, keyRequestBuffer->byteLength());
+    return Uint8Array::tryCreate(WTFMove(keyRequestBuffer), 0, keyRequestBuffer->byteLength());
 #endif
 }
 
index e82449a..cb3c922 100644 (file)
@@ -63,6 +63,7 @@
 #include <dispatch/dispatch.h>
 #if HAVE(AVFOUNDATION_LOADER_DELEGATE) && ENABLE(LEGACY_ENCRYPTED_MEDIA)
 #include <JavaScriptCore/DataView.h>
+#include <JavaScriptCore/TypedArrayInlines.h>
 #include <JavaScriptCore/Uint16Array.h>
 #endif
 #include <wtf/HashMap.h>
@@ -1893,12 +1894,12 @@ bool AVFWrapper::shouldWaitForLoadingOfResource(AVCFAssetResourceLoadingRequestR
         RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, initDataBuffer->byteLength());
         initDataView->set<uint32_t>(0, keyURISize, true);
 
-        RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), 4, keyURI.length());
+        auto keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), 4, keyURI.length());
         keyURIArray->setRange(reinterpret_cast<const uint16_t*>(StringView(keyURI).upconvertedCharacters().get()), keyURI.length() / sizeof(unsigned char), 0);
 
         unsigned byteLength = initDataBuffer->byteLength();
-        RefPtr<Uint8Array> initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
-        if (!m_owner->player()->keyNeeded(initData.get()))
+        auto initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
+        if (!m_owner->player()->keyNeeded(initData.ptr()))
             return false;
 
         setRequestForKey(keyURI, avRequest);
index 5edac46..e8dd3b5 100644 (file)
@@ -165,10 +165,10 @@ RefPtr<Uint8Array> CDMSessionAVContentKeySession::generateKeyRequest(const Strin
 
     if (!m_certificate) {
         String certificateString("certificate"_s);
-        RefPtr<Uint8Array> array = Uint8Array::create(certificateString.length());
+        auto array = Uint8Array::create(certificateString.length());
         for (unsigned i = 0, length = certificateString.length(); i < length; ++i)
             array->set(i, certificateString[i]);
-        return array;
+        return WTFMove(array);
     }
 
     if (!m_keyRequest) {
@@ -210,7 +210,7 @@ void CDMSessionAVContentKeySession::releaseKeys()
             if (m_sessionId == String(playbackSessionIdValue)) {
                 LOG(Media, "CDMSessionAVContentKeySession::releaseKeys(%p) - found session, sending expiration message");
                 m_expiredSession = expiredSessionData;
-                m_client->sendMessage(Uint8Array::create(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]).get(), emptyString());
+                m_client->sendMessage(Uint8Array::create(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]).ptr(), emptyString());
                 break;
             }
         }
@@ -300,7 +300,7 @@ bool CDMSessionAVContentKeySession::update(Uint8Array* key, RefPtr<Uint8Array>&
             return false;
         }
 
-        nextMessage = Uint8Array::create(static_cast<const uint8_t*>([requestData bytes]), [requestData length]);
+        nextMessage = Uint8Array::tryCreate(static_cast<const uint8_t*>([requestData bytes]), [requestData length]);
         return false;
     }
 
@@ -350,7 +350,7 @@ RefPtr<Uint8Array> CDMSessionAVContentKeySession::generateKeyReleaseMessage(unsi
     errorCode = 0;
     systemCode = 0;
     m_expiredSession = [expiredSessions firstObject];
-    return Uint8Array::create(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]);
+    return Uint8Array::tryCreate(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]);
 }
 
 void CDMSessionAVContentKeySession::didProvideContentKeyRequest(AVContentKeyRequest *keyRequest)
index 82f4cdc..ca19bae 100644 (file)
@@ -99,9 +99,9 @@ RefPtr<Uint8Array> CDMSessionAVFoundationObjC::generateKeyRequest(const String&
     systemCode = 0;
     destinationURL = String();
 
-    RefPtr<ArrayBuffer> keyRequestBuffer = ArrayBuffer::create([keyRequest.get() bytes], [keyRequest.get() length]);
+    auto keyRequestBuffer = ArrayBuffer::create([keyRequest.get() bytes], [keyRequest.get() length]);
     unsigned byteLength = keyRequestBuffer->byteLength();
-    return Uint8Array::create(WTFMove(keyRequestBuffer), 0, byteLength);
+    return Uint8Array::tryCreate(WTFMove(keyRequestBuffer), 0, byteLength);
 }
 
 void CDMSessionAVFoundationObjC::releaseKeys()
index 7b20281..e00f94d 100644 (file)
@@ -122,10 +122,10 @@ RefPtr<Uint8Array> CDMSessionAVStreamSession::generateKeyRequest(const String& m
     }
 
     String certificateString("certificate"_s);
-    RefPtr<Uint8Array> array = Uint8Array::create(certificateString.length());
+    auto array = Uint8Array::create(certificateString.length());
     for (unsigned i = 0, length = certificateString.length(); i < length; ++i)
         array->set(i, certificateString[i]);
-    return array;
+    return WTFMove(array);
 }
 
 void CDMSessionAVStreamSession::releaseKeys()
@@ -156,7 +156,7 @@ void CDMSessionAVStreamSession::releaseKeys()
             if (m_sessionId == String(playbackSessionIdValue)) {
                 LOG(Media, "CDMSessionAVStreamSession::releaseKeys(%p) - found session, sending expiration message");
                 m_expiredSession = expiredSessionData;
-                m_client->sendMessage(Uint8Array::create(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]).get(), emptyString());
+                m_client->sendMessage(Uint8Array::create(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]).ptr(), emptyString());
                 break;
             }
         }
@@ -335,7 +335,7 @@ RefPtr<Uint8Array> CDMSessionAVStreamSession::generateKeyReleaseMessage(unsigned
     errorCode = 0;
     systemCode = 0;
     m_expiredSession = [expiredSessions firstObject];
-    return Uint8Array::create(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]);
+    return Uint8Array::tryCreate(static_cast<const uint8_t*>([m_expiredSession bytes]), [m_expiredSession length]);
 }
 
 }
index d44a087..e00ae2f 100644 (file)
@@ -1764,16 +1764,16 @@ bool MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource(AVAssetR
         // Create an initData with the following layout:
         // [4 bytes: keyURI size], [keyURI size bytes: keyURI]
         unsigned keyURISize = keyURI.length() * sizeof(UChar);
-        RefPtr<ArrayBuffer> initDataBuffer = ArrayBuffer::create(4 + keyURISize, 1);
+        auto initDataBuffer = ArrayBuffer::create(4 + keyURISize, 1);
         unsigned byteLength = initDataBuffer->byteLength();
-        RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, byteLength);
+        auto initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, byteLength);
         initDataView->set<uint32_t>(0, keyURISize, true);
 
-        RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), 4, keyURI.length());
+        auto keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), 4, keyURI.length());
         keyURIArray->setRange(StringView(keyURI).upconvertedCharacters(), keyURI.length() / sizeof(unsigned char), 0);
 
-        RefPtr<Uint8Array> initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
-        if (!player()->keyNeeded(initData.get()))
+        auto initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
+        if (!player()->keyNeeded(initData.ptr()))
             return false;
 #endif
         m_keyURIToRequestMap.set(keyURI, avRequest);
@@ -1803,7 +1803,7 @@ bool MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource(AVAssetR
             return false;
         }
 
-        if (!player()->keyNeeded(initData.get()))
+        if (!player()->keyNeeded(initData.ptr()))
             return false;
 
         m_keyURIToRequestMap.set(keyID, avRequest);
index 1898dcb..c3bca61 100644 (file)
@@ -294,7 +294,7 @@ RefPtr<JSC::Uint8ClampedArray> MediaSampleAVFObjC::getRGBAImageData() const
 
     void* data = CVPixelBufferGetBaseAddressOfPlane(rgbaPixelBuffer.get(), 0);
     size_t byteLength = CVPixelBufferGetHeight(pixelBuffer) * CVPixelBufferGetWidth(pixelBuffer) * 4;
-    auto result = JSC::Uint8ClampedArray::create(JSC::ArrayBuffer::create(data, byteLength), 0, byteLength);
+    auto result = JSC::Uint8ClampedArray::tryCreate(JSC::ArrayBuffer::create(data, byteLength), 0, byteLength);
 
     status = CVPixelBufferUnlockBaseAddress(rgbaPixelBuffer.get(), kCVPixelBufferLock_ReadOnly);
     ASSERT(status == noErr);
index cd35475..21f4bc9 100644 (file)
@@ -650,9 +650,9 @@ void SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataFo
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     LOG(MediaSource, "SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID(%p) - track:%d", this, trackID);
     m_protectedTrackID = trackID;
-    RefPtr<Uint8Array> initDataArray = Uint8Array::create([initData length]);
+    auto initDataArray = Uint8Array::create([initData length]);
     [initData getBytes:initDataArray->data() length:initDataArray->length()];
-    m_mediaSource->sourceBufferKeyNeeded(this, initDataArray.get());
+    m_mediaSource->sourceBufferKeyNeeded(this, initDataArray.ptr());
     if (auto session = m_mediaSource->player()->cdmSession()) {
         session->addParser(m_parser.get());
         hasSessionSemaphore->signal();
index 456af78..ccbbe1f 100644 (file)
@@ -412,7 +412,7 @@ RefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, const IntRect& logic
     if (area.hasOverflowed())
         return nullptr;
 
-    auto result = Uint8ClampedArray::createUninitialized(area.unsafeGet());
+    auto result = Uint8ClampedArray::tryCreateUninitialized(area.unsafeGet());
     if (!result)
         return nullptr;
 
index d42aa34..8479d5d 100644 (file)
@@ -133,7 +133,7 @@ RefPtr<Uint8ClampedArray> ImageBufferData::getData(AlphaPremultiplication output
     if (area.hasOverflowed())
         return nullptr;
 
-    auto result = Uint8ClampedArray::createUninitialized(area.unsafeGet());
+    auto result = Uint8ClampedArray::tryCreateUninitialized(area.unsafeGet());
     uint8_t* resultData = result ? result->data() : nullptr;
     if (!resultData)
         return nullptr;
index 9a7998d..1180231 100644 (file)
@@ -531,7 +531,7 @@ void FEGaussianBlur::platformApplySoftware()
 
     IntSize paintSize = absolutePaintRect().size();
     paintSize.scale(filter().filterScale());
-    auto tmpImageData = Uint8ClampedArray::createUninitialized((paintSize.area() * 4).unsafeGet());
+    auto tmpImageData = Uint8ClampedArray::tryCreateUninitialized((paintSize.area() * 4).unsafeGet());
     if (!tmpImageData)
         return;
 
index 66c30a9..6e986d4 100644 (file)
@@ -290,7 +290,7 @@ RefPtr<Uint8ClampedArray> FilterEffect::unmultipliedResult(const IntRect& rect)
     IntSize scaledSize(rect.size());
     ASSERT(!ImageBuffer::sizeNeedsClamping(scaledSize));
     scaledSize.scale(m_filter.filterScale());
-    auto imageData = Uint8ClampedArray::createUninitialized((scaledSize.area() * 4).unsafeGet());
+    auto imageData = Uint8ClampedArray::tryCreateUninitialized((scaledSize.area() * 4).unsafeGet());
     if (!imageData)
         return nullptr;
 
@@ -303,7 +303,7 @@ RefPtr<Uint8ClampedArray> FilterEffect::premultipliedResult(const IntRect& rect)
     IntSize scaledSize(rect.size());
     ASSERT(!ImageBuffer::sizeNeedsClamping(scaledSize));
     scaledSize.scale(m_filter.filterScale());
-    auto imageData = Uint8ClampedArray::createUninitialized((scaledSize.area() * 4).unsafeGet());
+    auto imageData = Uint8ClampedArray::tryCreateUninitialized((scaledSize.area() * 4).unsafeGet());
     if (!imageData)
         return nullptr;
     copyPremultipliedResult(*imageData, rect);
@@ -450,7 +450,7 @@ void FilterEffect::copyUnmultipliedResult(Uint8ClampedArray& destination, const
             IntSize inputSize(m_absolutePaintRect.size());
             ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
             inputSize.scale(m_filter.filterScale());
-            m_unmultipliedImageResult = Uint8ClampedArray::createUninitialized((inputSize.area() * 4).unsafeGet());
+            m_unmultipliedImageResult = Uint8ClampedArray::tryCreateUninitialized((inputSize.area() * 4).unsafeGet());
             if (!m_unmultipliedImageResult)
                 return;
             
@@ -476,7 +476,7 @@ void FilterEffect::copyPremultipliedResult(Uint8ClampedArray& destination, const
             IntSize inputSize(m_absolutePaintRect.size());
             ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
             inputSize.scale(m_filter.filterScale());
-            m_premultipliedImageResult = Uint8ClampedArray::createUninitialized((inputSize.area() * 4).unsafeGet());
+            m_premultipliedImageResult = Uint8ClampedArray::tryCreateUninitialized((inputSize.area() * 4).unsafeGet());
             if (!m_premultipliedImageResult)
                 return;
             
@@ -515,7 +515,7 @@ Uint8ClampedArray* FilterEffect::createUnmultipliedImageResult()
     IntSize resultSize(m_absolutePaintRect.size());
     ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
     resultSize.scale(m_filter.filterScale());
-    m_unmultipliedImageResult = Uint8ClampedArray::createUninitialized((resultSize.area() * 4).unsafeGet());
+    m_unmultipliedImageResult = Uint8ClampedArray::tryCreateUninitialized((resultSize.area() * 4).unsafeGet());
     return m_unmultipliedImageResult.get();
 }
 
@@ -531,7 +531,7 @@ Uint8ClampedArray* FilterEffect::createPremultipliedImageResult()
     IntSize resultSize(m_absolutePaintRect.size());
     ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
     resultSize.scale(m_filter.filterScale());
-    m_premultipliedImageResult = Uint8ClampedArray::createUninitialized((resultSize.area() * 4).unsafeGet());
+    m_premultipliedImageResult = Uint8ClampedArray::tryCreateUninitialized((resultSize.area() * 4).unsafeGet());
     return m_premultipliedImageResult.get();
 }
 
index f0e2580..0275f9d 100644 (file)
@@ -50,7 +50,7 @@ RefPtr<Uint8ClampedArray> ImageBufferData::getData(AlphaPremultiplication, const
     if (numBytes.hasOverflowed())
         return nullptr;
 
-    auto result = Uint8ClampedArray::createUninitialized(numBytes.unsafeGet());
+    auto result = Uint8ClampedArray::tryCreateUninitialized(numBytes.unsafeGet());
     unsigned char* resultData = result ? result->data() : nullptr;
     if (!resultData)
         return nullptr;
index dc0d41c..e997b36 100644 (file)
@@ -190,7 +190,7 @@ static JSValue *jsValueWithDictionaryInContext(NSDictionary *dictionary, JSConte
         if (!value)
             continue;
 
-        auto name = OpaqueJSString::create(key);
+        auto name = OpaqueJSString::tryCreate(key);
         JSObjectSetProperty([context JSGlobalContextRef], resultObject, name.get(), [value JSValueRef], 0, &exception);
         if (exception)
             continue;
index d4aa205..e54ba37 100644 (file)
@@ -49,7 +49,7 @@ MockBox::MockBox(ArrayBuffer* data)
 String MockBox::peekType(ArrayBuffer* data)
 {
     StringBuilder builder;
-    RefPtr<Int8Array> array = JSC::Int8Array::create(data, 0, 4);
+    auto array = JSC::Int8Array::create(data, 0, 4);
     for (int i = 0; i < 4; ++i)
         builder.append(array->item(i));
     return builder.toString();
@@ -57,7 +57,7 @@ String MockBox::peekType(ArrayBuffer* data)
 
 size_t MockBox::peekLength(ArrayBuffer* data)
 {
-    RefPtr<JSC::DataView> view = JSC::DataView::create(data, 0, data->byteLength());
+    auto view = JSC::DataView::create(data, 0, data->byteLength());
     return view->get<uint32_t>(4, true);
 }
 
@@ -66,11 +66,11 @@ MockTrackBox::MockTrackBox(ArrayBuffer* data)
 {
     ASSERT(m_length == 17);
 
-    RefPtr<JSC::DataView> view = JSC::DataView::create(data, 0, data->byteLength());
+    auto view = JSC::DataView::create(data, 0, data->byteLength());
     m_trackID = view->get<int32_t>(8, true);
 
     StringBuilder builder;
-    RefPtr<Int8Array> array = JSC::Int8Array::create(data, 12, 4);
+    auto array = JSC::Int8Array::create(data, 12, 4);
     for (int i = 0; i < 4; ++i)
         builder.append(array->item(i));
     m_codec = builder.toString();
@@ -89,7 +89,7 @@ MockInitializationBox::MockInitializationBox(ArrayBuffer* data)
 {
     ASSERT(m_length >= 13);
 
-    RefPtr<JSC::DataView> view = JSC::DataView::create(data, 0, data->byteLength());
+    auto view = JSC::DataView::create(data, 0, data->byteLength());
     int32_t timeValue = view->get<int32_t>(8, true);
     int32_t timeScale = view->get<int32_t>(12, true);
     m_duration = MediaTime(timeValue, timeScale);
@@ -118,7 +118,7 @@ MockSampleBox::MockSampleBox(ArrayBuffer* data)
 {
     ASSERT(m_length == 30);
 
-    RefPtr<JSC::DataView> view = JSC::DataView::create(data, 0, data->byteLength());
+    auto view = JSC::DataView::create(data, 0, data->byteLength());
     int32_t timeScale = view->get<int32_t>(8, true);
 
     int32_t timeValue = view->get<int32_t>(12, true);
index 6832d09..b757f9f 100644 (file)
@@ -189,6 +189,7 @@ std::unique_ptr<Shape> Shape::createRasterShape(Image* image, float threshold, c
             graphicsContext.drawImage(*image, IntRect(IntPoint(), imageRect.size()));
 
         RefPtr<Uint8ClampedArray> pixelArray = imageBuffer->getUnmultipliedImageData(IntRect(IntPoint(), imageRect.size()));
+        RELEASE_ASSERT(pixelArray);
         unsigned pixelArrayLength = pixelArray->length();
         unsigned pixelArrayOffset = 3; // Each pixel is four bytes: RGBA.
         uint8_t alphaPixelThreshold = threshold * 255;
index 3890c0f..64287d2 100644 (file)
@@ -79,25 +79,25 @@ std::unique_ptr<LegacyCDMSession> LegacyMockCDM::createSession(LegacyCDMSessionC
 static Uint8Array* initDataPrefix()
 {
     const unsigned char prefixData[] = { 'm', 'o', 'c', 'k' };
-    static Uint8Array* prefix = Uint8Array::create(prefixData, WTF_ARRAY_LENGTH(prefixData)).leakRef();
+    static Uint8Array& prefix { Uint8Array::create(prefixData, WTF_ARRAY_LENGTH(prefixData)).leakRef() };
 
-    return prefix;
+    return &prefix;
 }
 
 static Uint8Array* keyPrefix()
 {
     static const unsigned char prefixData[] = {'k', 'e', 'y'};
-    static Uint8Array* prefix = Uint8Array::create(prefixData, WTF_ARRAY_LENGTH(prefixData)).leakRef();
+    static Uint8Array& prefix { Uint8Array::create(prefixData, WTF_ARRAY_LENGTH(prefixData)).leakRef() };
 
-    return prefix;
+    return &prefix;
 }
 
 static Uint8Array* keyRequest()
 {
     static const unsigned char requestData[] = {'r', 'e', 'q', 'u', 'e', 's', 't'};
-    static Uint8Array* request = Uint8Array::create(requestData, WTF_ARRAY_LENGTH(requestData)).leakRef();
+    static Uint8Array& request { Uint8Array::create(requestData, WTF_ARRAY_LENGTH(requestData)).leakRef() };
 
-    return request;
+    return &request;
 }
 
 static String generateSessionId()
index 7ef22d1..25b345d 100644 (file)
@@ -1,3 +1,22 @@
+2018-10-10  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=190429
+
+        Reviewed by Saam Barati.
+
+        Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.
+
+        * Shared/API/c/WKString.cpp:
+        (WKStringCopyJSString):
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::toJSValue):
+        (WebKit::callPropertyFunction):
+        (WebKit::WebAutomationSessionProxy::scriptObjectForFrame):
+        (WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction):
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::runScriptsInPDFDocument):
+
 2018-10-10  Chris Dumez  <cdumez@apple.com>
 
         Regression(PSON): Assertion hit under WebPageProxy::didNavigateWithNavigationData()
index 78de61e..767aa8d 100644 (file)
@@ -136,5 +136,5 @@ WKStringRef WKStringCreateWithJSString(JSStringRef jsStringRef)
 JSStringRef WKStringCopyJSString(WKStringRef stringRef)
 {
     JSC::initializeThreading();
-    return OpaqueJSString::create(toImpl(stringRef)->string()).leakRef();
+    return OpaqueJSString::tryCreate(toImpl(stringRef)->string()).leakRef();
 }
index 29fb01e..efa0341 100644 (file)
@@ -88,7 +88,7 @@ static JSObjectRef toJSArray(JSContextRef context, const Vector<T>& data, JSValu
 
 static inline JSValueRef toJSValue(JSContextRef context, const String& string)
 {
-    return JSValueMakeString(context, OpaqueJSString::create(string).get());
+    return JSValueMakeString(context, OpaqueJSString::tryCreate(string).get());
 }
 
 static inline JSValueRef callPropertyFunction(JSContextRef context, JSObjectRef object, const String& propertyName, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
@@ -96,7 +96,7 @@ static inline JSValueRef callPropertyFunction(JSContextRef context, JSObjectRef
     ASSERT_ARG(object, object);
     ASSERT_ARG(object, JSValueIsObject(context, object));
 
-    JSObjectRef function = const_cast<JSObjectRef>(JSObjectGetProperty(context, object, OpaqueJSString::create(propertyName).get(), exception));
+    JSObjectRef function = const_cast<JSObjectRef>(JSObjectGetProperty(context, object, OpaqueJSString::tryCreate(propertyName).get(), exception));
     ASSERT(JSObjectIsFunction(context, function));
 
     return JSObjectCallAsFunction(context, function, object, argumentCount, arguments, exception);
@@ -177,7 +177,7 @@ JSObjectRef WebAutomationSessionProxy::scriptObjectForFrame(WebFrame& frame)
 
     String script = StringImpl::createWithoutCopying(WebAutomationSessionProxyScriptSource, sizeof(WebAutomationSessionProxyScriptSource));
 
-    JSObjectRef scriptObjectFunction = const_cast<JSObjectRef>(JSEvaluateScript(context, OpaqueJSString::create(script).get(), nullptr, nullptr, 0, &exception));
+    JSObjectRef scriptObjectFunction = const_cast<JSObjectRef>(JSEvaluateScript(context, OpaqueJSString::tryCreate(script).get(), nullptr, nullptr, 0, &exception));
     ASSERT(JSValueIsObject(context, scriptObjectFunction));
 
     JSValueRef arguments[] = { sessionIdentifier, evaluateFunction, createUUIDFunction };
@@ -280,7 +280,7 @@ void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t pageID, uint
 
     String exceptionMessage;
     if (JSValueIsObject(context, exception)) {
-        JSValueRef nameValue = JSObjectGetProperty(context, const_cast<JSObjectRef>(exception), OpaqueJSString::create("name"_s).get(), nullptr);
+        JSValueRef nameValue = JSObjectGetProperty(context, const_cast<JSObjectRef>(exception), OpaqueJSString::tryCreate("name"_s).get(), nullptr);
         auto exceptionName = adoptRef(JSValueToStringCopy(context, nameValue, nullptr))->string();
         if (exceptionName == "NodeNotFound")
             errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::NodeNotFound);
@@ -291,7 +291,7 @@ void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t pageID, uint
         else if (exceptionName == "InvalidSelector")
             errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidSelector);
 
-        JSValueRef messageValue = JSObjectGetProperty(context, const_cast<JSObjectRef>(exception), OpaqueJSString::create("message"_s).get(), nullptr);
+        JSValueRef messageValue = JSObjectGetProperty(context, const_cast<JSObjectRef>(exception), OpaqueJSString::tryCreate("message"_s).get(), nullptr);
         exceptionMessage = adoptRef(JSValueToStringCopy(context, messageValue, nullptr))->string();
     } else
         exceptionMessage = adoptRef(JSValueToStringCopy(context, exception, nullptr))->string();
index 3d1fe75..49b2225 100644 (file)
@@ -1118,7 +1118,7 @@ void PDFPlugin::runScriptsInPDFDocument()
     JSGlobalContextRef ctx = JSGlobalContextCreate(0);
     JSObjectRef jsPDFDoc = makeJSPDFDoc(ctx);
     for (auto& script : scripts)
-        JSEvaluateScript(ctx, OpaqueJSString::create(script.get()).get(), jsPDFDoc, nullptr, 0, nullptr);
+        JSEvaluateScript(ctx, OpaqueJSString::tryCreate(script.get()).get(), jsPDFDoc, nullptr, 0, nullptr);
     JSGlobalContextRelease(ctx);
 }
 
index 8af3c3c..667efaf 100644 (file)
@@ -1,3 +1,17 @@
+2018-10-10  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=190429
+
+        Reviewed by Saam Barati.
+
+        Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.
+
+        * WebView/WebPDFViewIOS.mm:
+        (-[WebPDFView finishedLoadingWithDataSource:]):
+        * WebView/WebPDFViewPlaceholder.mm:
+        (-[WebPDFViewPlaceholder _evaluateJSForDocument:]):
+
 2018-10-02  Alex Christensen  <achristensen@webkit.org>
 
         Remove unused linked-on-or-before-iOS5 check
index 1841b98..f8b66a3 100644 (file)
@@ -326,7 +326,7 @@ static CGColorRef createCGColorWithDeviceWhite(CGFloat white, CGFloat alpha)
     JSGlobalContextRef ctx = JSGlobalContextCreate(0);
     JSObjectRef jsPDFDoc = makeJSPDFDoc(ctx, dataSource);
     for (NSString *script in scripts)
-        JSEvaluateScript(ctx, OpaqueJSString::create(script).get(), jsPDFDoc, nullptr, 0, nullptr);
+        JSEvaluateScript(ctx, OpaqueJSString::tryCreate(script).get(), jsPDFDoc, nullptr, 0, nullptr);
     JSGlobalContextRelease(ctx);
 
     [self setNeedsDisplay:YES];
index 1e86ba0..e8ea52c 100644 (file)
@@ -307,7 +307,7 @@ static const float PAGE_HEIGHT_INSET = 4.0f * 2.0f;
         JSGlobalContextRef ctx = JSGlobalContextCreate(0);
         JSObjectRef jsPDFDoc = makeJSPDFDoc(ctx, _dataSource);
         for (NSString *script in scripts)
-            JSEvaluateScript(ctx, OpaqueJSString::create(script).get(), jsPDFDoc, nullptr, 0, nullptr);
+            JSEvaluateScript(ctx, OpaqueJSString::tryCreate(script).get(), jsPDFDoc, nullptr, 0, nullptr);
         JSGlobalContextRelease(ctx);
     }
 }
index d54a27c..42c5264 100644 (file)
@@ -1,3 +1,15 @@
+2018-10-10  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=190429
+
+        Reviewed by Saam Barati.
+
+        Use `tryCreate` or new `create`. If we use new `create`, we can use Ref<> and remove null check.
+
+        * WebView/WebPDFRepresentation.mm:
+        (-[WebPDFRepresentation finishedLoadingWithDataSource:]):
+
 2018-10-08  Justin Fan  <justin_fan@apple.com>
 
         WebGPU: Rename old WebGPU prototype to WebMetal
index aadfed2..3468ddd 100644 (file)
     JSGlobalContextRef ctx = JSGlobalContextCreate(0);
     JSObjectRef jsPDFDoc = makeJSPDFDoc(ctx, dataSource);
     for (NSString *script in scripts)
-        JSEvaluateScript(ctx, OpaqueJSString::create(script).get(), jsPDFDoc, nullptr, 0, nullptr);
+        JSEvaluateScript(ctx, OpaqueJSString::tryCreate(script).get(), jsPDFDoc, nullptr, 0, nullptr);
     JSGlobalContextRelease(ctx);
 }
 
index bbdb53e..02d2bf7 100644 (file)
@@ -1,3 +1,13 @@
+2018-10-10  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=190429
+
+        Reviewed by Saam Barati.
+
+        * TestWebKitAPI/Tests/WebCore/mac/GPUBuffer.mm:
+        (TestWebKitAPI::TEST_F):
+
 2018-10-10  Chris Dumez  <cdumez@apple.com>
 
         Regression(PSON): Assertion hit under WebPageProxy::didNavigateWithNavigationData()
index 77ac59e..9cd2aaa 100644 (file)
@@ -59,7 +59,7 @@ TEST_F(GPU, BufferCreate)
     auto data = bufferView->data();
     memset(data, 1, bufferView->byteLength());
 
-    GPUBuffer buffer { device, *bufferView };
+    GPUBuffer buffer { device, bufferView.get() };
     EXPECT_EQ(1024U, buffer.length());
 
     auto contents = buffer.contents();