hey guys,

I wrote a simple patch against the sample shell to add support for the
'shebang' format, so that I can do this:

#!/usr/bin/env v8


here it is:

--- shell.cc.orig       2010-05-14 15:21:28.000000000 -0500
+++ shell.cc    2010-05-14 15:26:54.000000000 -0500
@@ -211,6 +211,13 @@
     i += read;
   }
   fclose(file);
+
+  // allow the first line to be a shebang (by commenting it out).
+  if ((chars[0] == '#') && (chars[1] == '!')) {
+    chars[0] = '/';
+    chars[1] = '/';
+  }
+
   v8::Handle<v8::String> result = v8::String::New(chars, size);
   delete[] chars;
   return result;


here's a test case (this is problem #1 from http://projecteuler.net):

cat > pe1.js < EOF
#!/usr/bin/env v8
var sum = 0;
var i;
for (i = 0; i<1000; i++) {
    if ((i%3==0) || (i%5==0)) {
        sum += i;
    }
}
print(sum);
EOF
chmod +x pe1.js
./pe1.js

-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to