Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created December 1, 2009 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriskowal/246603 to your computer and use it in GitHub Desktop.
Save kriskowal/246603 to your computer and use it in GitHub Desktop.
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
diff --git a/bin/.gitignore b/bin/.gitignore
deleted file mode 100644
index 4761b63..0000000
--- a/bin/.gitignore
+++ /dev/null
@@ -1,12 +0,0 @@
-*
-!activate
-!activate.bash
-!activate.cmd
-!js
-!json
-!narwhal
-!narwhal.cmd
-!sea
-!sea.cmd
-!tusk
-!tusk.cmd
diff --git a/bin/activate.bash b/bin/activate.bash
old mode 100644
new mode 100755
diff --git a/catalog.json b/catalog.json
index 4a33315..80826b5 100644
--- a/catalog.json
+++ b/catalog.json
@@ -938,4 +938,4 @@
"location": "http://github.com/hammerdr/barista/zipball/master"
}
}
-}
\ No newline at end of file
+}
diff --git a/docs/.gitignore b/docs/.gitignore
old mode 100644
new mode 100755
diff --git a/docs/available-packages.md b/docs/available-packages.md
old mode 100644
new mode 100755
diff --git a/docs/browser-api-plan.md b/docs/browser-api-plan.md
old mode 100644
new mode 100755
diff --git a/docs/browser-api.md b/docs/browser-api.md
old mode 100644
new mode 100755
diff --git a/docs/download.md b/docs/download.md
old mode 100644
new mode 100755
diff --git a/docs/engines.md b/docs/engines.md
old mode 100644
new mode 100755
diff --git a/docs/json-tool.md b/docs/json-tool.md
old mode 100644
new mode 100755
diff --git a/docs/lib/binary.wiki b/docs/lib/binary.wiki
old mode 100644
new mode 100755
diff --git a/docs/lib/file.wiki b/docs/lib/file.wiki
old mode 100644
new mode 100755
diff --git a/docs/lib/os/popen.md b/docs/lib/os/popen.md
old mode 100644
new mode 100755
diff --git a/docs/modules.md b/docs/modules.md
old mode 100644
new mode 100755
diff --git a/docs/narwhal.md b/docs/narwhal.md
old mode 100644
new mode 100755
diff --git a/docs/packages-howto.md b/docs/packages-howto.md
old mode 100644
new mode 100755
diff --git a/docs/packages.md b/docs/packages.md
old mode 100644
new mode 100755
diff --git a/docs/posts/2009-07-29-hello-0.1.md b/docs/posts/2009-07-29-hello-0.1.md
old mode 100644
new mode 100755
diff --git a/docs/quick-start.md b/docs/quick-start.md
old mode 100644
new mode 100755
diff --git a/docs/sea.md b/docs/sea.md
old mode 100644
new mode 100755
diff --git a/engines/.gitignore b/engines/.gitignore
new file mode 100644
index 0000000..0f4f491
--- /dev/null
+++ b/engines/.gitignore
@@ -0,0 +1,13 @@
+# Ignore all
+
+/*
+
+# except for
+
+!/.gitignore
+
+!/browser
+!/default
+!/rhino
+!/secure
+!/template
diff --git a/engines/browser/lib/binary.js b/engines/browser/lib/binary.js
old mode 100644
new mode 100755
diff --git a/engines/browser/lib/reactor.js b/engines/browser/lib/reactor.js
old mode 100644
new mode 100755
diff --git a/engines/browser/lib/system.js b/engines/browser/lib/system.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/array.js b/engines/default/lib/array.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/binary-engine.js b/engines/default/lib/binary-engine.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/binary.js b/engines/default/lib/binary.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/date.js b/engines/default/lib/date.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/file-engine.js b/engines/default/lib/file-engine.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/function.js b/engines/default/lib/function.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/global.js b/engines/default/lib/global.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/io-engine.js b/engines/default/lib/io-engine.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/json.js b/engines/default/lib/json.js
old mode 100644
new mode 100755
index c02e8c8..de9d0b2
--- a/engines/default/lib/json.js
+++ b/engines/default/lib/json.js
@@ -157,8 +157,13 @@
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
-
-var JSON = this.JSON = typeof exports == "undefined" ? {} : exports;
+if(global.JSON){
+ exports.parse = JSON.parse;
+ exports.stringify = JSON.stringify;
+}
+else{
+ global.JSON = typeof exports == "undefined" ? {} : exports;
+}
(function () {
diff --git a/engines/default/lib/object.js b/engines/default/lib/object.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/os-engine.js b/engines/default/lib/os-engine.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/reactor.js b/engines/default/lib/reactor.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/string.js b/engines/default/lib/string.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/system.js b/engines/default/lib/system.js
old mode 100644
new mode 100755
diff --git a/engines/default/lib/worker.js b/engines/default/lib/worker.js
index d780910..9e48c6e 100644
--- a/engines/default/lib/worker.js
+++ b/engines/default/lib/worker.js
@@ -22,7 +22,10 @@ function createPort(queue, target, port, global){
target[eventName].apply(target, args);
}
});
- }
+ },
+ hasPendingEvents: function(){
+ return queue.hasPendingEvents();
+ }
};
port.postMessage = function(message){
queue.enqueue(function(){
@@ -39,63 +42,46 @@ function createPort(queue, target, port, global){
}
});
};
- port.isIdle= function(){
- return queue.isEmpty();
- };
return port;
}
-function createWorker(scriptName, setup, workerName){
- var workerQueue,
- workerGlobal = workerEngine.createEnvironment();
+var createEnvironment = exports.createEnvironment = function(){
+ var workerGlobal = workerEngine.createEnvironment();
// add the module lookup paths from our environment
var paths = workerGlobal.require.paths;
paths.splice(0, paths.length);
paths.push.apply(paths, require.paths);
+ // there must be one and only one shared worker map amongst all workers
+ workerGlobal.require("system").__sharedWorkers__ = system.__sharedWorkers__;
+
+ return workerGlobal;
+};
+function createWorker(scriptName, setup, workerName){
+ var workerQueue,
+ workerGlobal = createEnvironment();
+
+ var sandbox = workerGlobal.require("sandbox").Sandbox({
+ "system": workerGlobal.system,
+ "loader": workerGlobal.require.loader,
+ "debug": workerGlobal.require.loader.debug
+ });
// get the event queue
- workerQueue = workerGlobal.require("event-queue");
+ workerQueue = sandbox("event-queue");
// calback for dedicated and shared workers to do their thing
var worker = setup(workerQueue, workerGlobal);
- // there must be one and only one shared worker map amongst all workers
- workerGlobal.require("system").__sharedWorkers__ = system.__sharedWorkers__;
-
workerEngine.spawn(function(){
- workerGlobal.require(scriptName);
+ sandbox.main(scriptName);
// enter the event loop
- while(true){
- try{
- workerQueue.nextEvent()();
- if(workerQueue.isEmpty()){
- // fire onidle events when empty, this allows to do effective worker pooling
- queue.enqueue(function(){
- if(worker && worker.onidle){
- worker.onidle();
- }
- });
- }
- }catch(e){
- workerQueue.enqueue(function(){
- if(typeof workerGlobal.onerror === "function"){
- // trigger the onerror event in the worker if an error occurs
- try{
- workerGlobal.onerror(e);
- }
- catch(e){
- // don't want an error here to go into an infinite loop!
- workerEngine.defaultErrorReporter(e);
- }
- }
- else{
- workerEngine.defaultErrorReporter(e);
- }
- });
-
-
- }
- }
+ workerQueue.enterEventLoop(function(){
+ queue.enqueue(function(){
+ if(worker && worker.onidle){
+ worker.onidle();
+ }
+ });
+ });
}, workerName || scriptName);
};
diff --git a/engines/rhino/bootstrap.js b/engines/rhino/bootstrap.js
old mode 100644
new mode 100755
index 40974b1..5699f1e
--- a/engines/rhino/bootstrap.js
+++ b/engines/rhino/bootstrap.js
@@ -10,11 +10,14 @@
/* this gets used for several fixtures */
var context = Packages.org.mozilla.javascript.Context.getCurrentContext();
- context.getWrapFactory().setJavaPrimitiveWrap(false);
// TODO: enable this via a command line switch
context.setOptimizationLevel(-1);
+
+ context.setLanguageVersion(180);
+ context.getWrapFactory().setJavaPrimitiveWrap(false);
+
var prefix = "";
if (typeof NARWHAL_HOME != "undefined") {
prefix = NARWHAL_HOME;
diff --git a/engines/rhino/jars/jline.jar b/engines/rhino/jars/jline.jar
old mode 100644
new mode 100755
diff --git a/engines/rhino/jars/jna.jar b/engines/rhino/jars/jna.jar
old mode 100644
new mode 100755
diff --git a/engines/rhino/jars/js.jar b/engines/rhino/jars/js.jar
old mode 100644
new mode 100755
index 51f7a8b..0590c96
Binary files a/engines/rhino/jars/js.jar and b/engines/rhino/jars/js.jar differ
diff --git a/engines/rhino/lib/binary-engine.js b/engines/rhino/lib/binary-engine.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/event-queue.js b/engines/rhino/lib/event-queue.js
index 2fdc1f7..372891d 100644
--- a/engines/rhino/lib/event-queue.js
+++ b/engines/rhino/lib/event-queue.js
@@ -1,18 +1,81 @@
/**
* Represents the event queue for a vat
+* The API is modeled after https://developer.mozilla.org/en/nsIThread
*/
// we could eventually upgrade to PriorityBlockingQueye with FIFOEntry tie breaking
-var queue = new java.util.concurrent.LinkedBlockingQueue();
+var shuttingDown,
+ queue = new java.util.concurrent.LinkedBlockingQueue();
+
-exports.nextEvent = function(){
+exports.getNextEvent = function(){
return queue.take();
};
+exports.processNextEvent = function(mayWait){
+ if(!mayWait && queue.isEmpty()){
+ return false;
+ }
+ try{
+ queue.take()();
+ }catch(e){
+ exports.enqueue(function(){
+ if(typeof onerror === "function"){
+ // trigger the onerror event in the worker if an error occurs
+ try{
+ onerror(e);
+ }
+ catch(e){
+ // don't want an error here to go into an infinite loop!
+ exports.defaultErrorReporter(e);
+ }
+ }
+ else{
+ exports.defaultErrorReporter(e);
+ }
+ });
+
+
+ }
+ return true;
+};
+
+exports.enterEventLoop = function(onidle){
+ while(true){
+ exports.processNextEvent(true);
+
+ if(queue.isEmpty()){
+ if(shuttingDown){
+ return;
+ }
+ // fire onidle events if a callback is provided
+ if(onidle){
+ onidle();
+ }
+ }
+ }
+
+};
+
exports.enqueue = function(task, priority){
- queue.put(task); // priority is ignored for now until PriorityBlockingQueue is used
+ if(!shuttingDown){
+ queue.put(task); // priority is ignored for now until PriorityBlockingQueue is used
+ }
+};
+
+exports.hasPendingEvents = function(){
+ return !queue.isEmpty();
+}
+
+exports.shutdown = function(){
+ shuttingDown = true;
+ if(queue.isEmpty()){
+ // if it is empty we need to kick start the event loop to make sure we get into the
+ // the check for shuttingDown
+ exports.enqueue(function(){});
+ }
};
-exports.isEmpty = function(){
- return queue.isEmpty();
-}
\ No newline at end of file
+exports.defaultErrorReporter = function(e){
+ print((e.rhinoException && e.rhinoException.printStackTrace()) || (e.name + ": " + e.message));
+};
\ No newline at end of file
diff --git a/engines/rhino/lib/file-engine.js b/engines/rhino/lib/file-engine.js
old mode 100644
new mode 100755
index e0d8a26..6455a5e
--- a/engines/rhino/lib/file-engine.js
+++ b/engines/rhino/lib/file-engine.js
@@ -97,6 +97,10 @@ exports.isAbsolute = function (path) {
/* see: http://www.idiom.com/~zilla/Xfiles/javasymlinks.html */
exports.isLink = function (path) {
+ if(java.io.File.separator == "\\"){
+ // these file separators result in different canonical vs absolute for non-links, and windows doesn't have symlinks anyway
+ return false;
+ }
path = exports.path(path);
var canonical = path.canonical().toString();
var absolute = path.absolute().toString();
diff --git a/engines/rhino/lib/http-engine.js b/engines/rhino/lib/http-engine.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/io-engine.js b/engines/rhino/lib/io-engine.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/md5-engine.js b/engines/rhino/lib/md5-engine.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/os-engine.js b/engines/rhino/lib/os-engine.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/packages-engine.js b/engines/rhino/lib/packages-engine.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/sandbox-engine.js b/engines/rhino/lib/sandbox-engine.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/system.js b/engines/rhino/lib/system.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/lib/uuid.js b/engines/rhino/lib/uuid.js
new file mode 100644
index 0000000..54f5742
--- /dev/null
+++ b/engines/rhino/lib/uuid.js
@@ -0,0 +1,3 @@
+exports.randomUUID = function(){
+ return java.util.UUID.randomUUID().toString()
+};
\ No newline at end of file
diff --git a/engines/rhino/lib/worker-engine.js b/engines/rhino/lib/worker-engine.js
index 0dcacb3..efc316e 100644
--- a/engines/rhino/lib/worker-engine.js
+++ b/engines/rhino/lib/worker-engine.js
@@ -11,13 +11,20 @@ exports.createEnvironment = function(){
org.mozilla.javascript.Context.enter(),
workerGlobal,
bootstrapPath);
+
return workerGlobal;
};
exports.spawn = function(functionToRun, threadName){
- (new java.lang.Thread(functionToRun, threadName)).start();
+ (new java.lang.Thread(function(){
+ var context = Packages.org.mozilla.javascript.Context.getCurrentContext();
+ // TODO: this needs call something that will do the context/thread preparation
+ context.setOptimizationLevel(-1);
+
+ context.setLanguageVersion(180);
+ context.getWrapFactory().setJavaPrimitiveWrap(false);
+
+ functionToRun();
+ }, threadName)).start();
};
-exports.defaultErrorReporter = function(e){
- print((e.rhinoException && e.rhinoException.printStackTrace()) || (e.name + ": " + e.message));
-};
\ No newline at end of file
diff --git a/engines/rhino/lib/zip.js b/engines/rhino/lib/zip.js
old mode 100644
new mode 100755
diff --git a/engines/rhino/package.json b/engines/rhino/package.json
old mode 100644
new mode 100755
diff --git a/engines/secure/lib/file.js b/engines/secure/lib/file.js
old mode 100644
new mode 100755
diff --git a/engines/secure/lib/system.js b/engines/secure/lib/system.js
old mode 100644
new mode 100755
diff --git a/engines/template/bootstrap.js b/engines/template/bootstrap.js
old mode 100644
new mode 100755
diff --git a/engines/template/lib/file-engine.js b/engines/template/lib/file-engine.js
old mode 100644
new mode 100755
diff --git a/engines/template/lib/system.js b/engines/template/lib/system.js
old mode 100644
new mode 100755
diff --git a/examples/not-quite-a-quine.js b/examples/not-quite-a-quine.js
old mode 100644
new mode 100755
diff --git a/lib/args.js b/lib/args.js
old mode 100644
new mode 100755
diff --git a/lib/base16.js b/lib/base16.js
old mode 100644
new mode 100755
diff --git a/lib/base64.js b/lib/base64.js
old mode 100644
new mode 100755
diff --git a/lib/codec/base64.js b/lib/codec/base64.js
old mode 100644
new mode 100755
diff --git a/lib/crc32.js b/lib/crc32.js
old mode 100644
new mode 100755
diff --git a/lib/file-bootstrap.js b/lib/file-bootstrap.js
old mode 100644
new mode 100755
diff --git a/lib/file.js b/lib/file.js
old mode 100644
new mode 100755
diff --git a/lib/hash.js b/lib/hash.js
old mode 100644
new mode 100755
diff --git a/lib/hashp.js b/lib/hashp.js
old mode 100644
new mode 100755
diff --git a/lib/http.js b/lib/http.js
old mode 100644
new mode 100755
diff --git a/lib/io.js b/lib/io.js
old mode 100644
new mode 100755
diff --git a/lib/jsmin.js b/lib/jsmin.js
old mode 100644
new mode 100755
diff --git a/lib/jsonpath.js b/lib/jsonpath.js
old mode 100644
new mode 100755
diff --git a/lib/logger.js b/lib/logger.js
old mode 100644
new mode 100755
diff --git a/lib/md4.js b/lib/md4.js
old mode 100644
new mode 100755
diff --git a/lib/md5.js b/lib/md5.js
old mode 100644
new mode 100755
diff --git a/lib/mime.js b/lib/mime.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal.js b/lib/narwhal.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/client.js b/lib/narwhal/client.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/env.js b/lib/narwhal/env.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/inline.js b/lib/narwhal/inline.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/json.js b/lib/narwhal/json.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/json.md b/lib/narwhal/json.md
old mode 100644
new mode 100755
diff --git a/lib/narwhal/repl-worker.js b/lib/narwhal/repl-worker.js
new file mode 100644
index 0000000..41aa9ff
--- /dev/null
+++ b/lib/narwhal/repl-worker.js
@@ -0,0 +1,84 @@
+var system = require("system");
+
+try { var readline = require("readline").readline; } catch (e) {}
+try { var Narcissus = require("narcissus/parse"); } catch (e) {}
+
+var util = require('util'),
+ queue = require("event-queue");
+
+var PROMPT_NORMAL = "js> ",
+ PROMPT_INCOMPLETE = " > "
+
+var buffer = "";
+
+function readln(input) {
+ while (!(/\n/).test(buffer))
+ buffer += input.read(100).toString();
+
+ var lines = buffer.split("\n"),
+ line = lines.shift();
+
+ buffer = lines.join("\n");
+
+ return line
+}
+global.onconnect = function (e) {
+ global.onconnect = null; // only connect to one worker
+
+ var buffer = "",
+ bufferedLines = [],
+ pendingLines = [];
+
+ system.stdout.write(PROMPT_NORMAL);
+ system.stdout.flush();
+
+ while (true) {
+ var line = readline ? readline() : system.stdin.readLine();
+ if (!line) {
+ system.stdout.write("\n");
+ system.stdout.flush();
+ break;
+ }
+
+ line = util.trimEnd(line);
+ var text = pendingLines.join("\n") + "\n" + line;
+ if (line == "" || !incomplete(text)) {
+
+ pendingLines = [];
+ e.port.postMessage(text);
+ queue.processNextEvent(true);// wait for it to be processed before showing the next prompt
+
+ } else
+ pendingLines.push(line);
+
+ if (pendingLines.length > 0)
+ system.stdout.write(PROMPT_INCOMPLETE);
+ else
+ system.stdout.write(PROMPT_NORMAL);
+ system.stdout.flush();
+
+ }
+}
+
+function incomplete(text) {
+ if (!Narcissus)
+ return false;
+
+ var incomp = true;
+ try {
+ var t = new Narcissus.Tokenizer(text);
+ var x = new Narcissus.CompilerContext(false);
+ var n = Narcissus.Script(t, x);
+ incomp = !t.done;
+ } catch (e) {
+ if (!t.done) {
+ print(e);
+ return false;
+ }
+ }
+ return incomp;
+}
+
+
+
+
diff --git a/lib/narwhal/repl.js b/lib/narwhal/repl.js
old mode 100644
new mode 100755
index 396504b..ecd49c1
--- a/lib/narwhal/repl.js
+++ b/lib/narwhal/repl.js
@@ -1,95 +1,36 @@
-
-var system = require("system");
-
-try { var readline = require("readline").readline; } catch (e) {}
-try { var Narcissus = require("narcissus/parse"); } catch (e) {}
-
-var util = require('util');
-
-var PROMPT_NORMAL = "js> ",
- PROMPT_INCOMPLETE = " > "
-
-var buffer = "";
-function readln(input) {
- while (!(/\n/).test(buffer))
- buffer += input.read(100).toString();
-
- var lines = buffer.split("\n"),
- line = lines.shift();
-
- buffer = lines.join("\n");
-
- return line
-}
-
-exports.repl = function() {
-
- var buffer = "",
- bufferedLines = [],
- pendingLines = [];
-
- system.stdout.write(PROMPT_NORMAL);
- system.stdout.flush();
-
- while (true) {
-
- var line = readline ? readline() : system.stdin.readLine();
- if (!line) {
- system.stdout.write("\n");
+var system = require("system"),
+ util = require('util'),
+ SharedWorker = require("worker").SharedWorker,
+ queue = require("event-queue");
+
+var replEval = eval;
+exports.repl = function(dontEnterEventLoop) {
+ var replWorker = new SharedWorker("narwhal/repl-worker", "repl-worker");
+ // the worker receives the input from the users and posts the inputs back to us
+ replWorker.port.onmessage = function(message){
+ // got a command from the console
+ try {
+ var result = replEval(message.data);
+ var repr = util.repr(result);
+ if (repr.length > 76 || /\n/.test(repr))
+ repr = String(result);
+ if (!util.no(result)) {
+ system.stdout.write(repr + '\n');
+ system.stdout.flush();
+ global._ = result;
+ }
+
+ } catch (e) {
+ system.stdout.write(" exception from uncaught JavaScript throw: " + e + "\n");
system.stdout.flush();
- break;
- }
-
- line = util.trimEnd(line);
- var text = pendingLines.join("\n") + "\n" + line;
- if (line == "" || !incomplete(text)) {
-
- pendingLines = [];
-
- try {
- var result = system.evalGlobal(text);
- var repr = util.repr(result);
- if (repr.length > 76 || /\n/.test(repr))
- repr = String(result);
- if (!util.no(result)) {
- system.stdout.write(repr + '\n');
- system.stdout.flush();
- global._ = result;
- }
- } catch (e) {
- system.stdout.write(" exception from uncaught JavaScript throw: " + e + "\n");
- }
-
- } else
- pendingLines.push(line);
-
- if (pendingLines.length > 0)
- system.stdout.write(PROMPT_INCOMPLETE);
- else
- system.stdout.write(PROMPT_NORMAL);
- system.stdout.flush();
-
- }
-}
-
-function incomplete(text) {
- if (!Narcissus)
- return false;
-
- var incomp = true;
- try {
- var t = new Narcissus.Tokenizer(text);
- var x = new Narcissus.CompilerContext(false);
- var n = Narcissus.Script(t, x);
- incomp = !t.done;
- } catch (e) {
- if (!t.done) {
- print(e);
- return false;
- }
- }
- return incomp;
-}
+ }
+ replWorker.port.postMessage(""); // just signal we are done displaying the result
+ };
+ if(!dontEnterEventLoop){
+ // now enter the event loop
+ queue.enterEventLoop();
+ }
+};
if (module.id == require.main)
exports.repl();
diff --git a/lib/narwhal/server-test.js b/lib/narwhal/server-test.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/server.js b/lib/narwhal/server.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk.js b/lib/narwhal/tusk.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/bin.js b/lib/narwhal/tusk/bin.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/bundle.js b/lib/narwhal/tusk/bundle.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/catalog.js b/lib/narwhal/tusk/catalog.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/clone.js b/lib/narwhal/tusk/clone.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/consolidate.js b/lib/narwhal/tusk/consolidate.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/create-catalog.js b/lib/narwhal/tusk/create-catalog.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/engine.js b/lib/narwhal/tusk/engine.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/freeze.js b/lib/narwhal/tusk/freeze.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/init.js b/lib/narwhal/tusk/init.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/install.js b/lib/narwhal/tusk/install.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/list.js b/lib/narwhal/tusk/list.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/orphans.js b/lib/narwhal/tusk/orphans.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/reheat.js b/lib/narwhal/tusk/reheat.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/remove.js b/lib/narwhal/tusk/remove.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/search.js b/lib/narwhal/tusk/search.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/update.js b/lib/narwhal/tusk/update.js
old mode 100644
new mode 100755
diff --git a/lib/narwhal/tusk/upgrade.js b/lib/narwhal/tusk/upgrade.js
old mode 100644
new mode 100755
diff --git a/lib/os.js b/lib/os.js
old mode 100644
new mode 100755
diff --git a/lib/packages.js b/lib/packages.js
old mode 100644
new mode 100755
diff --git a/lib/printf.js b/lib/printf.js
old mode 100644
new mode 100755
diff --git a/lib/promise.js b/lib/promise.js
old mode 100644
new mode 100755
index 1e31cd4..d8695ef
--- a/lib/promise.js
+++ b/lib/promise.js
@@ -333,11 +333,7 @@ exports.wait = function(target){
result = error;
});
while(!isFinished){
- try{
- queue.nextEvent()();
- }catch(e){
- print(e);
- }
+ queue.processNextEvent(true);
}
if(isError){
throw result;
diff --git a/lib/querystring.js b/lib/querystring.js
old mode 100644
new mode 100755
diff --git a/lib/regexp.js b/lib/regexp.js
old mode 100644
new mode 100755
diff --git a/lib/sandbox.js b/lib/sandbox.js
old mode 100644
new mode 100755
index fca58fe..6d54bb2
--- a/lib/sandbox.js
+++ b/lib/sandbox.js
@@ -209,6 +209,7 @@ exports.Sandbox = function (options) {
var sandbox = function (id, baseId, force, reload) {
id = loader.resolve(id, baseId);
+ id = id.replace(/\\/g,'/'); // module ids need to use forward slashes, despite what the OS might say
/* populate memo with module instance */
if (!Object.prototype.hasOwnProperty.call(modules, id) || force) {
@@ -266,15 +267,13 @@ exports.Sandbox = function (options) {
var exports = modules[id];
var imports = {};
var importsUsed = false;
- var curryUsed = false;
for (var name in exports) {
- curryUsed = (
+ var curryUsed = (
typeof exports[name] == "function" &&
// if it is Java class this will throw an exception, which is terribly annoying during debugging
Object.prototype.toString.call(exports[name]) != "[object JavaClass]" &&
exports[name].xNarwhalCurryId
);
-
if (curryUsed) {
importsUsed = true;
imports[name] = (function (callback) {
diff --git a/lib/sha.js b/lib/sha.js
old mode 100644
new mode 100755
diff --git a/lib/sha256.js b/lib/sha256.js
old mode 100644
new mode 100755
diff --git a/lib/struct.js b/lib/struct.js
old mode 100644
new mode 100755
diff --git a/lib/term.js b/lib/term.js
old mode 100644
new mode 100755
diff --git a/lib/test/assert.js b/lib/test/assert.js
old mode 100644
new mode 100755
diff --git a/lib/test/equiv.js b/lib/test/equiv.js
old mode 100644
new mode 100755
diff --git a/lib/test/jsdump.js b/lib/test/jsdump.js
old mode 100644
new mode 100755
diff --git a/lib/test/runner.js b/lib/test/runner.js
old mode 100644
new mode 100755
diff --git a/lib/unload.js b/lib/unload.js
old mode 100644
new mode 100755
diff --git a/lib/uri.js b/lib/uri.js
old mode 100644
new mode 100755
diff --git a/lib/url.js b/lib/url.js
old mode 100644
new mode 100755
diff --git a/lib/utf8.js b/lib/utf8.js
old mode 100644
new mode 100755
diff --git a/lib/util.js b/lib/util.js
old mode 100644
new mode 100755
diff --git a/lib/xregexp.js b/lib/xregexp.js
old mode 100644
new mode 100755
diff --git a/local.json.template b/local.json.template
old mode 100644
new mode 100755
diff --git a/narwhal.conf.template b/narwhal.conf.template
old mode 100644
new mode 100755
diff --git a/narwhal.gemspec b/narwhal.gemspec
old mode 100644
new mode 100755
diff --git a/narwhal.js b/narwhal.js
old mode 100644
new mode 100755
diff --git a/package.json b/package.json
old mode 100644
new mode 100755
diff --git a/packages/.gitignore b/packages/.gitignore
index 6d0eebc..54b2eda 100644
--- a/packages/.gitignore
+++ b/packages/.gitignore
@@ -1,10 +1,9 @@
-!.gitignore
-!narwhal-helma
-!narwhal-jaxer
-!narwhal-test
-!narwhal-k7
-!narwhal-v8cgi
-!narwhal-xulrunner
-# only ignore other directories in this directory
-# (does not ignore files within checked-in directories)
+# Ignore all
+
/*
+
+# except for
+
+!/.gitignore
+
+!/readline
diff --git a/packages/readline/engines/default/lib/readline.js b/packages/readline/engines/default/lib/readline.js
old mode 100644
new mode 100755
diff --git a/packages/readline/engines/rhino/lib/readline.js b/packages/readline/engines/rhino/lib/readline.js
old mode 100644
new mode 100755
index e1838ce..38a530e
--- a/packages/readline/engines/rhino/lib/readline.js
+++ b/packages/readline/engines/rhino/lib/readline.js
@@ -1,6 +1,19 @@
-
-var reader = new Packages.jline.ConsoleReader();
+// use the Rhino shell, in case stdin is coming from the debugger GUI (this will still use jline)
+var reader = new java.io.BufferedReader(
+ new java.io.InputStreamReader(
+ new org.mozilla.javascript.NativeJavaObject(
+ global, org.mozilla.javascript.tools.shell.Main.global, null).
+ getIn(), "UTF-8"));
exports.readline = function() {
- return String(reader.readLine());
+ var line = reader.readLine();
+ if(line === null){
+ // jline will fail in eclipse, revert to the default impl
+ exports.readline = function(){
+ return system.stdin.readLine();
+ };
+ return exports.readline();
+ }
+
+ return String(line);
}
diff --git a/packages/readline/package.json b/packages/readline/package.json
old mode 100644
new mode 100755
diff --git a/tests/all-tests.js b/tests/all-tests.js
old mode 100644
new mode 100755
diff --git a/tests/args.js b/tests/args.js
old mode 100644
new mode 100755
diff --git a/tests/args/domain.js b/tests/args/domain.js
old mode 100644
new mode 100755
diff --git a/tests/args/options.js b/tests/args/options.js
old mode 100644
new mode 100755
diff --git a/tests/args/shifting.js b/tests/args/shifting.js
old mode 100644
new mode 100755
diff --git a/tests/args/validation.js b/tests/args/validation.js
old mode 100644
new mode 100755
diff --git a/tests/base64.js b/tests/base64.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs.js b/tests/commonjs.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/all-tests.js b/tests/commonjs/all-tests.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/bytearray-encodings-tests.js b/tests/commonjs/bytearray-encodings-tests.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/bytearray-tests.js b/tests/commonjs/bytearray-tests.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/bytestring-encodings-tests.js b/tests/commonjs/bytestring-encodings-tests.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/bytestring-tests.js b/tests/commonjs/bytestring-tests.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file-tests.js b/tests/commonjs/file-tests.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file/dirname.js b/tests/commonjs/file/dirname.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file/extension.js b/tests/commonjs/file/extension.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file/is-absolute.js b/tests/commonjs/file/is-absolute.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file/iterator.js b/tests/commonjs/file/iterator.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file/normal.js b/tests/commonjs/file/normal.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file/relative.js b/tests/commonjs/file/relative.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/file/resolve.js b/tests/commonjs/file/resolve.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/module-tests.js b/tests/commonjs/module-tests.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/absolute/b.js b/tests/commonjs/modules/absolute/b.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/absolute/program.js b/tests/commonjs/modules/absolute/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/absolute/submodule/a.js b/tests/commonjs/modules/absolute/submodule/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/absolute/test.js b/tests/commonjs/modules/absolute/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/config.js b/tests/commonjs/modules/config.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/cyclic/a.js b/tests/commonjs/modules/cyclic/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/cyclic/b.js b/tests/commonjs/modules/cyclic/b.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/cyclic/program.js b/tests/commonjs/modules/cyclic/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/cyclic/test.js b/tests/commonjs/modules/cyclic/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/determinism/program.js b/tests/commonjs/modules/determinism/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/determinism/submodule/a.js b/tests/commonjs/modules/determinism/submodule/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/determinism/submodule/b.js b/tests/commonjs/modules/determinism/submodule/b.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/determinism/test.js b/tests/commonjs/modules/determinism/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/exactExports/a.js b/tests/commonjs/modules/exactExports/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/exactExports/program.js b/tests/commonjs/modules/exactExports/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/exactExports/test.js b/tests/commonjs/modules/exactExports/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js b/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/hasOwnProperty/program.js b/tests/commonjs/modules/hasOwnProperty/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/hasOwnProperty/test.js b/tests/commonjs/modules/hasOwnProperty/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/hasOwnProperty/toString.js b/tests/commonjs/modules/hasOwnProperty/toString.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/method/a.js b/tests/commonjs/modules/method/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/method/program.js b/tests/commonjs/modules/method/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/method/test.js b/tests/commonjs/modules/method/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/missing/program.js b/tests/commonjs/modules/missing/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/missing/test.js b/tests/commonjs/modules/missing/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/monkeys/a.js b/tests/commonjs/modules/monkeys/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/monkeys/program.js b/tests/commonjs/modules/monkeys/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/monkeys/test.js b/tests/commonjs/modules/monkeys/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/nested/a/b/c/d.js b/tests/commonjs/modules/nested/a/b/c/d.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/nested/program.js b/tests/commonjs/modules/nested/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/nested/test.js b/tests/commonjs/modules/nested/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/relative/program.js b/tests/commonjs/modules/relative/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/relative/submodule/a.js b/tests/commonjs/modules/relative/submodule/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/relative/submodule/b.js b/tests/commonjs/modules/relative/submodule/b.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/relative/test.js b/tests/commonjs/modules/relative/test.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/transitive/a.js b/tests/commonjs/modules/transitive/a.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/transitive/b.js b/tests/commonjs/modules/transitive/b.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/transitive/c.js b/tests/commonjs/modules/transitive/c.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/transitive/program.js b/tests/commonjs/modules/transitive/program.js
old mode 100644
new mode 100755
diff --git a/tests/commonjs/modules/transitive/test.js b/tests/commonjs/modules/transitive/test.js
old mode 100644
new mode 100755
diff --git a/tests/file/all-tests.js b/tests/file/all-tests.js
old mode 100644
new mode 100755
diff --git a/tests/file/glob.js b/tests/file/glob.js
index a808594..43775c6 100644
--- a/tests/file/glob.js
+++ b/tests/file/glob.js
@@ -463,4 +463,3 @@ exports["tests '**/*.ext'"] = function() {
if (require.main === module.id)
require("os").exit(require("test/runner").run(exports));
-
diff --git a/tests/file/match.js b/tests/file/match.js
old mode 100644
new mode 100755
diff --git a/tests/global.js b/tests/global.js
old mode 100644
new mode 100755
diff --git a/tests/global/array.js b/tests/global/array.js
old mode 100644
new mode 100755
diff --git a/tests/hashes.js b/tests/hashes.js
old mode 100644
new mode 100755
diff --git a/tests/io/stringio.js b/tests/io/stringio.js
old mode 100644
new mode 100755
diff --git a/tests/os/all-tests.js b/tests/os/all-tests.js
old mode 100644
new mode 100755
diff --git a/tests/os/popen.js b/tests/os/popen.js
old mode 100644
new mode 100755
diff --git a/tests/printf.js b/tests/printf.js
old mode 100644
new mode 100755
diff --git a/tests/sandbox/byte-io.js b/tests/sandbox/byte-io.js
old mode 100644
new mode 100755
diff --git a/tests/sandbox/fileName.js b/tests/sandbox/fileName.js
old mode 100644
new mode 100755
diff --git a/tests/sandbox/foo.js b/tests/sandbox/foo.js
old mode 100644
new mode 100755
diff --git a/tests/sandbox/reload.js b/tests/sandbox/reload.js
old mode 100644
new mode 100755
diff --git a/tests/string.js b/tests/string.js
old mode 100644
new mode 100755
diff --git a/tests/uri.js b/tests/uri.js
old mode 100644
new mode 100755
diff --git a/tests/util/all-tests.js b/tests/util/all-tests.js
old mode 100644
new mode 100755
diff --git a/tests/util/array.js b/tests/util/array.js
old mode 100644
new mode 100755
diff --git a/tests/util/array/is-arguments.js b/tests/util/array/is-arguments.js
old mode 100644
new mode 100755
diff --git a/tests/util/array/is-array-like.js b/tests/util/array/is-array-like.js
old mode 100644
new mode 100755
diff --git a/tests/util/case.js b/tests/util/case.js
old mode 100644
new mode 100755
diff --git a/tests/util/collection.js b/tests/util/collection.js
old mode 100644
new mode 100755
diff --git a/tests/util/eq.js b/tests/util/eq.js
old mode 100644
new mode 100755
diff --git a/tests/util/expand.js b/tests/util/expand.js
old mode 100644
new mode 100755
diff --git a/tests/util/object.js b/tests/util/object.js
old mode 100644
new mode 100755
diff --git a/tests/util/operator.js b/tests/util/operator.js
old mode 100644
new mode 100755
diff --git a/tests/util/repr.js b/tests/util/repr.js
old mode 100644
new mode 100755
diff --git a/tests/util/string.js b/tests/util/string.js
old mode 100644
new mode 100755
diff --git a/tests/util/unique.js b/tests/util/unique.js
old mode 100644
new mode 100755
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment