Bug 127486

Summary: jsc-cli should allow scripts to access argv
Product: WebKit Reporter: Mark Hahnenberg <mhahnenberg>
Component: JavaScriptCoreAssignee: Mark Hahnenberg <mhahnenberg>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 127432    
Attachments:
Description Flags
Patch oliver: review+

Description Mark Hahnenberg 2014-01-23 08:43:24 PST
One of the fundamental things command line scripts want to do is access their command line arguments. One way to do this would be to expose a global ARGV array containing each argument passed the script.
Comment 1 Mark Hahnenberg 2014-02-14 09:37:44 PST
Created attachment 224227 [details]
Patch
Comment 2 Oliver Hunt 2014-02-14 10:04:45 PST
Comment on attachment 224227 [details]
Patch

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

> Tools/jsc-cli/jsc-cli.xcodeproj/project.pbxproj:8
> -   classes = {
> -   };
> -   objectVersion = 46;
> -   objects = {
> +	archiveVersion = 1;
> +	classes = {
> +	};
> +	objectVersion = 46;
> +	objects = {
>  

Goddammit Xcode :)
Comment 3 Mark Hahnenberg 2014-02-14 10:08:54 PST
(In reply to comment #2)
> (From update of attachment 224227 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=224227&action=review
> 
> > Tools/jsc-cli/jsc-cli.xcodeproj/project.pbxproj:8
> > -   classes = {
> > -   };
> > -   objectVersion = 46;
> > -   objects = {
> > +	archiveVersion = 1;
> > +	classes = {
> > +	};
> > +	objectVersion = 46;
> > +	objects = {
> >  
> 
> Goddammit Xcode :)

Yeah, I dunno what's going on there lol.
Comment 4 Mark Hahnenberg 2014-02-14 14:12:50 PST
Comment on attachment 224227 [details]
Patch

Commit queue looks like it's having a bad time, so I'll land manually.
Comment 5 Mark Hahnenberg 2014-02-14 14:23:30 PST
Committed r164134: <http://trac.webkit.org/changeset/164134>
Comment 6 Joseph Pecoraro 2014-02-14 14:32:20 PST
Comment on attachment 224227 [details]
Patch

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

> Tools/jsc-cli/jsc-cli/CLIInstance.m:75
> +    [_context[@"ARGV"] setValue:(_baseFile ? _baseFile : @"") atIndex:0];

Nit: You could pull _context[@"ARGV"] out into a local instead of potentially calling it a bunch of times in a loop. I don't think ObjC has any support for optimizing away repeated calls like this. Of course performance right here is not important, but this is a good idiom to get used to for ObjC.
Comment 7 Mark Hahnenberg 2014-02-14 14:33:55 PST
(In reply to comment #6)
> (From update of attachment 224227 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=224227&action=review
> 
> > Tools/jsc-cli/jsc-cli/CLIInstance.m:75
> > +    [_context[@"ARGV"] setValue:(_baseFile ? _baseFile : @"") atIndex:0];
> 
> Nit: You could pull _context[@"ARGV"] out into a local instead of potentially calling it a bunch of times in a loop. I don't think ObjC has any support for optimizing away repeated calls like this. Of course performance right here is not important, but this is a good idiom to get used to for ObjC.

Yeah, that's definitely a good idea. Not only does Obj-C not do a good job optimizing this, but these lookups aren't exactly cheap in the JSC API.