Bug 128540 - Obj-C API: JSExport doesn't work for methods that contain protocols in their type signature
Summary: Obj-C API: JSExport doesn't work for methods that contain protocols in their ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Hahnenberg
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-10 09:49 PST by Mark Hahnenberg
Modified: 2014-02-11 09:39 PST (History)
4 users (show)

See Also:


Attachments
Patch (14.59 KB, patch)
2014-02-10 11:21 PST, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
Patch (14.49 KB, patch)
2014-02-10 11:43 PST, Mark Hahnenberg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Hahnenberg 2014-02-10 09:49:22 PST
The bug is in parseObjCType in ObjcRuntimeExtras.h. When we see an '@' in the type signature of a method, we assume that what follows the '@' is a class name, so we call objc_getClass, and if that returns nil then we give up on the method and don't export it.

This assumption doesn't work in the case of id<Protocol> because it's the name of the protocol that follows the '@', not the name of a class. We should have another fallback case for protocol names.

There's another case that also doesn't work, and that's the case of a named class with a specified prototype in a method signature (e.g. NSObject<MyProtocol>). There the substring of the type signature that represents the class is "NSObject<MyProtocol>", which will also cause objc_getClass to return nil.
Comment 1 Mark Hahnenberg 2014-02-10 09:49:43 PST
<rdar://problem/15954242>
Comment 2 Mark Hahnenberg 2014-02-10 11:21:07 PST
Created attachment 223728 [details]
Patch
Comment 3 Filip Pizlo 2014-02-10 11:25:05 PST
Comment on attachment 223728 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=223728&action=review

> Source/JavaScriptCore/API/ObjcRuntimeExtras.h:198
> +                position = index(++position, '"') + 1;

This feels at first like something that would give you victory at the IOCCC.  I eventually figured it.  But maybe you an come up with a better idiom for this at some point?
Comment 4 Mark Hahnenberg 2014-02-10 11:34:27 PST
(In reply to comment #3)
> (From update of attachment 223728 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=223728&action=review
> 
> > Source/JavaScriptCore/API/ObjcRuntimeExtras.h:198
> > +                position = index(++position, '"') + 1;
> 
> This feels at first like something that would give you victory at the IOCCC.  I eventually figured it.  But maybe you an come up with a better idiom for this at some point?

I guess at this point, begin == position and we don't need to increment anything because we already know we're not pointing at a '"', so i can just change it to:

position = index(begin, '"') + 1;

Copy, paste, modify...not even once.
Comment 5 Geoffrey Garen 2014-02-10 11:40:51 PST
> This feels at first like something that would give you victory at the IOCCC.

Probably only second place, if Gavin also entered.
Comment 6 Mark Hahnenberg 2014-02-10 11:43:25 PST
Created attachment 223729 [details]
Patch
Comment 7 Mark Hahnenberg 2014-02-10 11:43:51 PST
(In reply to comment #6)
> Created an attachment (id=223729) [details]
> Patch

I decided to take Phil's advice to heart and actually write this code in a more understandable fashion.
Comment 8 WebKit Commit Bot 2014-02-11 08:22:42 PST
Comment on attachment 223729 [details]
Patch

Clearing flags on attachment: 223729

Committed r163876: <http://trac.webkit.org/changeset/163876>
Comment 9 WebKit Commit Bot 2014-02-11 08:22:44 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Darin Adler 2014-02-11 08:40:44 PST
Comment on attachment 223729 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=223729&action=review

> Source/JavaScriptCore/API/ObjcRuntimeExtras.h:197
> +            const char* protocolPosition = index(begin, '<');
> +            const char* endOfType = index(begin, '"');

It’s a little strange that we use index() here instead of strchr(). I think that index() is an archaic, pre-standardization, name for the same thing.
Comment 11 Mark Hahnenberg 2014-02-11 09:39:39 PST
(In reply to comment #10)
> (From update of attachment 223729 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=223729&action=review
> 
> > Source/JavaScriptCore/API/ObjcRuntimeExtras.h:197
> > +            const char* protocolPosition = index(begin, '<');
> > +            const char* endOfType = index(begin, '"');
> 
> It’s a little strange that we use index() here instead of strchr(). I think that index() is an archaic, pre-standardization, name for the same thing.

index() does look like it's been deprecated in favor of strchr(). I filed bug 128610 to get rid index() in ObjcRuntimeExtras.h