Skip to content

Commit fe8ab64

Browse files
committed
[JSC] Rename createXXX to tryCreateXXX if it can return RefPtr
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): Canonical link: https://commits.webkit.org/205388@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237009 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 7477a4f commit fe8ab64

90 files changed

Lines changed: 532 additions & 203 deletions

File tree

Some content is hidden

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

Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ bool JSCallbackObject<Parent>::getOwnPropertySlot(JSObject* object, ExecState* e
155155
// optional optimization to bypass getProperty in cases when we only need to know if the property exists
156156
if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
157157
if (!propertyNameRef)
158-
propertyNameRef = OpaqueJSString::create(name);
158+
propertyNameRef = OpaqueJSString::tryCreate(name);
159159
JSLock::DropAllLocks dropAllLocks(exec);
160160
if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
161161
slot.setCustom(thisObject, PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum, callbackGetter);
162162
return true;
163163
}
164164
} else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
165165
if (!propertyNameRef)
166-
propertyNameRef = OpaqueJSString::create(name);
166+
propertyNameRef = OpaqueJSString::tryCreate(name);
167167
JSValueRef exception = 0;
168168
JSValueRef value;
169169
{
@@ -252,7 +252,7 @@ bool JSCallbackObject<Parent>::put(JSCell* cell, ExecState* exec, PropertyName p
252252
for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
253253
if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
254254
if (!propertyNameRef)
255-
propertyNameRef = OpaqueJSString::create(name);
255+
propertyNameRef = OpaqueJSString::tryCreate(name);
256256
JSValueRef exception = 0;
257257
bool result;
258258
{
@@ -316,7 +316,7 @@ bool JSCallbackObject<Parent>::putByIndex(JSCell* cell, ExecState* exec, unsigne
316316
for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
317317
if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
318318
if (!propertyNameRef)
319-
propertyNameRef = OpaqueJSString::create(propertyName.impl());
319+
propertyNameRef = OpaqueJSString::tryCreate(propertyName.impl());
320320
JSValueRef exception = 0;
321321
bool result;
322322
{
@@ -375,7 +375,7 @@ bool JSCallbackObject<Parent>::deleteProperty(JSCell* cell, ExecState* exec, Pro
375375
for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
376376
if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
377377
if (!propertyNameRef)
378-
propertyNameRef = OpaqueJSString::create(name);
378+
propertyNameRef = OpaqueJSString::tryCreate(name);
379379
JSValueRef exception = 0;
380380
bool result;
381381
{
@@ -679,7 +679,7 @@ EncodedJSValue JSCallbackObject<Parent>::callbackGetter(ExecState* exec, Encoded
679679
for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
680680
if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
681681
if (!propertyNameRef)
682-
propertyNameRef = OpaqueJSString::create(name);
682+
propertyNameRef = OpaqueJSString::tryCreate(name);
683683
JSValueRef exception = 0;
684684
JSValueRef value;
685685
{

Source/JavaScriptCore/API/JSClassRef.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ struct StaticValueEntry {
3737
WTF_MAKE_FAST_ALLOCATED;
3838
public:
3939
StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes, String& propertyName)
40-
: getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes), propertyNameRef(OpaqueJSString::create(propertyName))
40+
: getProperty(_getProperty)
41+
, setProperty(_setProperty)
42+
, attributes(_attributes)
43+
, propertyNameRef(OpaqueJSString::tryCreate(propertyName))
4144
{
4245
}
4346

Source/JavaScriptCore/API/JSContext.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ - (JSValue *)evaluateScript:(NSString *)script
100100
- (JSValue *)evaluateScript:(NSString *)script withSourceURL:(NSURL *)sourceURL
101101
{
102102
JSValueRef exceptionValue = nullptr;
103-
auto scriptJS = OpaqueJSString::create(script);
104-
auto sourceURLJS = OpaqueJSString::create([sourceURL absoluteString]);
103+
auto scriptJS = OpaqueJSString::tryCreate(script);
104+
auto sourceURLJS = OpaqueJSString::tryCreate([sourceURL absoluteString]);
105105
JSValueRef result = JSEvaluateScript(m_context, scriptJS.get(), nullptr, sourceURLJS.get(), 0, &exceptionValue);
106106

107107
if (exceptionValue)
@@ -200,7 +200,7 @@ - (NSString *)name
200200

201201
- (void)setName:(NSString *)name
202202
{
203-
JSGlobalContextSetName(m_context, OpaqueJSString::create(name).get());
203+
JSGlobalContextSetName(m_context, OpaqueJSString::tryCreate(name).get());
204204
}
205205

206206
- (BOOL)_remoteInspectionEnabled

Source/JavaScriptCore/API/JSContextRef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ JSStringRef JSGlobalContextCopyName(JSGlobalContextRef ctx)
232232
if (name.isNull())
233233
return 0;
234234

235-
return OpaqueJSString::create(name).leakRef();
235+
return OpaqueJSString::tryCreate(name).leakRef();
236236
}
237237

238238
void JSGlobalContextSetName(JSGlobalContextRef ctx, JSStringRef name)
@@ -316,7 +316,7 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
316316
BacktraceFunctor functor(builder, maxStackSize);
317317
frame->iterate(functor);
318318

319-
return OpaqueJSString::create(builder.toString()).leakRef();
319+
return OpaqueJSString::tryCreate(builder.toString()).leakRef();
320320
}
321321

322322
bool JSGlobalContextGetRemoteInspectionEnabled(JSGlobalContextRef ctx)

Source/JavaScriptCore/API/JSObjectRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef o
820820
size_t size = array.size();
821821
propertyNames->array.reserveInitialCapacity(size);
822822
for (size_t i = 0; i < size; ++i)
823-
propertyNames->array.uncheckedAppend(OpaqueJSString::create(array[i].string()).releaseNonNull());
823+
propertyNames->array.uncheckedAppend(OpaqueJSString::tryCreate(array[i].string()).releaseNonNull());
824824

825825
return JSPropertyNameArrayRetain(propertyNames);
826826
}

Source/JavaScriptCore/API/JSScriptRef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ JSScriptRef JSScriptCreateReferencingImmortalASCIIText(JSContextGroupRef context
9999
ParserError error;
100100
if (!parseScript(vm, SourceCode(result.copyRef()), error)) {
101101
if (errorMessage)
102-
*errorMessage = OpaqueJSString::create(error.message()).leakRef();
102+
*errorMessage = OpaqueJSString::tryCreate(error.message()).leakRef();
103103
if (errorLine)
104104
*errorLine = error.line();
105105
return nullptr;
@@ -121,7 +121,7 @@ JSScriptRef JSScriptCreateFromString(JSContextGroupRef contextGroup, JSStringRef
121121
ParserError error;
122122
if (!parseScript(vm, SourceCode(result.copyRef()), error)) {
123123
if (errorMessage)
124-
*errorMessage = OpaqueJSString::create(error.message()).leakRef();
124+
*errorMessage = OpaqueJSString::tryCreate(error.message()).leakRef();
125125
if (errorLine)
126126
*errorLine = error.line();
127127
return nullptr;

Source/JavaScriptCore/API/JSStringRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ JSStringRef JSStringCreateWithUTF8CString(const char* string)
6262
JSStringRef JSStringCreateWithCharactersNoCopy(const JSChar* chars, size_t numChars)
6363
{
6464
initializeThreading();
65-
return OpaqueJSString::create(StringImpl::createWithoutCopying(reinterpret_cast<const UChar*>(chars), numChars)).leakRef();
65+
return OpaqueJSString::tryCreate(StringImpl::createWithoutCopying(reinterpret_cast<const UChar*>(chars), numChars)).leakRef();
6666
}
6767

6868
JSStringRef JSStringRetain(JSStringRef string)

Source/JavaScriptCore/API/JSValue.mm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ + (JSValue *)valueWithNewArrayInContext:(JSContext *)context
126126

127127
+ (JSValue *)valueWithNewRegularExpressionFromPattern:(NSString *)pattern flags:(NSString *)flags inContext:(JSContext *)context
128128
{
129-
auto patternString = OpaqueJSString::create(pattern);
130-
auto flagsString = OpaqueJSString::create(flags);
129+
auto patternString = OpaqueJSString::tryCreate(pattern);
130+
auto flagsString = OpaqueJSString::tryCreate(flags);
131131
JSValueRef arguments[2] = { JSValueMakeString([context JSGlobalContextRef], patternString.get()), JSValueMakeString([context JSGlobalContextRef], flagsString.get()) };
132132
return [JSValue valueWithJSValueRef:JSObjectMakeRegExp([context JSGlobalContextRef], 2, arguments, 0) inContext:context];
133133
}
134134

135135
+ (JSValue *)valueWithNewErrorFromMessage:(NSString *)message inContext:(JSContext *)context
136136
{
137-
auto string = OpaqueJSString::create(message);
137+
auto string = OpaqueJSString::tryCreate(message);
138138
JSValueRef argument = JSValueMakeString([context JSGlobalContextRef], string.get());
139139
return [JSValue valueWithJSValueRef:JSObjectMakeError([context JSGlobalContextRef], 1, &argument, 0) inContext:context];
140140
}
@@ -151,7 +151,7 @@ + (JSValue *)valueWithUndefinedInContext:(JSContext *)context
151151

152152
+ (JSValue *)valueWithNewSymbolFromDescription:(NSString *)description inContext:(JSContext *)context
153153
{
154-
auto string = OpaqueJSString::create(description);
154+
auto string = OpaqueJSString::tryCreate(description);
155155
return [JSValue valueWithJSValueRef:JSValueMakeSymbol([context JSGlobalContextRef], string.get()) inContext:context];
156156
}
157157

@@ -292,7 +292,7 @@ - (NSDictionary *)toDictionary
292292
Result result;
293293
// If it's a NSString already, reduce indirection and just pass the NSString.
294294
if ([propertyKey isKindOfClass:[NSString class]]) {
295-
auto name = OpaqueJSString::create((NSString *)propertyKey);
295+
auto name = OpaqueJSString::tryCreate((NSString *)propertyKey);
296296
result = stringFunction([context JSGlobalContextRef], object, name.get(), arguments..., &exception);
297297
} else
298298
result = jsFunction([context JSGlobalContextRef], object, [[JSValue valueWithObject:propertyKey inContext:context] JSValueRef], arguments..., &exception);
@@ -520,7 +520,7 @@ - (JSValue *)invokeMethod:(NSString *)method withArguments:(NSArray *)arguments
520520
if (exception)
521521
return [_context valueFromNotifyException:exception];
522522

523-
auto name = OpaqueJSString::create(method);
523+
auto name = OpaqueJSString::tryCreate(method);
524524
JSValueRef function = JSObjectGetProperty([_context JSGlobalContextRef], thisObject, name.get(), &exception);
525525
if (exception)
526526
return [_context valueFromNotifyException:exception];
@@ -774,7 +774,7 @@ static id containerValueToObject(JSGlobalContextRef context, JSContainerConverto
774774
ASSERT([current.objc isKindOfClass:[NSMutableArray class]]);
775775
NSMutableArray *array = (NSMutableArray *)current.objc;
776776

777-
auto lengthString = OpaqueJSString::create("length"_s);
777+
auto lengthString = OpaqueJSString::tryCreate("length"_s);
778778
unsigned length = JSC::toUInt32(JSValueToNumber(context, JSObjectGetProperty(context, js, lengthString.get(), 0), 0));
779779

780780
for (unsigned i = 0; i < length; ++i) {
@@ -984,7 +984,7 @@ inline bool isNSBoolean(id object)
984984
return { object, ((JSValue *)object)->m_value, ContainerNone };
985985

986986
if ([object isKindOfClass:[NSString class]]) {
987-
auto string = OpaqueJSString::create((NSString *)object);
987+
auto string = OpaqueJSString::tryCreate((NSString *)object);
988988
return { object, JSValueMakeString(contextRef, string.get()), ContainerNone };
989989
}
990990

@@ -1041,7 +1041,7 @@ JSValueRef objectToValue(JSContext *context, id object)
10411041
NSDictionary *dictionary = (NSDictionary *)current.objc;
10421042
for (id key in [dictionary keyEnumerator]) {
10431043
if ([key isKindOfClass:[NSString class]]) {
1044-
auto propertyName = OpaqueJSString::create((NSString *)key);
1044+
auto propertyName = OpaqueJSString::tryCreate((NSString *)key);
10451045
JSObjectSetProperty(contextRef, js, propertyName.get(), convertor.convert([dictionary objectForKey:key]), 0, 0);
10461046
}
10471047
}

Source/JavaScriptCore/API/JSValueRef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsig
386386
*exception = 0;
387387
if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
388388
return 0;
389-
return OpaqueJSString::create(result).leakRef();
389+
return OpaqueJSString::tryCreate(result).leakRef();
390390
}
391391

392392
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
@@ -434,7 +434,7 @@ JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef*
434434

435435
JSValue jsValue = toJS(exec, value);
436436

437-
auto stringRef(OpaqueJSString::create(jsValue.toWTFString(exec)));
437+
auto stringRef(OpaqueJSString::tryCreate(jsValue.toWTFString(exec)));
438438
if (handleExceptionIfNeeded(scope, exec, exception) == ExceptionStatus::DidThrow)
439439
stringRef = nullptr;
440440
return stringRef.leakRef();

Source/JavaScriptCore/API/OpaqueJSString.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434

3535
using namespace JSC;
3636

37-
RefPtr<OpaqueJSString> OpaqueJSString::create(const String& string)
37+
RefPtr<OpaqueJSString> OpaqueJSString::tryCreate(const String& string)
3838
{
3939
if (string.isNull())
4040
return nullptr;
4141

4242
return adoptRef(new OpaqueJSString(string));
4343
}
4444

45-
RefPtr<OpaqueJSString> OpaqueJSString::create(String&& string)
45+
RefPtr<OpaqueJSString> OpaqueJSString::tryCreate(String&& string)
4646
{
4747
if (string.isNull())
4848
return nullptr;

0 commit comments

Comments
 (0)