Last Comment Bug 655168 - add facilities to read binary files in the shell
: add facilities to read binary files in the shell
Status: RESOLVED FIXED
fixed-in-tracemonkey
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: x86 Mac OS X
: -- normal (vote)
: ---
Assigned To: Andreas Gal :gal
:
:
Mentors:
Depends on:
Blocks: 657891
  Show dependency treegraph
 
Reported: 2011-05-05 16:06 PDT by Andreas Gal :gal
Modified: 2011-05-18 02:44 PDT (History)
1 user (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
patch (3.71 KB, patch)
2011-05-05 16:09 PDT, Andreas Gal :gal
cdleary: review+
Details | Diff | Splinter Review

Description Andreas Gal :gal 2011-05-05 16:06:09 PDT
Syntax: snarf(path, "binary") => returns a Uint8Array with the binary data
Comment 1 Andreas Gal :gal 2011-05-05 16:09:27 PDT
Created attachment 530452 [details] [diff] [review]
patch
Comment 2 Chris Leary [:cdleary] (not checking bugmail) 2011-05-05 16:29:33 PDT
Comment on attachment 530452 [details] [diff] [review]
patch

Review of attachment 530452 [details] [diff] [review]:

Yay for shell functionality!

::: js/src/shell/js.cpp
@@ +1168,5 @@
+        return NULL;
+    }
+
+    JSObject *obj = NULL;
+    if (fseek(file, 0, SEEK_END) == EOF) {

Nonzero instead of EOF? C99 spec just says "The fseek function returns nonzero only for a request that cannot be satisfied." for this and ftell.

@@ +4505,5 @@
+        JS_GUARD_OBJECT_NOTIFIER_INIT;
+    }
+
+    ~FreeOnReturn() {
+#ifdef XP_UNIX

FreeOnReturn class that only frees on XP_UNIX should probably be called either XPFreeOnReturn or you should pass an |enable| bool to the constructor that's the value of defined(XP_UNIX).

@@ +4535,5 @@
 #ifdef XP_UNIX
     pathname = MakeAbsolutePathname(cx, script->filename, filename.ptr());
     if (!pathname)
         return JS_FALSE;
+    FreeOnReturn _(cx, pathname);

I think _ is technically an illegal variable name. "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace." pnGuard?
Comment 3 Jeff Walden [:Waldo] (remove +bmo to email) 2011-05-05 17:53:26 PDT
Comment on attachment 530452 [details] [diff] [review]
patch

Review of attachment 530452 [details] [diff] [review]:

::: js/src/shell/js.cpp
@@ +4535,5 @@
 #ifdef XP_UNIX
     pathname = MakeAbsolutePathname(cx, script->filename, filename.ptr());
     if (!pathname)
         return JS_FALSE;
+    FreeOnReturn _(cx, pathname);

"in the global namespace", right?  This is inside a function.  I think it's safe to use here, by that language, if I understand it correctly.
Comment 4 Andreas Gal :gal 2011-05-05 18:01:38 PDT
http://hg.mozilla.org/tracemonkey/rev/e04165ece84c
Comment 5 Chris Leary [:cdleary] (not checking bugmail) 2011-05-10 15:13:09 PDT
cdleary-bot mozilla-central merge info:
http://hg.mozilla.org/mozilla-central/rev/e04165ece84c

Note You need to log in before you can comment on or make changes to this bug.