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,32 @@
|
|
1
|
+
|
2
|
+
How to make Packages
|
3
|
+
====================
|
4
|
+
|
5
|
+
A package consists of a directory of modules conforming to the ServerJS [Securable Modules](https://wiki.mozilla.org/ServerJS/Modules/SecurableModules) specification, and a "package.json" file in the root of the package containing the location of the modules, depedencies, and other metadata.
|
6
|
+
|
7
|
+
A package directory might have the following files and directories:
|
8
|
+
|
9
|
+
* `package.json` for package metadata like dependencies and overrides for the conventional directory names.
|
10
|
+
* `local.json` for overrides on `package.json` provided by the user.
|
11
|
+
* `bin` for executables.
|
12
|
+
* `lib` for all object code, including JavaScript modules, and C extensions.
|
13
|
+
* `src` for all buildable source code, including C and Java source code.
|
14
|
+
* `jars` for Java class trees and archives.
|
15
|
+
* `packages/{name}` for installed sub-packages.
|
16
|
+
* `engines/{engine}` for engine-specific packages.
|
17
|
+
|
18
|
+
`package.json` and `local.json` may contain the following attributes:
|
19
|
+
|
20
|
+
* `name` - the name of the package. The package system will only load one package with a given name. The name defaults to the name of the parent directory.
|
21
|
+
* `author` - the original author of the package. The author may be a String including an optional `(` URL in parentheses `)` and optional `<` email address in angle brackets `>`. Alternately, it may be an Object with any of `name`, `email`, and `url` attributes. The package reader normalizes authors to the latter Object form.
|
22
|
+
* `maintainer` - the package maintainer for the project as a String or Object just as the author attribute.
|
23
|
+
* `contributors` - may be an Array of additional author Strings.
|
24
|
+
* `url` - the URL of the project website.
|
25
|
+
* `license` - the name of the license as a String, with an optional URL in parentheses, or an Object with `name` and `url` attributes.
|
26
|
+
* `description` - a String describing the package. Most package descriptions end with a period/full stop.
|
27
|
+
* `keywords` - an Array of String keywords to assist users searching for the package with `tusk search` or `tusk apropos`.
|
28
|
+
* `lib` - a path or array of paths to top-level module directories provided in this package. Defaults to `["lib"]`.
|
29
|
+
* `jars` - for Rhino engines, a path or array of paths to directories to add to the Java CLASSPATH (uses a Java URLClassLoader, so accepts `.jar` paths and directory paths ending with `/`).
|
30
|
+
* `packages` - a path or array of paths to directories containing additional packages, defaults to `["packages"]`.
|
31
|
+
* `engines` - a path or array of paths to directories containing engine-specific packages, defaults to `["engines"]`. These engine packages will be loaded if and in the prioritized order they appear in the `system.engines` array, and with higher priority that those in this package's generic `js` path so that they can override engine-specific modules.
|
32
|
+
|
data/docs/packages.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
Available Packages
|
3
|
+
==================
|
4
|
+
|
5
|
+
You can download and install packages using the `tusk` application that comes with Narwhal. Check out `tusk help` for details. These are some of the packages:
|
6
|
+
|
7
|
+
* `jack`: the webserver and web application/framework agnostic interface, similar to Ruby's Rack and Python's WSGI. Narwhal was conceived while building Jack, and was later extracted into it's own project.
|
8
|
+
|
9
|
+
[http://github.com/tlrobinson/jack](http://github.com/tlrobinson/jack)
|
10
|
+
|
11
|
+
* `chiron`: a system of interoperable JavaScript modules, including a type system, base types, general-purpose functions, events, encoding, decoding, hashing, and caching.
|
12
|
+
|
13
|
+
[http://github.com/kriskowal/chiron](http://github.com/kriskowal/chiron)
|
14
|
+
|
15
|
+
* `nitro`: a web application framework built on top of Jack.
|
16
|
+
|
17
|
+
[http://github.com/gmosx/nitro](http://github.com/gmosx/nitro)
|
18
|
+
|
19
|
+
And others including:
|
20
|
+
|
21
|
+
* Narcissus
|
22
|
+
* Wiki Creole
|
23
|
+
* Browser
|
24
|
+
* Inspec
|
25
|
+
* Kupo
|
26
|
+
* Bespin Server Prototype
|
27
|
+
* Bespin PubSub
|
28
|
+
* Nitro Templates
|
29
|
+
* Google App Engine Utilities
|
30
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Hello 0.1
|
2
|
+
=========
|
3
|
+
|
4
|
+
Today we're announcing [Narwhal](http://narwhaljs.org/) 0.1 and [Jack](http://jackjs.org/) 0.1.
|
5
|
+
|
6
|
+
### Download
|
7
|
+
|
8
|
+
* Narwhal 0.1: [tar](http://github.com/tlrobinson/narwhal/tarball/0.1), [zip](http://github.com/tlrobinson/narwhal/zipball/0.1)
|
9
|
+
* Jack 0.1: [tar](http://github.com/tlrobinson/jack/tarball/0.1), [zip](http://github.com/tlrobinson/jack/zipball/0.1)
|
10
|
+
|
11
|
+
Check out the [quick start guide](http://narwhaljs.org/quick-start.html) for instructions on getting up and running with Narwhal and Jack.
|
12
|
+
|
13
|
+
### Release Notes
|
14
|
+
|
15
|
+
* Complete [securable modules](https://wiki.mozilla.org/ServerJS/Modules/SecurableModules) implementation, in JavaScript, with hooks for native module loading.
|
16
|
+
* Various modules, including `file`, `binary`, `os`, `system`, `args`, and many others.
|
17
|
+
* The "tusk" package manager, currently using [Github](http://github.com/) as a package repository.
|
18
|
+
* Full support for the Rhino interpreter, and partial support for numerous other [engines](http://narwhaljs.org/engines.html).
|
19
|
+
* Full support for Mac OS X, Linux, and other Unixes. Preliminary support for Windows.
|
data/docs/quick-start.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
Narwhal Quick Start
|
3
|
+
===================
|
4
|
+
|
5
|
+
Download Narwhal.
|
6
|
+
|
7
|
+
* download and extract the [zip](http://github.com/tlrobinson/narwhal/zipball/master) or [tar](http://github.com/tlrobinson/narwhal/tarball/master) archive, or
|
8
|
+
* `git clone git://github.com/tlrobinson/narwhal.git`
|
9
|
+
|
10
|
+
Put Narwhal on your PATH environment variable.
|
11
|
+
|
12
|
+
* `export PATH=$PATH:~/narwhal/bin`, or
|
13
|
+
* `source narwhal/bin/activate`
|
14
|
+
|
15
|
+
Run `narwhal` or `js` (they are equivalent).
|
16
|
+
|
17
|
+
* `js narwhal/examples/hello`
|
18
|
+
|
19
|
+
Look at the options for Narwhal.
|
20
|
+
|
21
|
+
* `js --help`
|
22
|
+
|
23
|
+
And for Tusk, the package manager and virtual environment tool.
|
24
|
+
|
25
|
+
* `tusk help`
|
26
|
+
|
27
|
+
|
28
|
+
My First Web Server
|
29
|
+
===================
|
30
|
+
|
31
|
+
Create a project "hello-web".
|
32
|
+
|
33
|
+
tusk init hello-web
|
34
|
+
cd hello-web
|
35
|
+
|
36
|
+
Enter your project as a "virtual environment" using `activate` or `sea` so that its libraries, binaries, and packages get automatically installed when you run Narwhal.
|
37
|
+
|
38
|
+
source bin/activate
|
39
|
+
|
40
|
+
or
|
41
|
+
|
42
|
+
bin/sea
|
43
|
+
|
44
|
+
Install some packages you will need, like Jack, the JSGI standard library for interoperable web services.
|
45
|
+
|
46
|
+
tusk install jack
|
47
|
+
|
48
|
+
Tusk gets downloaded and installed at "hello-web/packages/jack".
|
49
|
+
|
50
|
+
Create your "jackconfig.js". This is a trivial JSGI compatible application, wrapped in the `ContentLength` middleware to automatically set the "Content-Length" header.
|
51
|
+
|
52
|
+
exports.app = function(env) {
|
53
|
+
var text = "Hello, Web!";
|
54
|
+
return {
|
55
|
+
status : 200,
|
56
|
+
headers : { "Content-Type" : "text/plain", "Content-Length" : String(text.length) },
|
57
|
+
body : [text]
|
58
|
+
};
|
59
|
+
};
|
60
|
+
|
61
|
+
Run it!
|
62
|
+
|
63
|
+
jackup
|
64
|
+
|
65
|
+
`jackup` looks for a file called `jackconfig.js` in the current directory, or you can specify a path to a Jack application.
|
66
|
+
|
67
|
+
Open [http://localhost:8080/](http://localhost:8080/) in your web browser.
|
68
|
+
|
69
|
+
Next, take a look at the introduction to [modules](modules.html), for a primer on using and making modules in Narwhal.
|
data/docs/sea.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
Narwhal, Tusk, and Sea
|
3
|
+
======================
|
4
|
+
|
5
|
+
Narwhal is your JavaScript interpreter. It is executable with `narwhal` or `js`. See `narwhal --help` for a list of its options. It is comparable to your shell, Python or Ruby/IRB.
|
6
|
+
|
7
|
+
Tusk is your package manager. Tusk by default installs packages whereever `narwhal` is installed. See `tusk help` for a list of options. It is comparable to `apt` or `gem`. You can also use `tusk` to create new "packages", application project scaffolds, or "virtual environments", which are all share a common structure.
|
8
|
+
|
9
|
+
`sea` is a tool for entering a Narwhal "virtual environment". It executes a command or reexecutes your shell inside a "virtual environment". There is a version of `sea` that comes packed with "Narwhal", that you can use to "enter" your system `narwhal` environment, which is handy if `narwhal/bin` is not on your path. You can also `source bin/activate`, as long as your version of bash supports the `${BASH_ARGV[0]}` notation, or if your current working directory contains `bin/activate`.
|
10
|
+
|
11
|
+
You can use `narwhal`, `tusk`, and `sea` to create multiple, independent, reproducable Narwhal project installations. Assuming that `narwhal` and `tusk` are on your path, you can use `tusk init` to create two application projects.
|
12
|
+
|
13
|
+
$ tusk init foo
|
14
|
+
$ tusk init bar
|
15
|
+
$ cd foo
|
16
|
+
foo$ bin/sea
|
17
|
+
PATH=foo/bin
|
18
|
+
SEALVL=1
|
19
|
+
foo$ tusk install jack
|
20
|
+
foo$ edit jackconfig.js
|
21
|
+
foo$ jackup
|
22
|
+
Loading configuration module at foo/jackconfig
|
23
|
+
Jack is starting up using Simple on port 8080
|
24
|
+
^C
|
25
|
+
foo$ echo $SEA
|
26
|
+
foo
|
27
|
+
foo$ which sea
|
28
|
+
foo/bin/sea
|
29
|
+
foo$ exit
|
30
|
+
SEALVL=0
|
31
|
+
foo$ cd ../bar
|
32
|
+
bar$ bin/sea
|
33
|
+
PATH=bar/bin
|
34
|
+
SEALVL=1
|
35
|
+
...
|
36
|
+
|
37
|
+
When you are in a Sea, Narwhal loads all of the packages installed in that Sea and Tusk installs packages in your Sea. While you can manipulate the NARWHAL_PATH and JS_PATH environment variables manually, Seas obviate the need.
|
38
|
+
|
39
|
+
Each sea can also have a different JavaScript engine. Edit `narwhal.conf` in your Sea to use a different engine.
|
40
|
+
|
41
|
+
$ js -e 'print(system.engine)'
|
42
|
+
rhino
|
43
|
+
$ cat bar/narwhal.conf
|
44
|
+
NARWHAL_DEFAULT_PLATFORM=v8
|
45
|
+
$ bar/bin/sea 'js -e "print(system.engine)"'
|
46
|
+
v8
|
47
|
+
PATH=/bin
|
48
|
+
SEALVL=0
|
49
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
var active = false;
|
3
|
+
var pending = [];
|
4
|
+
var run = function () {
|
5
|
+
var task = pending.shift();
|
6
|
+
if (0 === pending.length) {
|
7
|
+
active = false;
|
8
|
+
} else {
|
9
|
+
setTimeout(run, 0);
|
10
|
+
}
|
11
|
+
task();
|
12
|
+
};
|
13
|
+
|
14
|
+
exports.enqueue = function enqueue(task) {
|
15
|
+
pending.push(task);
|
16
|
+
if (!active) {
|
17
|
+
setTimeout(run, 0);
|
18
|
+
active = true;
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
@@ -0,0 +1,164 @@
|
|
1
|
+
// Array additions.
|
2
|
+
|
3
|
+
// ES5 draft:
|
4
|
+
// http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
|
5
|
+
|
6
|
+
// ES5 15.4.3.2
|
7
|
+
if (!Array.isArray) {
|
8
|
+
Array.isArray = function(obj) {
|
9
|
+
return Object.prototype.toString.call(obj) == "[object Array]";
|
10
|
+
};
|
11
|
+
}
|
12
|
+
|
13
|
+
// ES5 15.4.4.18
|
14
|
+
if (!Array.prototype.forEach) {
|
15
|
+
Array.prototype.forEach = function(block, thisObject) {
|
16
|
+
var len = this.length >>> 0;
|
17
|
+
for (var i = 0; i < len; i++) {
|
18
|
+
if (i in this) {
|
19
|
+
block.call(thisObject, this[i], i, this);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
// ES5 15.4.4.19
|
26
|
+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
|
27
|
+
if (!Array.prototype.map) {
|
28
|
+
Array.prototype.map = function(fun /*, thisp*/) {
|
29
|
+
var len = this.length >>> 0;
|
30
|
+
if (typeof fun != "function")
|
31
|
+
throw new TypeError();
|
32
|
+
|
33
|
+
var res = new Array(len);
|
34
|
+
var thisp = arguments[1];
|
35
|
+
for (var i = 0; i < len; i++) {
|
36
|
+
if (i in this)
|
37
|
+
res[i] = fun.call(thisp, this[i], i, this);
|
38
|
+
}
|
39
|
+
|
40
|
+
return res;
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
// filter
|
45
|
+
if (!Array.prototype.filter) {
|
46
|
+
Array.prototype.filter = function (block /*, thisp */) {
|
47
|
+
var values = [];
|
48
|
+
var thisp = arguments[1];
|
49
|
+
for (var i = 0; i < this.length; i++)
|
50
|
+
if (block.call(thisp, this[i]))
|
51
|
+
values.push(this[i]);
|
52
|
+
return values;
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
56
|
+
// every
|
57
|
+
if (!Array.prototype.every) {
|
58
|
+
Array.prototype.every = function (block /*, thisp */) {
|
59
|
+
var thisp = arguments[1];
|
60
|
+
for (var i = 0; i < this.length; i++)
|
61
|
+
if (!block.call(thisp, this[i]))
|
62
|
+
return false;
|
63
|
+
return true;
|
64
|
+
};
|
65
|
+
}
|
66
|
+
|
67
|
+
// some
|
68
|
+
if (!Array.prototype.some) {
|
69
|
+
Array.prototype.some = function (block /*, thisp */) {
|
70
|
+
var thisp = arguments[1];
|
71
|
+
for (var i = 0; i < this.length; i++)
|
72
|
+
if (block.call(thisp, this[i]))
|
73
|
+
return true;
|
74
|
+
return false;
|
75
|
+
};
|
76
|
+
}
|
77
|
+
|
78
|
+
// reduce
|
79
|
+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
|
80
|
+
if (!Array.prototype.reduce) {
|
81
|
+
Array.prototype.reduce = function(fun /*, initial*/) {
|
82
|
+
var len = this.length >>> 0;
|
83
|
+
if (typeof fun != "function")
|
84
|
+
throw new TypeError();
|
85
|
+
|
86
|
+
// no value to return if no initial value and an empty array
|
87
|
+
if (len == 0 && arguments.length == 1)
|
88
|
+
throw new TypeError();
|
89
|
+
|
90
|
+
var i = 0;
|
91
|
+
if (arguments.length >= 2) {
|
92
|
+
var rv = arguments[1];
|
93
|
+
} else {
|
94
|
+
do {
|
95
|
+
if (i in this) {
|
96
|
+
rv = this[i++];
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
|
100
|
+
// if array contains no values, no initial value to return
|
101
|
+
if (++i >= len)
|
102
|
+
throw new TypeError();
|
103
|
+
} while (true);
|
104
|
+
}
|
105
|
+
|
106
|
+
for (; i < len; i++) {
|
107
|
+
if (i in this)
|
108
|
+
rv = fun.call(null, rv, this[i], i, this);
|
109
|
+
}
|
110
|
+
|
111
|
+
return rv;
|
112
|
+
};
|
113
|
+
}
|
114
|
+
|
115
|
+
// reduceRight
|
116
|
+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
|
117
|
+
if (!Array.prototype.reduceRight) {
|
118
|
+
Array.prototype.reduceRight = function(fun /*, initial*/) {
|
119
|
+
var len = this.length >>> 0;
|
120
|
+
if (typeof fun != "function")
|
121
|
+
throw new TypeError();
|
122
|
+
|
123
|
+
// no value to return if no initial value, empty array
|
124
|
+
if (len == 0 && arguments.length == 1)
|
125
|
+
throw new TypeError();
|
126
|
+
|
127
|
+
var i = len - 1;
|
128
|
+
if (arguments.length >= 2) {
|
129
|
+
var rv = arguments[1];
|
130
|
+
} else {
|
131
|
+
do {
|
132
|
+
if (i in this) {
|
133
|
+
rv = this[i--];
|
134
|
+
break;
|
135
|
+
}
|
136
|
+
|
137
|
+
// if array contains no values, no initial value to return
|
138
|
+
if (--i < 0)
|
139
|
+
throw new TypeError();
|
140
|
+
} while (true);
|
141
|
+
}
|
142
|
+
|
143
|
+
for (; i >= 0; i--) {
|
144
|
+
if (i in this)
|
145
|
+
rv = fun.call(null, rv, this[i], i, this);
|
146
|
+
}
|
147
|
+
|
148
|
+
return rv;
|
149
|
+
};
|
150
|
+
}
|
151
|
+
|
152
|
+
/* binary */
|
153
|
+
|
154
|
+
// https://wiki.mozilla.org/ServerJS/Binary/B
|
155
|
+
if (!Array.prototype.toByteString)
|
156
|
+
Array.prototype.toByteString = function(charset) {
|
157
|
+
return new require("binary").ByteString(this);
|
158
|
+
};
|
159
|
+
|
160
|
+
if (!Array.prototype.toByteArray)
|
161
|
+
Array.prototype.toByteArray = function(charset) {
|
162
|
+
return new ByteArray(this);
|
163
|
+
};
|
164
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
exports.B_LENGTH = function(bytes) {
|
2
|
+
return bytes.length;
|
3
|
+
}
|
4
|
+
|
5
|
+
exports.B_ALLOC = function(length) {
|
6
|
+
var bytes = new Array(length);
|
7
|
+
for (var i = 0; i < length; i++)
|
8
|
+
bytes[i] = 0;
|
9
|
+
return bytes;
|
10
|
+
}
|
11
|
+
|
12
|
+
exports.B_FILL = function(bytes, from, to, value) {
|
13
|
+
for (var i = from; i < to; i++)
|
14
|
+
bytes[i] = value;
|
15
|
+
}
|
16
|
+
|
17
|
+
exports.B_COPY = function(src, srcOffset, dst, dstOffset, length) {
|
18
|
+
for (var i = 0; i < length; i++)
|
19
|
+
dst[dstOffset+i] = src[srcOffset+i];
|
20
|
+
}
|
21
|
+
|
22
|
+
exports.B_GET = function(bytes, index) {
|
23
|
+
return bytes[index];
|
24
|
+
}
|
25
|
+
|
26
|
+
exports.B_SET = function(bytes, index, value) {
|
27
|
+
return bytes[index] = value;
|
28
|
+
}
|
29
|
+
|
30
|
+
var DEFAULT_ENCODING = "UTF-8";
|
31
|
+
|
32
|
+
exports.B_DECODE = function(bytes, offset, length, codec) {
|
33
|
+
var newBytes = exports.B_TRANSCODE(bytes, offset, length, codec, DEFAULT_ENCODING);
|
34
|
+
return exports.B_DECODE_DEFAULT(newBytes, 0, exports.B_LENGTH(newBytes));
|
35
|
+
}
|
36
|
+
|
37
|
+
exports.B_DECODE_DEFAULT = function(bytes, offset, length) {
|
38
|
+
throw "NYI";
|
39
|
+
}
|
40
|
+
|
41
|
+
exports.B_ENCODE = function(string, codec) {
|
42
|
+
var bytes = exports.B_ENCODE_DEFAULT(string);
|
43
|
+
return exports.B_TRANSCODE(bytes, 0, exports.B_LENGTH(bytes), DEFAULT_ENCODING, codec);
|
44
|
+
}
|
45
|
+
|
46
|
+
exports.B_ENCODE_DEFAULT = function(string) {
|
47
|
+
throw "NYI";
|
48
|
+
}
|
49
|
+
|
50
|
+
exports.B_TRANSCODE = function(bytes, offset, length, sourceCodec, targetCodec) {
|
51
|
+
throw "NYI";
|
52
|
+
}
|
53
|
+
|