add facilities to read binary files in the shell

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: gal, Assigned: gal)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 attachment)

(Assignee)

Description

6 years ago
Syntax: snarf(path, "binary") => returns a Uint8Array with the binary data
(Assignee)

Comment 1

6 years ago
Created attachment 530452 [details] [diff] [review]
patch
Assignee: general → gal
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?
Attachment #530452 - Flags: review+
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.
(Assignee)

Comment 4

6 years ago
http://hg.mozilla.org/tracemonkey/rev/e04165ece84c
Whiteboard: fixed-in-tracemonkey
cdleary-bot mozilla-central merge info:
http://hg.mozilla.org/mozilla-central/rev/e04165ece84c
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED

Updated

6 years ago
Blocks: 657891
You need to log in before you can comment on or make changes to this bug.