@@ -166,7 +166,7 @@ static bool constructorHasInstance(JSContextRef ctx, JSObjectRef constructorRef,
166166 auto renameMap = adoptNS ([[NSMutableDictionary alloc ] init ]);
167167
168168 forEachMethodInProtocol (protocol, NO , isInstanceMethod, ^(SEL sel, const char *){
169- NSString * rename = @(sel_getName (sel));
169+ RetainPtr rename = @(sel_getName (sel));
170170 NSRange range = [rename rangeOfString: @" __JS_EXPORT_AS__" ];
171171 if (range.location == NSNotFound )
172172 return ;
@@ -255,22 +255,22 @@ static void copyMethodsToObject(JSContext *context, Class objcClass, Protocol *p
255255
256256 forEachMethodInProtocol (protocol, YES , isInstanceMethod, ^(SEL sel, const char * types){
257257 const char * nameCStr = sel_getName (sel);
258- NSString * name = @(nameCStr);
258+ RetainPtr name = @(nameCStr);
259259
260- if (shouldSkipMethodWithName (name))
260+ if (shouldSkipMethodWithName (name. get () ))
261261 return ;
262262
263- if (accessorMethods && accessorMethods[name]) {
263+ if (accessorMethods && accessorMethods[name. get () ]) {
264264 JSObjectRef method = objCCallbackFunctionForMethod (context, objcClass, protocol, isInstanceMethod, sel, types);
265265 if (!method)
266266 return ;
267- accessorMethods[name] = [JSValue valueWithJSValueRef: method inContext: context];
267+ accessorMethods[name. get () ] = [JSValue valueWithJSValueRef: method inContext: context];
268268 } else {
269- name = renameMap.get ()[name];
269+ name = renameMap.get ()[name. get () ];
270270 if (!name)
271271 name = selectorToPropertyName (nameCStr);
272272 JSC ::JSGlobalObject* globalObject = toJS ([context JSGlobalContextRef ]);
273- JSValue *existingMethod = object[name];
273+ JSValue *existingMethod = object[name. get () ];
274274 // ObjCCallbackFunction does a dynamic lookup for the
275275 // selector before calling the method. In order to save
276276 // memory we only put one callback object in any givin
@@ -282,7 +282,7 @@ static void copyMethodsToObject(JSContext *context, Class objcClass, Protocol *p
282282 return ;
283283 JSObjectRef method = objCCallbackFunctionForMethod (context, objcClass, protocol, isInstanceMethod, sel, types);
284284 if (method)
285- putNonEnumerable (context, object, name, [JSValue valueWithJSValueRef: method inContext: context]);
285+ putNonEnumerable (context, object, name. get () , [JSValue valueWithJSValueRef: method inContext: context]);
286286 }
287287 });
288288}
@@ -368,15 +368,15 @@ static void copyPrototypeProperties(JSContext *context, Class objcClass, Protoco
368368 JSValue* getter = accessorMethods[property.getterName.get ()];
369369 ASSERT (![getter isUndefined ]);
370370
371- JSValue* setter = undefined;
371+ RetainPtr setter = undefined;
372372 if (property.setterName ) {
373373 setter = accessorMethods[property.setterName.get ()];
374374 ASSERT (![setter isUndefined ]);
375375 }
376-
376+
377377 [prototypeValue defineProperty: @(property.name) descriptor: @{
378378 JSPropertyDescriptorGetKey: getter,
379- JSPropertyDescriptorSetKey: setter,
379+ JSPropertyDescriptorSetKey: setter. get () ,
380380 JSPropertyDescriptorEnumerableKey: @NO ,
381381 JSPropertyDescriptorConfigurableKey: @YES
382382 }];
@@ -431,9 +431,9 @@ - (void)dealloc
431431
432432 // For each protocol that the class implements, gather all of the init family methods into a hash table.
433433 __block UncheckedKeyHashMap<String, CFTypeRef> initTable;
434- Protocol * exportProtocol = getJSExportProtocol ();
435- for (Class currentClass = cls; currentClass; currentClass = class_getSuperclass (currentClass)) {
436- forEachProtocolImplementingProtocol (currentClass, exportProtocol, ^(Protocol *protocol, bool &) {
434+ RetainPtr exportProtocol = getJSExportProtocol ();
435+ for (RetainPtr currentClass = cls; currentClass; currentClass = class_getSuperclass (currentClass. get () )) {
436+ forEachProtocolImplementingProtocol (currentClass. get () , exportProtocol. get () , ^(Protocol *protocol, bool &) {
437437 forEachMethodInProtocol (protocol, YES , YES , ^(SEL selector, const char *) {
438438 const char * name = sel_getName (selector);
439439 if (!isInitFamilyMethod (@(name)))
@@ -443,12 +443,12 @@ - (void)dealloc
443443 });
444444 }
445445
446- for (Class currentClass = cls; currentClass; currentClass = class_getSuperclass (currentClass)) {
446+ for (RetainPtr currentClass = cls; currentClass; currentClass = class_getSuperclass (currentClass. get () )) {
447447 __block unsigned numberOfInitsFound = 0 ;
448448 __block SEL initMethod = 0 ;
449- __block Protocol * initProtocol = 0 ;
449+ __block RetainPtr< Protocol> initProtocol;
450450 __block const char * types = 0 ;
451- forEachMethodInClass (currentClass, ^(Method method) {
451+ forEachMethodInClass (currentClass. get () , ^(Method method) {
452452 SEL selector = method_getName (method);
453453 const char * name = sel_getName (selector);
454454 auto iter = initTable.find (String::fromLatin1 (name));
@@ -470,7 +470,7 @@ - (void)dealloc
470470 break ;
471471 }
472472
473- JSObjectRef method = objCCallbackFunctionForInit (context, cls, initProtocol, initMethod, types);
473+ JSObjectRef method = objCCallbackFunctionForInit (context, cls, initProtocol. get () , initMethod, types);
474474 return toJS (method);
475475 }
476476 return constructorWithCustomBrand (context, [NSString stringWithFormat: @" %s Constructor" , className], cls);
@@ -511,8 +511,8 @@ - (ConstructorPrototypePair)ensureConstructorAndPrototypeInContext:(JSContext *)
511511 putNonEnumerable (context, prototype, @" constructor" , constructor);
512512 putNonEnumerable (context, constructor, @" prototype" , prototype);
513513
514- Protocol * exportProtocol = getJSExportProtocol ();
515- forEachProtocolImplementingProtocol (m_class, exportProtocol, ^(Protocol *protocol, bool &){
514+ RetainPtr exportProtocol = getJSExportProtocol ();
515+ forEachProtocolImplementingProtocol (m_class, exportProtocol. get () , ^(Protocol *protocol, bool &) {
516516 copyPrototypeProperties (context, m_class, protocol, prototype);
517517 copyMethodsToObject (context, m_class, protocol, NO , constructor);
518518 });
@@ -714,14 +714,14 @@ bool supportsInitMethodConstructors()
714714
715715Protocol *getJSExportProtocol ()
716716{
717- static Protocol * protocol = objc_getProtocol (" JSExport" );
718- return protocol;
717+ static NeverDestroyed<RetainPtr< Protocol>> protocol = objc_getProtocol (" JSExport" );
718+ return protocol-> get () ;
719719}
720720
721721Class getNSBlockClass ()
722722{
723- static Class cls = objc_getClass (" NSBlock" );
724- return cls;
723+ static NeverDestroyed<RetainPtr< Class >> cls = objc_getClass (" NSBlock" );
724+ return cls-> get () ;
725725}
726726
727727WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
0 commit comments