sproutit-narwhal 0.1.106
Sign up to get free protection for your applications and to get access to all the features.
- data/DISTRIBUTION.yml +15 -0
- data/README.md +86 -0
- data/Rakefile +349 -0
- data/VERSION.yml +7 -0
- data/bin/activate +50 -0
- data/bin/activate.bash +50 -0
- data/bin/activate.cmd +3 -0
- data/bin/js +67 -0
- data/bin/json +2 -0
- data/bin/narwhal +67 -0
- data/bin/narwhal.cmd +29 -0
- data/bin/sea +45 -0
- data/bin/sea.cmd +25 -0
- data/bin/tusk +2 -0
- data/bin/tusk.cmd +5 -0
- data/catalog.json +902 -0
- data/docs/available-packages.md +32 -0
- data/docs/browser-api-plan.md +290 -0
- data/docs/browser-api.md +153 -0
- data/docs/download.md +25 -0
- data/docs/engines.md +32 -0
- data/docs/json-tool.md +121 -0
- data/docs/lib/binary.wiki +242 -0
- data/docs/lib/file.wiki +325 -0
- data/docs/lib/os/popen.md +70 -0
- data/docs/modules.md +38 -0
- data/docs/narwhal.md +487 -0
- data/docs/packages-howto.md +32 -0
- data/docs/packages.md +30 -0
- data/docs/posts/2009-07-29-hello-0.1.md +19 -0
- data/docs/quick-start.md +69 -0
- data/docs/sea.md +49 -0
- data/engines/browser/lib/binary.js +2 -0
- data/engines/browser/lib/reactor.js +21 -0
- data/engines/browser/lib/system.js +3 -0
- data/engines/default/lib/array.js +164 -0
- data/engines/default/lib/binary-engine.js +53 -0
- data/engines/default/lib/binary.js +755 -0
- data/engines/default/lib/date.js +8 -0
- data/engines/default/lib/file-engine.js +119 -0
- data/engines/default/lib/function.js +119 -0
- data/engines/default/lib/global.js +11 -0
- data/engines/default/lib/io-engine.js +26 -0
- data/engines/default/lib/json.js +488 -0
- data/engines/default/lib/object.js +69 -0
- data/engines/default/lib/os-engine.js +3 -0
- data/engines/default/lib/reactor.js +12 -0
- data/engines/default/lib/string.js +84 -0
- data/engines/default/lib/system.js +20 -0
- data/engines/default/lib/worker.js +133 -0
- data/engines/jsc/README.md +18 -0
- data/engines/jsc/bootstrap.js +53 -0
- data/engines/jsc/deps/http-parser/LICENSE +77 -0
- data/engines/jsc/deps/http-parser/README.md +145 -0
- data/engines/jsc/deps/http-parser/http_parser.c +6087 -0
- data/engines/jsc/deps/http-parser/http_parser.h +141 -0
- data/engines/jsc/deps/http-parser/http_parser.rl +500 -0
- data/engines/jsc/deps/http-parser/test.c +858 -0
- data/engines/jsc/include/binary-engine.h +11 -0
- data/engines/jsc/include/io-engine.h +23 -0
- data/engines/jsc/include/narwhal.h +427 -0
- data/engines/jsc/lib/file-engine.js +31 -0
- data/engines/jsc/lib/http.js +1 -0
- data/engines/jsc/lib/io-engine.js +202 -0
- data/engines/jsc/lib/os-engine.js +25 -0
- data/engines/jsc/lib/system.js +18 -0
- data/engines/jsc/lib/zip.js +1 -0
- data/engines/jsc/narwhal-jsc.c +273 -0
- data/engines/jsc/narwhal.c +29 -0
- data/engines/jsc/package.json +8 -0
- data/engines/jsc/src/binary-engine.cc +290 -0
- data/engines/jsc/src/file-engine.cc +405 -0
- data/engines/jsc/src/io-engine.cc +423 -0
- data/engines/jsc/src/jack/handler/jill.cc +710 -0
- data/engines/jsc/src/os-engine.cc +210 -0
- data/engines/rhino/bin/narwhal-rhino +68 -0
- data/engines/rhino/bin/narwhal-rhino.cmd +34 -0
- data/engines/rhino/bootstrap.js +119 -0
- data/engines/rhino/jars/jline.jar +0 -0
- data/engines/rhino/jars/jna.jar +0 -0
- data/engines/rhino/jars/js.jar +0 -0
- data/engines/rhino/lib/binary-engine.js +83 -0
- data/engines/rhino/lib/concurrency.js +6 -0
- data/engines/rhino/lib/event-queue.js +18 -0
- data/engines/rhino/lib/file-engine.js +216 -0
- data/engines/rhino/lib/http-client-engine.js +90 -0
- data/engines/rhino/lib/http-engine.js +10 -0
- data/engines/rhino/lib/io-engine.js +347 -0
- data/engines/rhino/lib/md5-engine.js +40 -0
- data/engines/rhino/lib/os-engine.js +150 -0
- data/engines/rhino/lib/packages-engine.js +71 -0
- data/engines/rhino/lib/sandbox-engine.js +70 -0
- data/engines/rhino/lib/system.js +38 -0
- data/engines/rhino/lib/worker-engine.js +23 -0
- data/engines/rhino/lib/zip.js +78 -0
- data/engines/rhino/package.json +4 -0
- data/engines/secure/lib/file.js +6 -0
- data/engines/secure/lib/system.js +6 -0
- data/engines/template/bin/narwhal-engine-name +32 -0
- data/engines/template/bootstrap.js +40 -0
- data/engines/template/lib/file-engine.js +118 -0
- data/engines/template/lib/system.js +17 -0
- data/examples/browser-deployment-jackconfig.js +35 -0
- data/examples/fibonacci-worker.js +35 -0
- data/examples/fibonacci.js +19 -0
- data/examples/hello +2 -0
- data/examples/narwhal +3 -0
- data/examples/not-quite-a-quine.js +1 -0
- data/extconf.rb +44 -0
- data/gem_bin/narwhal +5 -0
- data/gem_bin/sea +4 -0
- data/gem_bin/tusk +4 -0
- data/lib/args.js +849 -0
- data/lib/base16.js +16 -0
- data/lib/base64.js +120 -0
- data/lib/codec/base64.js +8 -0
- data/lib/crc32.js +60 -0
- data/lib/file-bootstrap.js +187 -0
- data/lib/file.js +659 -0
- data/lib/hash.js +28 -0
- data/lib/hashp.js +65 -0
- data/lib/html.js +16 -0
- data/lib/http-client.js +134 -0
- data/lib/http.js +17 -0
- data/lib/io.js +98 -0
- data/lib/jsmin.js +315 -0
- data/lib/jsonpath.js +89 -0
- data/lib/logger.js +55 -0
- data/lib/md4.js +146 -0
- data/lib/md5.js +164 -0
- data/lib/mime.js +166 -0
- data/lib/narwhal.js +102 -0
- data/lib/narwhal/client.js +261 -0
- data/lib/narwhal/compile.js +99 -0
- data/lib/narwhal/env.js +140 -0
- data/lib/narwhal/inline.js +106 -0
- data/lib/narwhal/json.js +324 -0
- data/lib/narwhal/json.md +178 -0
- data/lib/narwhal/repl.js +96 -0
- data/lib/narwhal/server-test.js +6 -0
- data/lib/narwhal/server.js +270 -0
- data/lib/narwhal/tusk.js +170 -0
- data/lib/narwhal/tusk/bin.js +13 -0
- data/lib/narwhal/tusk/bundle.js +0 -0
- data/lib/narwhal/tusk/catalog.js +22 -0
- data/lib/narwhal/tusk/clone.js +66 -0
- data/lib/narwhal/tusk/consolidate.js +25 -0
- data/lib/narwhal/tusk/create-catalog.js +80 -0
- data/lib/narwhal/tusk/engine.js +42 -0
- data/lib/narwhal/tusk/freeze.js +0 -0
- data/lib/narwhal/tusk/init.js +56 -0
- data/lib/narwhal/tusk/install.js +288 -0
- data/lib/narwhal/tusk/list.js +20 -0
- data/lib/narwhal/tusk/orphans.js +0 -0
- data/lib/narwhal/tusk/reheat.js +15 -0
- data/lib/narwhal/tusk/remove.js +15 -0
- data/lib/narwhal/tusk/search.js +145 -0
- data/lib/narwhal/tusk/update.js +21 -0
- data/lib/narwhal/tusk/upgrade.js +0 -0
- data/lib/os.js +33 -0
- data/lib/packages.js +423 -0
- data/lib/printf.js +169 -0
- data/lib/promise.js +352 -0
- data/lib/querystring.js +176 -0
- data/lib/ref-send.js +257 -0
- data/lib/regexp.js +12 -0
- data/lib/sandbox.js +422 -0
- data/lib/sha.js +112 -0
- data/lib/sha256.js +102 -0
- data/lib/struct.js +228 -0
- data/lib/term.js +179 -0
- data/lib/test/assert.js +95 -0
- data/lib/test/equiv.js +188 -0
- data/lib/test/jsdump.js +165 -0
- data/lib/test/runner.js +129 -0
- data/lib/unload.js +13 -0
- data/lib/uri.js +378 -0
- data/lib/url.js +5 -0
- data/lib/utf8.js +64 -0
- data/lib/util.js +985 -0
- data/lib/uuid.js +89 -0
- data/lib/xregexp.js +521 -0
- data/local.json.template +1 -0
- data/narwhal.gemspec +105 -0
- data/narwhal.js +213 -0
- data/package.json +26 -0
- data/packages/readline/engines/default/lib/readline.js +4 -0
- data/packages/readline/engines/rhino/lib/readline.js +6 -0
- data/packages/readline/package.json +5 -0
- data/sources.json +207 -0
- data/tests/all-tests.js +17 -0
- data/tests/args.js +31 -0
- data/tests/args/domain.js +215 -0
- data/tests/args/options.js +36 -0
- data/tests/args/shifting.js +92 -0
- data/tests/args/validation.js +31 -0
- data/tests/base64.js +23 -0
- data/tests/commonjs.js +3 -0
- data/tests/commonjs/all-tests.js +12 -0
- data/tests/commonjs/bytearray-encodings-tests.js +69 -0
- data/tests/commonjs/bytearray-tests.js +465 -0
- data/tests/commonjs/bytestring-encodings-tests.js +89 -0
- data/tests/commonjs/bytestring-tests.js +263 -0
- data/tests/commonjs/es5/all-tests.js +3 -0
- data/tests/commonjs/es5/bind.js +29 -0
- data/tests/commonjs/file-tests.js +315 -0
- data/tests/commonjs/file/dirname.js +31 -0
- data/tests/commonjs/file/extension.js +45 -0
- data/tests/commonjs/file/is-absolute.js +11 -0
- data/tests/commonjs/file/iterator.js +101 -0
- data/tests/commonjs/file/normal.js +27 -0
- data/tests/commonjs/file/path.js +17 -0
- data/tests/commonjs/file/relative.js +42 -0
- data/tests/commonjs/file/resolve.js +44 -0
- data/tests/commonjs/module-tests.js +9 -0
- data/tests/commonjs/modules/absolute/b.js +1 -0
- data/tests/commonjs/modules/absolute/program.js +5 -0
- data/tests/commonjs/modules/absolute/submodule/a.js +3 -0
- data/tests/commonjs/modules/absolute/test.js +9 -0
- data/tests/commonjs/modules/all-tests.js +47 -0
- data/tests/commonjs/modules/config.js +11 -0
- data/tests/commonjs/modules/cyclic/a.js +4 -0
- data/tests/commonjs/modules/cyclic/b.js +4 -0
- data/tests/commonjs/modules/cyclic/program.js +10 -0
- data/tests/commonjs/modules/cyclic/test.js +9 -0
- data/tests/commonjs/modules/determinism/program.js +3 -0
- data/tests/commonjs/modules/determinism/submodule/a.js +8 -0
- data/tests/commonjs/modules/determinism/submodule/b.js +2 -0
- data/tests/commonjs/modules/determinism/test.js +9 -0
- data/tests/commonjs/modules/exactExports/a.js +3 -0
- data/tests/commonjs/modules/exactExports/program.js +4 -0
- data/tests/commonjs/modules/exactExports/test.js +9 -0
- data/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js +0 -0
- data/tests/commonjs/modules/hasOwnProperty/program.js +3 -0
- data/tests/commonjs/modules/hasOwnProperty/test.js +9 -0
- data/tests/commonjs/modules/hasOwnProperty/toString.js +0 -0
- data/tests/commonjs/modules/method/a.js +12 -0
- data/tests/commonjs/modules/method/program.js +8 -0
- data/tests/commonjs/modules/method/test.js +9 -0
- data/tests/commonjs/modules/missing/program.js +8 -0
- data/tests/commonjs/modules/missing/test.js +9 -0
- data/tests/commonjs/modules/monkeys/a.js +1 -0
- data/tests/commonjs/modules/monkeys/program.js +4 -0
- data/tests/commonjs/modules/monkeys/test.js +9 -0
- data/tests/commonjs/modules/nested/a/b/c/d.js +3 -0
- data/tests/commonjs/modules/nested/program.js +3 -0
- data/tests/commonjs/modules/nested/test.js +9 -0
- data/tests/commonjs/modules/relative/program.js +5 -0
- data/tests/commonjs/modules/relative/submodule/a.js +1 -0
- data/tests/commonjs/modules/relative/submodule/b.js +2 -0
- data/tests/commonjs/modules/relative/test.js +9 -0
- data/tests/commonjs/modules/transitive/a.js +1 -0
- data/tests/commonjs/modules/transitive/b.js +1 -0
- data/tests/commonjs/modules/transitive/c.js +3 -0
- data/tests/commonjs/modules/transitive/program.js +3 -0
- data/tests/commonjs/modules/transitive/test.js +9 -0
- data/tests/file/all-tests.js +61 -0
- data/tests/file/fnmatch.js +102 -0
- data/tests/file/glob.js +466 -0
- data/tests/file/match.js +102 -0
- data/tests/global.js +6 -0
- data/tests/global/array.js +19 -0
- data/tests/hashes.js +94 -0
- data/tests/html.js +13 -0
- data/tests/io/stringio.js +21 -0
- data/tests/os/all-tests.js +4 -0
- data/tests/os/popen.js +41 -0
- data/tests/os/system.js +22 -0
- data/tests/printf.js +123 -0
- data/tests/query-string.js +87 -0
- data/tests/sandbox/byte-io.js +20 -0
- data/tests/sandbox/fileName.js +3 -0
- data/tests/sandbox/foo.js +0 -0
- data/tests/sandbox/reload.js +79 -0
- data/tests/string.js +35 -0
- data/tests/uri.js +41 -0
- data/tests/util/all-tests.js +79 -0
- data/tests/util/array.js +207 -0
- data/tests/util/array/is-arguments.js +29 -0
- data/tests/util/array/is-array-like.js +29 -0
- data/tests/util/case.js +9 -0
- data/tests/util/collection.js +104 -0
- data/tests/util/eq.js +57 -0
- data/tests/util/expand.js +45 -0
- data/tests/util/object.js +125 -0
- data/tests/util/operator.js +25 -0
- data/tests/util/range.js +19 -0
- data/tests/util/repr.js +26 -0
- data/tests/util/string.js +34 -0
- data/tests/util/unique.js +12 -0
- metadata +434 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
if (!Object.keys) {
|
3
|
+
Object.keys = function (object) {
|
4
|
+
var keys = [];
|
5
|
+
for (var name in object) {
|
6
|
+
if (Object.prototype.hasOwnProperty.call(object, name)) {
|
7
|
+
keys.push(name);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
return keys;
|
11
|
+
};
|
12
|
+
}
|
13
|
+
|
14
|
+
if (!Object.defineProperty)
|
15
|
+
Object.defineProperty = function(object, property, descriptor) {
|
16
|
+
var has = Object.prototype.hasOwnProperty;
|
17
|
+
if (typeof descriptor == "object") {
|
18
|
+
if (has.call(descriptor, "value")) {
|
19
|
+
if (!object.__lookupGetter__(property) && !object.__lookupSetter__(property))
|
20
|
+
// data property defined and no pre-existing accessors
|
21
|
+
object[property] = descriptor.value;
|
22
|
+
if ((has.call(descriptor, "get") || has.call(descriptor, "set")))
|
23
|
+
// descriptor has a value property but accessor already exists
|
24
|
+
throw new TypeError("Object doesn't support this action");
|
25
|
+
}
|
26
|
+
if ( // can't implement these features; allow false but not true
|
27
|
+
!(has.call(descriptor, "writable") ? descriptor.writable : true) ||
|
28
|
+
!(has.call(descriptor, "enumerable") ? descriptor.enumerable : true) ||
|
29
|
+
!(has.call(descriptor, "configurable") ? descriptor.configurable : true)
|
30
|
+
)
|
31
|
+
throw new RangeError(
|
32
|
+
"This implementation of Object.defineProperty does not " +
|
33
|
+
"support configurable, enumerable, or writable."
|
34
|
+
);
|
35
|
+
else if (typeof descriptor.get == "function")
|
36
|
+
object.__defineGetter__(property, descriptor.get);
|
37
|
+
if (typeof descriptor.set == "function")
|
38
|
+
object.__defineSetter__(property, descriptor.set);
|
39
|
+
}
|
40
|
+
return object;
|
41
|
+
};
|
42
|
+
|
43
|
+
if (!Object.defineProperties) {
|
44
|
+
Object.defineProperties = function(object, properties) {
|
45
|
+
for (var property in properties) {
|
46
|
+
if (Object.prototype.hasOwnProperty.call(properties, property))
|
47
|
+
Object.defineProperty(object, property, properties[property]);
|
48
|
+
}
|
49
|
+
return object;
|
50
|
+
};
|
51
|
+
}
|
52
|
+
|
53
|
+
if (!Object.create) {
|
54
|
+
Object.create = function(prototype, properties) {
|
55
|
+
function Type() {};
|
56
|
+
Type.prototype = prototype;
|
57
|
+
var object = new Type();
|
58
|
+
if (typeof properties !== "undefined")
|
59
|
+
Object.defineProperties(object, properties);
|
60
|
+
return object;
|
61
|
+
};
|
62
|
+
}
|
63
|
+
|
64
|
+
if (!Object.freeze) {
|
65
|
+
Object.freeze = function (object) {
|
66
|
+
return object;
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
// String additions
|
2
|
+
|
3
|
+
String.prototype.squeeze = function() {
|
4
|
+
var set = arguments.length > 0 ? "["+Array.prototype.join.call(arguments, '')+"]" : ".|\\n",
|
5
|
+
regex = new RegExp("("+set+")\\1+", "g");
|
6
|
+
|
7
|
+
return this.replace(regex, "$1");
|
8
|
+
};
|
9
|
+
|
10
|
+
String.prototype.chomp = function(separator) {
|
11
|
+
var extra = separator ? separator + "|" : "";
|
12
|
+
return this.replace(new RegExp("("+extra+"\\r|\\n|\\r\\n)*$"), "");
|
13
|
+
};
|
14
|
+
|
15
|
+
// Check if the string starts with the given prefix string.
|
16
|
+
String.prototype.begins = function(str) {
|
17
|
+
return this.indexOf(str) === 0;
|
18
|
+
};
|
19
|
+
|
20
|
+
// Check if the string ends with the given postfix string.
|
21
|
+
String.prototype.ends = function(str) {
|
22
|
+
var offset = this.length - str.length;
|
23
|
+
return offset >= 0 && this.lastIndexOf(str) === offset;
|
24
|
+
};
|
25
|
+
|
26
|
+
// Trim the string, left/right.
|
27
|
+
//
|
28
|
+
// Faster version: http://blog.stevenlevithan.com/archives/faster-trim-javascript
|
29
|
+
//
|
30
|
+
// function trim (str) {
|
31
|
+
// var str = str.replace(/^\s\s*/, ''),
|
32
|
+
// ws = /\s/,
|
33
|
+
// i = str.length;
|
34
|
+
// while (ws.test(str.charAt(--i)));
|
35
|
+
// return str.slice(0, i + 1);
|
36
|
+
// }
|
37
|
+
//Trim the string, left.
|
38
|
+
var trimBeginExpression = /^\s\s*/g;
|
39
|
+
String.prototype.trimBegin = function() {
|
40
|
+
return this.replace(trimBeginExpression, "");
|
41
|
+
};
|
42
|
+
|
43
|
+
// Trim the string, right.
|
44
|
+
var trimEndExpression = /\s\s*$/g;
|
45
|
+
String.prototype.trimEnd = function() {
|
46
|
+
return this.replace(trimEndExpression, "");
|
47
|
+
};
|
48
|
+
|
49
|
+
String.prototype.trim = function() {
|
50
|
+
return this.replace(trimBeginExpression, "").replace(trimEndExpression, "");
|
51
|
+
};
|
52
|
+
|
53
|
+
/* binary */
|
54
|
+
|
55
|
+
// https://wiki.mozilla.org/ServerJS/Binary/B
|
56
|
+
if (!String.prototype.toByteString)
|
57
|
+
String.prototype.toByteString = function(charset) {
|
58
|
+
// RHINO bug: it thinks "this" is a Java string (?!)
|
59
|
+
var binary = require("binary");
|
60
|
+
return new binary.ByteString(String(this), charset);
|
61
|
+
};
|
62
|
+
|
63
|
+
// https://wiki.mozilla.org/ServerJS/Binary/B
|
64
|
+
if (!String.prototype.toByteArray)
|
65
|
+
String.prototype.toByteArray = function(charset) {
|
66
|
+
// RHINO bug: it thinks "this" is a Java string (?!)
|
67
|
+
var binary = require("binary");
|
68
|
+
return new binary.ByteArray(String(this), charset);
|
69
|
+
};
|
70
|
+
|
71
|
+
// https://wiki.mozilla.org/ServerJS/Binary/B
|
72
|
+
if (!String.prototype.charCodes)
|
73
|
+
String.prototype.charCodes = function() {
|
74
|
+
return Array.prototype.map.call(this, function (c) {
|
75
|
+
return c.charCodeAt();
|
76
|
+
});
|
77
|
+
};
|
78
|
+
|
79
|
+
// https://wiki.mozilla.org/ServerJS/Binary/B
|
80
|
+
if (!String.prototype.fromCharCodes)
|
81
|
+
String.fromCharCodes = function (codes) {
|
82
|
+
return codes.map(String.fromCharCode).join('');
|
83
|
+
};
|
84
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
var IO = require("./io").IO;
|
3
|
+
|
4
|
+
exports.print = function () {
|
5
|
+
exports.stdout.write(Array.prototype.join.call(arguments, ' ') + "\n").flush();
|
6
|
+
};
|
7
|
+
|
8
|
+
exports.stdin = new IO(function(){}, null);
|
9
|
+
exports.stdout = new IO(null, function(string) { exports.print(String(string).replace(/\n$/,"")); });
|
10
|
+
exports.stderr = new IO(null, function(string) { exports.print(String(string).replace(/\n$/,"")); });
|
11
|
+
|
12
|
+
exports.args = global.arguments || [];
|
13
|
+
|
14
|
+
exports.env = {};
|
15
|
+
|
16
|
+
exports.fs = require('./file');
|
17
|
+
|
18
|
+
// default logger
|
19
|
+
var Logger = require("logger").Logger;
|
20
|
+
exports.log = new Logger(exports.stdout);
|
@@ -0,0 +1,133 @@
|
|
1
|
+
var queue = require("event-queue");
|
2
|
+
var workerEngine = require("worker-engine");
|
3
|
+
|
4
|
+
var Worker = exports.Worker = function(scriptName){
|
5
|
+
var worker;
|
6
|
+
createWorker(scriptName, function(workerQueue, workerGlobal){
|
7
|
+
worker = createPort(workerQueue, workerGlobal, null, workerGlobal);
|
8
|
+
createPort(queue, worker, workerGlobal, global);
|
9
|
+
return worker;
|
10
|
+
});
|
11
|
+
return worker;
|
12
|
+
};
|
13
|
+
|
14
|
+
function createPort(queue, target, port, global){
|
15
|
+
target.onmessage = true; // give it something to feature detect off of
|
16
|
+
port = port || {
|
17
|
+
// allows for sending a message with a direct object reference.
|
18
|
+
// this is not part of CommonJS, and must be used with great care.
|
19
|
+
__enqueue__: function(eventName, args){
|
20
|
+
queue.enqueue(function(){
|
21
|
+
if(typeof target[eventName] == "function"){
|
22
|
+
target[eventName].apply(target, args);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
}
|
26
|
+
};
|
27
|
+
port.postMessage = function(message){
|
28
|
+
queue.enqueue(function(){
|
29
|
+
var event = {
|
30
|
+
//when is supposed to be the target, and when the ports? The spec is confusing
|
31
|
+
target: target,
|
32
|
+
ports: [target],
|
33
|
+
// this can be optimized to be much faster
|
34
|
+
data: typeof message == "string" ? message :
|
35
|
+
global.JSON.parse(JSON.stringify(message)),
|
36
|
+
}
|
37
|
+
if(typeof target.onmessage == "function"){
|
38
|
+
target.onmessage(event);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
};
|
42
|
+
port.isIdle= function(){
|
43
|
+
return queue.isEmpty();
|
44
|
+
};
|
45
|
+
return port;
|
46
|
+
}
|
47
|
+
function createWorker(scriptName, setup, workerName){
|
48
|
+
var workerQueue,
|
49
|
+
workerGlobal = workerEngine.createEnvironment();
|
50
|
+
|
51
|
+
// add the module lookup paths from our environment
|
52
|
+
var paths = workerGlobal.require.paths;
|
53
|
+
paths.splice(0, paths.length);
|
54
|
+
paths.push.apply(paths, require.paths);
|
55
|
+
|
56
|
+
// get the event queue
|
57
|
+
workerQueue = workerGlobal.require("event-queue");
|
58
|
+
|
59
|
+
// calback for dedicated and shared workers to do their thing
|
60
|
+
var worker = setup(workerQueue, workerGlobal);
|
61
|
+
|
62
|
+
// there must be one and only one shared worker map amongst all workers
|
63
|
+
workerGlobal.require("system").__sharedWorkers__ = system.__sharedWorkers__;
|
64
|
+
|
65
|
+
workerEngine.spawn(function(){
|
66
|
+
workerGlobal.require(scriptName);
|
67
|
+
// enter the event loop
|
68
|
+
while(true){
|
69
|
+
try{
|
70
|
+
workerQueue.nextEvent()();
|
71
|
+
if(workerQueue.isEmpty()){
|
72
|
+
// fire onidle events when empty, this allows to do effective worker pooling
|
73
|
+
queue.enqueue(function(){
|
74
|
+
if(worker && worker.onidle){
|
75
|
+
worker.onidle();
|
76
|
+
}
|
77
|
+
});
|
78
|
+
}
|
79
|
+
}catch(e){
|
80
|
+
workerQueue.enqueue(function(){
|
81
|
+
if(typeof workerGlobal.onerror === "function"){
|
82
|
+
// trigger the onerror event in the worker if an error occurs
|
83
|
+
try{
|
84
|
+
workerGlobal.onerror(e);
|
85
|
+
}
|
86
|
+
catch(e){
|
87
|
+
// don't want an error here to go into an infinite loop!
|
88
|
+
workerEngine.defaultErrorReporter(e);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
else{
|
92
|
+
workerEngine.defaultErrorReporter(e);
|
93
|
+
}
|
94
|
+
});
|
95
|
+
|
96
|
+
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}, workerName || scriptName);
|
100
|
+
};
|
101
|
+
|
102
|
+
if(!system.__sharedWorkers__){
|
103
|
+
system.__sharedWorkers__ = {};
|
104
|
+
}
|
105
|
+
|
106
|
+
exports.SharedWorker = function(scriptName, workerName){
|
107
|
+
workerName = workerName || scriptName;
|
108
|
+
var shared = system.__sharedWorkers__[workerName];
|
109
|
+
if(!shared){
|
110
|
+
var shared = {};
|
111
|
+
createWorker(scriptName, function(queue, global){
|
112
|
+
shared.queue = queue;
|
113
|
+
shared.global = global;
|
114
|
+
global.onconnect = true;
|
115
|
+
}, workerName);
|
116
|
+
system.__sharedWorkers__[workerName] = shared;
|
117
|
+
}
|
118
|
+
var port = {};
|
119
|
+
|
120
|
+
var returnPort = createPort(queue, port, null, global);
|
121
|
+
|
122
|
+
createPort(shared.queue, returnPort, port, shared.global);
|
123
|
+
shared.queue.enqueue(function(){
|
124
|
+
if(typeof shared.global.onconnect == "function"){
|
125
|
+
shared.global.onconnect({
|
126
|
+
port: returnPort
|
127
|
+
});
|
128
|
+
}
|
129
|
+
});
|
130
|
+
shared.num = shared.num || Math.random();
|
131
|
+
return {port: port};
|
132
|
+
}
|
133
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Narwhal JavaScriptCore / JSCocoa Platform
|
2
|
+
=========================================
|
3
|
+
|
4
|
+
Setup
|
5
|
+
-----
|
6
|
+
|
7
|
+
git clone git://github.com/tlrobinson/narwhal.git narwhal
|
8
|
+
cd narwhal/engines
|
9
|
+
git clone git://github.com/tlrobinson/narwhal-jsc.git jsc
|
10
|
+
cd jsc
|
11
|
+
make
|
12
|
+
cd ../..
|
13
|
+
NARWHAL_ENGINE=jsc bin/narwhal
|
14
|
+
|
15
|
+
Notes
|
16
|
+
-----
|
17
|
+
|
18
|
+
* Only builds on Mac OS X and JSCocoa support is currently broken, but both of these things can be fixed with improved Makefiles (or Jakefiles)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
(function (evalGlobal, global) {
|
2
|
+
var debug = true;
|
3
|
+
|
4
|
+
var prefix = ENV['NARWHAL_HOME'];
|
5
|
+
var enginePrefix = ENV['NARWHAL_ENGINE_HOME'];
|
6
|
+
|
7
|
+
var _isFile = isFile, _read = read, _print = print;
|
8
|
+
delete read, isFile, print;
|
9
|
+
|
10
|
+
function NativeLoader() {
|
11
|
+
var loader = {};
|
12
|
+
var factories = {};
|
13
|
+
|
14
|
+
loader.reload = function(topId, path) {
|
15
|
+
factories[topId] = requireNative(topId, path);
|
16
|
+
}
|
17
|
+
|
18
|
+
loader.load = function(topId, path) {
|
19
|
+
if (!factories.hasOwnProperty(topId))
|
20
|
+
loader.reload(topId, path);
|
21
|
+
return factories[topId];
|
22
|
+
}
|
23
|
+
|
24
|
+
return loader;
|
25
|
+
};
|
26
|
+
|
27
|
+
var narwhal = eval(_read(prefix + "/narwhal.js"));
|
28
|
+
|
29
|
+
narwhal({
|
30
|
+
global: global,
|
31
|
+
evalGlobal: evalGlobal,
|
32
|
+
engine: 'jsc',
|
33
|
+
engines: ['jsc', 'c', 'default'],
|
34
|
+
prefix: prefix,
|
35
|
+
prefixes: [enginePrefix, prefix],
|
36
|
+
debug: debug,
|
37
|
+
print: function (string) { _print(String(string)); },
|
38
|
+
evaluate: function (text) {
|
39
|
+
return eval("(function(require,exports,module,system,print){" + text + "/**/\n})");
|
40
|
+
},
|
41
|
+
fs: {
|
42
|
+
read: function(path) { return _read(path); },
|
43
|
+
isFile: function(path) { return _isFile(path); }
|
44
|
+
},
|
45
|
+
loaders: [[".dylib", NativeLoader()]],
|
46
|
+
os : "darwin",
|
47
|
+
debug: ENV['NARWHAL_DEBUG'],
|
48
|
+
verbose: ENV['NARWHAL_VERBOSE']
|
49
|
+
});
|
50
|
+
|
51
|
+
})(function () {
|
52
|
+
return eval(arguments[0]);
|
53
|
+
}, this);
|
@@ -0,0 +1,77 @@
|
|
1
|
+
Copyright 2009, Ryan Lienhart Dahl. All rights reserved.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
IN THE SOFTWARE.
|
20
|
+
|
21
|
+
http_parser is based on Zed Shaw's Mongrel. Mongrel's license is as follows.
|
22
|
+
|
23
|
+
---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----
|
24
|
+
Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
|
25
|
+
<zedshaw at zedshaw dot com> and contributors. You can redistribute it
|
26
|
+
and/or modify it under either the terms of the GPL2 or the conditions below:
|
27
|
+
|
28
|
+
1. You may make and give away verbatim copies of the source form of the
|
29
|
+
software without restriction, provided that you duplicate all of the
|
30
|
+
original copyright notices and associated disclaimers.
|
31
|
+
|
32
|
+
2. You may modify your copy of the software in any way, provided that
|
33
|
+
you do at least ONE of the following:
|
34
|
+
|
35
|
+
a) place your modifications in the Public Domain or otherwise make them
|
36
|
+
Freely Available, such as by posting said modifications to Usenet or an
|
37
|
+
equivalent medium, or by allowing the author to include your
|
38
|
+
modifications in the software.
|
39
|
+
|
40
|
+
b) use the modified software only within your corporation or
|
41
|
+
organization.
|
42
|
+
|
43
|
+
c) rename any non-standard executables so the names do not conflict with
|
44
|
+
standard executables, which must also be provided.
|
45
|
+
|
46
|
+
d) make other distribution arrangements with the author.
|
47
|
+
|
48
|
+
3. You may distribute the software in object code or executable
|
49
|
+
form, provided that you do at least ONE of the following:
|
50
|
+
|
51
|
+
a) distribute the executables and library files of the software,
|
52
|
+
together with instructions (in the manual page or equivalent) on where
|
53
|
+
to get the original distribution.
|
54
|
+
|
55
|
+
b) accompany the distribution with the machine-readable source of the
|
56
|
+
software.
|
57
|
+
|
58
|
+
c) give non-standard executables non-standard names, with
|
59
|
+
instructions on where to get the original software distribution.
|
60
|
+
|
61
|
+
d) make other distribution arrangements with the author.
|
62
|
+
|
63
|
+
4. You may modify and include the part of the software into any other
|
64
|
+
software (possibly commercial). But some files in the distribution
|
65
|
+
are not written by the author, so that they are not under this terms.
|
66
|
+
|
67
|
+
5. The scripts and library files supplied as input to or produced as
|
68
|
+
output from the software do not automatically fall under the
|
69
|
+
copyright of the software, but belong to whomever generated them,
|
70
|
+
and may be sold commercially, and may be aggregated with this
|
71
|
+
software.
|
72
|
+
|
73
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
74
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
75
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
76
|
+
PURPOSE.
|
77
|
+
---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----
|