Changeset 158695 in webkit for trunk/Source/JavaScriptCore/API/ObjCCallbackFunction.mm
- Timestamp:
- Nov 5, 2013, 2:51:52 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/ObjCCallbackFunction.mm
r158286 r158695 408 408 ~ObjCCallbackFunctionImpl() 409 409 { 410 // We need to explicity release the target since we didn't call 411 // -retainArguments on m_invocation (and we don't want to do so). 412 if (m_type == CallbackBlock || m_type == CallbackClassMethod) 413 [[m_invocation.get() target] release]; 410 414 [m_instanceClass release]; 411 415 } … … 540 544 if (m_type == CallbackInitMethod) 541 545 return class_getName(m_instanceClass); 546 // FIXME: Maybe we could support having the selector as the name of the non-init 547 // functions to make it a bit more user-friendly from the JS side? 542 548 return ""; 543 549 } … … 664 670 JSC::APIEntryShim shim(exec); 665 671 OwnPtr<JSC::ObjCCallbackFunctionImpl> impl = adoptPtr(new JSC::ObjCCallbackFunctionImpl(invocation, type, instanceClass, arguments.release(), result.release())); 666 // FIXME: Maybe we could support having the selector as the name of the function to make it a bit more user-friendly from the JS side?667 672 return toRef(JSC::ObjCCallbackFunction::create(exec->vm(), exec->lexicalGlobalObject(), impl->name(), impl.release())); 668 673 } … … 679 684 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:types]]; 680 685 [invocation setSelector:sel]; 686 // We need to retain the target Class because m_invocation doesn't retain it 687 // by default (and we don't want it to). 681 688 if (!isInstanceMethod) 682 [invocation setTarget: cls];689 [invocation setTarget:[cls retain]]; 683 690 return objCCallbackFunctionForInvocation(context, invocation, isInstanceMethod ? CallbackInstanceMethod : CallbackClassMethod, isInstanceMethod ? cls : nil, _protocol_getMethodTypeEncoding(protocol, sel, YES, isInstanceMethod)); 684 691 } … … 690 697 const char* signature = _Block_signature(target); 691 698 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:signature]]; 692 [invocation retainArguments]; 693 id targetCopy = [target copy]; 694 [invocation setTarget:targetCopy]; 695 [targetCopy release]; 699 700 // We don't want to use -retainArguments because that leaks memory. Arguments 701 // would be retained indefinitely between invocations of the callback. 702 // Additionally, we copy the target because we want the block to stick around 703 // until the ObjCCallbackFunctionImpl is destroyed. 704 [invocation setTarget:[target copy]]; 705 696 706 return objCCallbackFunctionForInvocation(context, invocation, CallbackBlock, nil, signature); 697 707 }
Note:
See TracChangeset
for help on using the changeset viewer.