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,8 @@
|
|
1
|
+
// Format a Date object as a string according to a subset of the ISO-8601 standard.
|
2
|
+
// Useful in Atom.
|
3
|
+
if (!Date.prototype.toISOString) {
|
4
|
+
Date.prototype.toISOString = function() {
|
5
|
+
return (this.getFullYear() + "-" + this.getMonth() + "-" + this.getDate() + "T" + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds() + "Z");
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
|
2
|
+
// HACK: use "fs.read" and "fs.isFile" until properly implemented.
|
3
|
+
// save "fs" here since it will be replaced in "system" later.
|
4
|
+
var fs = system.fs;
|
5
|
+
|
6
|
+
var exports = require('./file');
|
7
|
+
|
8
|
+
exports.SEPARATOR = '/';
|
9
|
+
exports.ALT_SEPARATOR = undefined;
|
10
|
+
exports.ROOT = '/';
|
11
|
+
|
12
|
+
exports.cwd = function () {
|
13
|
+
return system.env['PWD'] || '.';
|
14
|
+
};
|
15
|
+
|
16
|
+
// TODO necessary for package loading
|
17
|
+
exports.list = function (path) {
|
18
|
+
throw Error("list not yet implemented.");
|
19
|
+
};
|
20
|
+
|
21
|
+
// TODO necessary for package loading
|
22
|
+
exports.canonical = function (path) {
|
23
|
+
// does not resolve symlinks
|
24
|
+
return exports.absolute(path);
|
25
|
+
};
|
26
|
+
|
27
|
+
exports.exists = function (path) {
|
28
|
+
throw Error("exists not yet implemented.");
|
29
|
+
};
|
30
|
+
|
31
|
+
// TODO necessary for lazy module reloading in sandboxes
|
32
|
+
exports.mtime = function (path) {
|
33
|
+
return Date();
|
34
|
+
};
|
35
|
+
|
36
|
+
exports.size = function (path) {
|
37
|
+
throw Error("size not yet implemented.");
|
38
|
+
};
|
39
|
+
|
40
|
+
exports.stat = function (path) {
|
41
|
+
return {
|
42
|
+
mtime: exports.mtime(path),
|
43
|
+
size: exports.size(path)
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
// TODO necessary for package loading
|
48
|
+
exports.isDirectory = function (path) {
|
49
|
+
//throw Error("isDirectory not yet implemented.");
|
50
|
+
system.log.warn("isDirectory not yet implemented. ("+path+")");
|
51
|
+
return false;
|
52
|
+
};
|
53
|
+
|
54
|
+
// TODO necessary for module loading
|
55
|
+
exports.isFile = function (path) {
|
56
|
+
return fs.isFile(path);
|
57
|
+
};
|
58
|
+
|
59
|
+
exports.isLink = function (path) {
|
60
|
+
throw Error("isLink not yet implemented.");
|
61
|
+
};
|
62
|
+
|
63
|
+
exports.isReadable = function (path) {
|
64
|
+
throw Error("isReadable not yet implemented.");
|
65
|
+
};
|
66
|
+
|
67
|
+
exports.isWritable = function (path) {
|
68
|
+
throw Error("isWritable not yet implemented.");
|
69
|
+
};
|
70
|
+
|
71
|
+
exports.rename = function (source, target) {
|
72
|
+
throw Error("rename not yet implemented.");
|
73
|
+
};
|
74
|
+
|
75
|
+
exports.move = function (source, target) {
|
76
|
+
throw Error("move not yet implemented.");
|
77
|
+
};
|
78
|
+
|
79
|
+
exports.remove = function (path) {
|
80
|
+
throw Error("remove not yet implemented.");
|
81
|
+
};
|
82
|
+
|
83
|
+
exports.mkdir = function (path) {
|
84
|
+
throw Error("mkdir not yet implemented.");
|
85
|
+
};
|
86
|
+
|
87
|
+
exports.rmdir = function(path) {
|
88
|
+
throw Error("rmdir not yet implemented.");
|
89
|
+
};
|
90
|
+
|
91
|
+
exports.touch = function (path, mtime) {
|
92
|
+
throw Error("touch not yet implemented.");
|
93
|
+
};
|
94
|
+
|
95
|
+
exports.FileIO = function (path, mode, permissions) {
|
96
|
+
mode = exports.mode(mode);
|
97
|
+
var read = mode.read,
|
98
|
+
write = mode.write,
|
99
|
+
append = mode.append,
|
100
|
+
update = mode.update;
|
101
|
+
|
102
|
+
if (update) {
|
103
|
+
throw new Error("Updating IO not yet implemented.");
|
104
|
+
} else if (write || append) {
|
105
|
+
throw new Error("Writing IO not yet implemented.");
|
106
|
+
} else if (read) {
|
107
|
+
// FIXME temporary hack
|
108
|
+
return {
|
109
|
+
'read': function () {
|
110
|
+
return fs.read(path);
|
111
|
+
},
|
112
|
+
'close': function () {
|
113
|
+
}
|
114
|
+
};
|
115
|
+
} else {
|
116
|
+
throw new Error("Files must be opened either for read, write, or update mode.");
|
117
|
+
}
|
118
|
+
};
|
119
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
|
2
|
+
require("object"); // must come first
|
3
|
+
|
4
|
+
// ES-5 15.3.4.5
|
5
|
+
// http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
|
6
|
+
var slice = Array.prototype.slice;
|
7
|
+
if (!Function.prototype.bind) {
|
8
|
+
Function.prototype.bind = function (that) { // .length is 1
|
9
|
+
// 1. Let Target be the this value.
|
10
|
+
var target = this;
|
11
|
+
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
12
|
+
// XXX this gets pretty close, for all intents and purposes, letting
|
13
|
+
// some duck-types slide
|
14
|
+
if (typeof target.apply != "function" || typeof target.call != "function")
|
15
|
+
return new TypeError();
|
16
|
+
// 3. Let A be a new (possibly empty) internal list of all of the
|
17
|
+
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
18
|
+
var args = slice.call(arguments);
|
19
|
+
// 4. Let F be a new native ECMAScript object.
|
20
|
+
// 9. Set the [[Prototype]] internal property of F to the standard
|
21
|
+
// built-in Function prototype object as specified in 15.3.3.1.
|
22
|
+
// 10. Set the [[Call]] internal property of F as described in
|
23
|
+
// 15.3.4.5.1.
|
24
|
+
// 11. Set the [[Construct]] internal property of F as described in
|
25
|
+
// 15.3.4.5.2.
|
26
|
+
// 12. Set the [[HasInstance]] internal property of F as described in
|
27
|
+
// 15.3.4.5.3.
|
28
|
+
// 13. The [[Scope]] internal property of F is unused and need not
|
29
|
+
// exist.
|
30
|
+
var bound = function () {
|
31
|
+
|
32
|
+
if (this instanceof bound) {
|
33
|
+
// 15.3.4.5.2 [[Construct]]
|
34
|
+
// When the [[Construct]] internal method of a function object,
|
35
|
+
// F that was created using the bind function is called with a
|
36
|
+
// list of arguments ExtraArgs the following steps are taken:
|
37
|
+
// 1. Let target be the value of F's [[TargetFunction]]
|
38
|
+
// internal property.
|
39
|
+
// 2. If target has no [[Construct]] internal method, a
|
40
|
+
// TypeError exception is thrown.
|
41
|
+
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
|
42
|
+
// property.
|
43
|
+
// 4. Let args be a new list containing the same values as the
|
44
|
+
// list boundArgs in the same order followed by the same
|
45
|
+
// values as the list ExtraArgs in the same order.
|
46
|
+
|
47
|
+
var self = Object.create(target.prototype);
|
48
|
+
target.apply(self, args.concat(slice.call(arguments)));
|
49
|
+
return self;
|
50
|
+
|
51
|
+
} else {
|
52
|
+
// 15.3.4.5.1 [[Call]]
|
53
|
+
// When the [[Call]] internal method of a function object, F,
|
54
|
+
// which was created using the bind function is called with a
|
55
|
+
// this value and a list of arguments ExtraArgs the following
|
56
|
+
// steps are taken:
|
57
|
+
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
58
|
+
// property.
|
59
|
+
// 2. Let boundThis be the value of F's [[BoundThis]] internal
|
60
|
+
// property.
|
61
|
+
// 3. Let target be the value of F's [[TargetFunction]] internal
|
62
|
+
// property.
|
63
|
+
// 4. Let args be a new list containing the same values as the list
|
64
|
+
// boundArgs in the same order followed by the same values as
|
65
|
+
// the list ExtraArgs in the same order. 5. Return the
|
66
|
+
// result of calling the [[Call]] internal method of target
|
67
|
+
// providing boundThis as the this value and providing args
|
68
|
+
// as the arguments.
|
69
|
+
|
70
|
+
// equiv: target.call(this, ...boundArgs, ...args)
|
71
|
+
return target.call.apply(
|
72
|
+
target,
|
73
|
+
args.concat(slice.call(arguments))
|
74
|
+
);
|
75
|
+
|
76
|
+
}
|
77
|
+
|
78
|
+
};
|
79
|
+
// 5. Set the [[TargetFunction]] internal property of F to Target.
|
80
|
+
// extra:
|
81
|
+
bound.bound = target;
|
82
|
+
// 6. Set the [[BoundThis]] internal property of F to the value of
|
83
|
+
// thisArg.
|
84
|
+
// extra:
|
85
|
+
bound.boundTo = that;
|
86
|
+
// 7. Set the [[BoundArgs]] internal property of F to A.
|
87
|
+
// extra:
|
88
|
+
bound.boundArgs = args;
|
89
|
+
bound.length = (
|
90
|
+
// 14. If the [[Class]] internal property of Target is "Function", then
|
91
|
+
typeof target == "function" ?
|
92
|
+
// a. Let L be the length property of Target minus the length of A.
|
93
|
+
// b. Set the length own property of F to either 0 or L, whichever is larger.
|
94
|
+
Math.max(target.length - args.length, 0) :
|
95
|
+
// 15. Else set the length own property of F to 0.
|
96
|
+
0
|
97
|
+
)
|
98
|
+
// 16. The length own property of F is given attributes as specified in
|
99
|
+
// 15.3.5.1.
|
100
|
+
// TODO
|
101
|
+
// 17. Set the [[Extensible]] internal property of F to true.
|
102
|
+
// TODO
|
103
|
+
// 18. Call the [[DefineOwnProperty]] internal method of F with
|
104
|
+
// arguments "caller", PropertyDescriptor {[[Value]]: null,
|
105
|
+
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
|
106
|
+
// false}, and false.
|
107
|
+
// TODO
|
108
|
+
// 19. Call the [[DefineOwnProperty]] internal method of F with
|
109
|
+
// arguments "arguments", PropertyDescriptor {[[Value]]: null,
|
110
|
+
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
|
111
|
+
// false}, and false.
|
112
|
+
// TODO
|
113
|
+
// NOTE Function objects created using Function.prototype.bind do not
|
114
|
+
// have a prototype property.
|
115
|
+
// XXX can't delete it in pure-js.
|
116
|
+
return bound;
|
117
|
+
};
|
118
|
+
}
|
119
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// IO: default
|
2
|
+
|
3
|
+
var IO = exports.IO = function(inputStream, outputStream) {
|
4
|
+
this.inputStream = inputStream;
|
5
|
+
this.outputStream = outputStream;
|
6
|
+
}
|
7
|
+
|
8
|
+
IO.prototype.read = function(length) {
|
9
|
+
return this.inputStream(length);
|
10
|
+
}
|
11
|
+
|
12
|
+
IO.prototype.write = function(object) {
|
13
|
+
this.outputStream(object);
|
14
|
+
return this;
|
15
|
+
}
|
16
|
+
|
17
|
+
IO.prototype.flush = function() {
|
18
|
+
return this;
|
19
|
+
}
|
20
|
+
|
21
|
+
IO.prototype.close = function() {
|
22
|
+
}
|
23
|
+
|
24
|
+
exports.TextIOWrapper = function (raw, mode, lineBuffering, buffering, charset, options) {
|
25
|
+
return raw;
|
26
|
+
}
|
@@ -0,0 +1,488 @@
|
|
1
|
+
/*
|
2
|
+
http://www.JSON.org/json2.js
|
3
|
+
2008-11-19
|
4
|
+
|
5
|
+
Public Domain.
|
6
|
+
|
7
|
+
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
8
|
+
|
9
|
+
See http://www.JSON.org/js.html
|
10
|
+
|
11
|
+
This file creates a global JSON object containing two methods: stringify
|
12
|
+
and parse.
|
13
|
+
|
14
|
+
JSON.stringify(value, replacer, space)
|
15
|
+
value any JavaScript value, usually an object or array.
|
16
|
+
|
17
|
+
replacer an optional parameter that determines how object
|
18
|
+
values are stringified for objects. It can be a
|
19
|
+
function or an array of strings.
|
20
|
+
|
21
|
+
space an optional parameter that specifies the indentation
|
22
|
+
of nested structures. If it is omitted, the text will
|
23
|
+
be packed without extra whitespace. If it is a number,
|
24
|
+
it will specify the number of spaces to indent at each
|
25
|
+
level. If it is a string (such as '\t' or ' '),
|
26
|
+
it contains the characters used to indent at each level.
|
27
|
+
|
28
|
+
This method produces a JSON text from a JavaScript value.
|
29
|
+
|
30
|
+
When an object value is found, if the object contains a toJSON
|
31
|
+
method, its toJSON method will be called and the result will be
|
32
|
+
stringified. A toJSON method does not serialize: it returns the
|
33
|
+
value represented by the name/value pair that should be serialized,
|
34
|
+
or undefined if nothing should be serialized. The toJSON method
|
35
|
+
will be passed the key associated with the value, and this will be
|
36
|
+
bound to the object holding the key.
|
37
|
+
|
38
|
+
For example, this would serialize Dates as ISO strings.
|
39
|
+
|
40
|
+
Date.prototype.toJSON = function (key) {
|
41
|
+
function f(n) {
|
42
|
+
// Format integers to have at least two digits.
|
43
|
+
return n < 10 ? '0' + n : n;
|
44
|
+
}
|
45
|
+
|
46
|
+
return this.getUTCFullYear() + '-' +
|
47
|
+
f(this.getUTCMonth() + 1) + '-' +
|
48
|
+
f(this.getUTCDate()) + 'T' +
|
49
|
+
f(this.getUTCHours()) + ':' +
|
50
|
+
f(this.getUTCMinutes()) + ':' +
|
51
|
+
f(this.getUTCSeconds()) + 'Z';
|
52
|
+
};
|
53
|
+
|
54
|
+
You can provide an optional replacer method. It will be passed the
|
55
|
+
key and value of each member, with this bound to the containing
|
56
|
+
object. The value that is returned from your method will be
|
57
|
+
serialized. If your method returns undefined, then the member will
|
58
|
+
be excluded from the serialization.
|
59
|
+
|
60
|
+
If the replacer parameter is an array of strings, then it will be
|
61
|
+
used to select the members to be serialized. It filters the results
|
62
|
+
such that only members with keys listed in the replacer array are
|
63
|
+
stringified.
|
64
|
+
|
65
|
+
Values that do not have JSON representations, such as undefined or
|
66
|
+
functions, will not be serialized. Such values in objects will be
|
67
|
+
dropped; in arrays they will be replaced with null. You can use
|
68
|
+
a replacer function to replace those with JSON values.
|
69
|
+
JSON.stringify(undefined) returns undefined.
|
70
|
+
|
71
|
+
The optional space parameter produces a stringification of the
|
72
|
+
value that is filled with line breaks and indentation to make it
|
73
|
+
easier to read.
|
74
|
+
|
75
|
+
If the space parameter is a non-empty string, then that string will
|
76
|
+
be used for indentation. If the space parameter is a number, then
|
77
|
+
the indentation will be that many spaces.
|
78
|
+
|
79
|
+
Example:
|
80
|
+
|
81
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
82
|
+
// text is '["e",{"pluribus":"unum"}]'
|
83
|
+
|
84
|
+
|
85
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
86
|
+
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
87
|
+
|
88
|
+
text = JSON.stringify([new Date()], function (key, value) {
|
89
|
+
return this[key] instanceof Date ?
|
90
|
+
'Date(' + this[key] + ')' : value;
|
91
|
+
});
|
92
|
+
// text is '["Date(---current time---)"]'
|
93
|
+
|
94
|
+
|
95
|
+
JSON.parse(text, reviver)
|
96
|
+
This method parses a JSON text to produce an object or array.
|
97
|
+
It can throw a SyntaxError exception.
|
98
|
+
|
99
|
+
The optional reviver parameter is a function that can filter and
|
100
|
+
transform the results. It receives each of the keys and values,
|
101
|
+
and its return value is used instead of the original value.
|
102
|
+
If it returns what it received, then the structure is not modified.
|
103
|
+
If it returns undefined then the member is deleted.
|
104
|
+
|
105
|
+
Example:
|
106
|
+
|
107
|
+
// Parse the text. Values that look like ISO date strings will
|
108
|
+
// be converted to Date objects.
|
109
|
+
|
110
|
+
myData = JSON.parse(text, function (key, value) {
|
111
|
+
var a;
|
112
|
+
if (typeof value === 'string') {
|
113
|
+
a =
|
114
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
115
|
+
if (a) {
|
116
|
+
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
117
|
+
+a[5], +a[6]));
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return value;
|
121
|
+
});
|
122
|
+
|
123
|
+
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
124
|
+
var d;
|
125
|
+
if (typeof value === 'string' &&
|
126
|
+
value.slice(0, 5) === 'Date(' &&
|
127
|
+
value.slice(-1) === ')') {
|
128
|
+
d = new Date(value.slice(5, -1));
|
129
|
+
if (d) {
|
130
|
+
return d;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
return value;
|
134
|
+
});
|
135
|
+
|
136
|
+
|
137
|
+
This is a reference implementation. You are free to copy, modify, or
|
138
|
+
redistribute.
|
139
|
+
|
140
|
+
This code should be minified before deployment.
|
141
|
+
See http://javascript.crockford.com/jsmin.html
|
142
|
+
|
143
|
+
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
144
|
+
NOT CONTROL.
|
145
|
+
*/
|
146
|
+
|
147
|
+
/*jslint evil: true */
|
148
|
+
|
149
|
+
/*global JSON */
|
150
|
+
|
151
|
+
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
152
|
+
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
153
|
+
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
154
|
+
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
155
|
+
test, toJSON, toString, valueOf
|
156
|
+
*/
|
157
|
+
|
158
|
+
// Create a JSON object only if one does not already exist. We create the
|
159
|
+
// methods in a closure to avoid creating global variables.
|
160
|
+
|
161
|
+
var JSON = this.JSON = typeof exports == "undefined" ? {} : exports;
|
162
|
+
|
163
|
+
(function () {
|
164
|
+
|
165
|
+
function f(n) {
|
166
|
+
// Format integers to have at least two digits.
|
167
|
+
return n < 10 ? '0' + n : n;
|
168
|
+
}
|
169
|
+
|
170
|
+
if (typeof Date.prototype.toJSON !== 'function') {
|
171
|
+
|
172
|
+
Date.prototype.toJSON = function (key) {
|
173
|
+
|
174
|
+
return this.getUTCFullYear() + '-' +
|
175
|
+
f(this.getUTCMonth() + 1) + '-' +
|
176
|
+
f(this.getUTCDate()) + 'T' +
|
177
|
+
f(this.getUTCHours()) + ':' +
|
178
|
+
f(this.getUTCMinutes()) + ':' +
|
179
|
+
f(this.getUTCSeconds()) + 'Z';
|
180
|
+
};
|
181
|
+
|
182
|
+
String.prototype.toJSON =
|
183
|
+
Number.prototype.toJSON =
|
184
|
+
Boolean.prototype.toJSON = function (key) {
|
185
|
+
return this.valueOf();
|
186
|
+
};
|
187
|
+
}
|
188
|
+
|
189
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
190
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
191
|
+
gap,
|
192
|
+
indent,
|
193
|
+
meta = { // table of character substitutions
|
194
|
+
'\b': '\\b',
|
195
|
+
'\t': '\\t',
|
196
|
+
'\n': '\\n',
|
197
|
+
'\f': '\\f',
|
198
|
+
'\r': '\\r',
|
199
|
+
'"' : '\\"',
|
200
|
+
'\\': '\\\\'
|
201
|
+
},
|
202
|
+
rep;
|
203
|
+
|
204
|
+
|
205
|
+
function quote(string) {
|
206
|
+
|
207
|
+
// If the string contains no control characters, no quote characters, and no
|
208
|
+
// backslash characters, then we can safely slap some quotes around it.
|
209
|
+
// Otherwise we must also replace the offending characters with safe escape
|
210
|
+
// sequences.
|
211
|
+
|
212
|
+
escapable.lastIndex = 0;
|
213
|
+
return escapable.test(string) ?
|
214
|
+
'"' + string.replace(escapable, function (a) {
|
215
|
+
var c = meta[a];
|
216
|
+
return typeof c === 'string' ? c :
|
217
|
+
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
218
|
+
}) + '"' :
|
219
|
+
'"' + string + '"';
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
function str(key, holder) {
|
224
|
+
|
225
|
+
// Produce a string from holder[key].
|
226
|
+
|
227
|
+
var i, // The loop counter.
|
228
|
+
k, // The member key.
|
229
|
+
v, // The member value.
|
230
|
+
length,
|
231
|
+
mind = gap,
|
232
|
+
partial,
|
233
|
+
value = holder[key];
|
234
|
+
|
235
|
+
// If the value has a toJSON method, call it to obtain a replacement value.
|
236
|
+
|
237
|
+
if (value && typeof value === 'object' &&
|
238
|
+
typeof value.toJSON === 'function') {
|
239
|
+
value = value.toJSON(key);
|
240
|
+
}
|
241
|
+
|
242
|
+
// If we were called with a replacer function, then call the replacer to
|
243
|
+
// obtain a replacement value.
|
244
|
+
|
245
|
+
if (typeof rep === 'function') {
|
246
|
+
value = rep.call(holder, key, value);
|
247
|
+
}
|
248
|
+
|
249
|
+
// What happens next depends on the value's type.
|
250
|
+
|
251
|
+
switch (typeof value) {
|
252
|
+
case 'string':
|
253
|
+
return quote(value);
|
254
|
+
|
255
|
+
case 'number':
|
256
|
+
|
257
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
258
|
+
|
259
|
+
return isFinite(value) ? String(value) : 'null';
|
260
|
+
|
261
|
+
case 'boolean':
|
262
|
+
case 'null':
|
263
|
+
|
264
|
+
// If the value is a boolean or null, convert it to a string. Note:
|
265
|
+
// typeof null does not produce 'null'. The case is included here in
|
266
|
+
// the remote chance that this gets fixed someday.
|
267
|
+
|
268
|
+
return String(value);
|
269
|
+
|
270
|
+
// If the type is 'object', we might be dealing with an object or an array or
|
271
|
+
// null.
|
272
|
+
|
273
|
+
case 'object':
|
274
|
+
|
275
|
+
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
276
|
+
// so watch out for that case.
|
277
|
+
|
278
|
+
if (!value) {
|
279
|
+
return 'null';
|
280
|
+
}
|
281
|
+
|
282
|
+
// Make an array to hold the partial results of stringifying this object value.
|
283
|
+
|
284
|
+
gap += indent;
|
285
|
+
partial = [];
|
286
|
+
|
287
|
+
// Is the value an array?
|
288
|
+
|
289
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
290
|
+
|
291
|
+
// The value is an array. Stringify every element. Use null as a placeholder
|
292
|
+
// for non-JSON values.
|
293
|
+
|
294
|
+
length = value.length;
|
295
|
+
for (i = 0; i < length; i += 1) {
|
296
|
+
partial[i] = str(i, value) || 'null';
|
297
|
+
}
|
298
|
+
|
299
|
+
// Join all of the elements together, separated with commas, and wrap them in
|
300
|
+
// brackets.
|
301
|
+
|
302
|
+
v = partial.length === 0 ? '[]' :
|
303
|
+
gap ? '[\n' + gap +
|
304
|
+
partial.join(',\n' + gap) + '\n' +
|
305
|
+
mind + ']' :
|
306
|
+
'[' + partial.join(',') + ']';
|
307
|
+
gap = mind;
|
308
|
+
return v;
|
309
|
+
}
|
310
|
+
|
311
|
+
// If the replacer is an array, use it to select the members to be stringified.
|
312
|
+
|
313
|
+
if (rep && typeof rep === 'object') {
|
314
|
+
length = rep.length;
|
315
|
+
for (i = 0; i < length; i += 1) {
|
316
|
+
k = rep[i];
|
317
|
+
if (typeof k === 'string') {
|
318
|
+
v = str(k, value);
|
319
|
+
if (v) {
|
320
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
} else {
|
325
|
+
|
326
|
+
// Otherwise, iterate through all of the keys in the object.
|
327
|
+
|
328
|
+
for (k in value) {
|
329
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
330
|
+
v = str(k, value);
|
331
|
+
if (v) {
|
332
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
333
|
+
}
|
334
|
+
}
|
335
|
+
}
|
336
|
+
}
|
337
|
+
|
338
|
+
// Join all of the member texts together, separated with commas,
|
339
|
+
// and wrap them in braces.
|
340
|
+
|
341
|
+
v = partial.length === 0 ? '{}' :
|
342
|
+
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
343
|
+
mind + '}' : '{' + partial.join(',') + '}';
|
344
|
+
gap = mind;
|
345
|
+
return v;
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
// If the JSON object does not yet have a stringify method, give it one.
|
350
|
+
|
351
|
+
if (typeof JSON.stringify !== 'function') {
|
352
|
+
JSON.stringify = function (value, replacer, space) {
|
353
|
+
|
354
|
+
// The stringify method takes a value and an optional replacer, and an optional
|
355
|
+
// space parameter, and returns a JSON text. The replacer can be a function
|
356
|
+
// that can replace values, or an array of strings that will select the keys.
|
357
|
+
// A default replacer method can be provided. Use of the space parameter can
|
358
|
+
// produce text that is more easily readable.
|
359
|
+
|
360
|
+
var i;
|
361
|
+
gap = '';
|
362
|
+
indent = '';
|
363
|
+
|
364
|
+
// If the space parameter is a number, make an indent string containing that
|
365
|
+
// many spaces.
|
366
|
+
|
367
|
+
if (typeof space === 'number') {
|
368
|
+
for (i = 0; i < space; i += 1) {
|
369
|
+
indent += ' ';
|
370
|
+
}
|
371
|
+
|
372
|
+
// If the space parameter is a string, it will be used as the indent string.
|
373
|
+
|
374
|
+
} else if (typeof space === 'string') {
|
375
|
+
indent = space;
|
376
|
+
}
|
377
|
+
|
378
|
+
// If there is a replacer, it must be a function or an array.
|
379
|
+
// Otherwise, throw an error.
|
380
|
+
|
381
|
+
rep = replacer;
|
382
|
+
if (replacer && typeof replacer !== 'function' &&
|
383
|
+
(typeof replacer !== 'object' ||
|
384
|
+
typeof replacer.length !== 'number')) {
|
385
|
+
throw new Error('JSON.stringify');
|
386
|
+
}
|
387
|
+
|
388
|
+
// Make a fake root object containing our value under the key of ''.
|
389
|
+
// Return the result of stringifying the value.
|
390
|
+
|
391
|
+
return str('', {'': value});
|
392
|
+
};
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
// If the JSON object does not yet have a parse method, give it one.
|
397
|
+
|
398
|
+
if (typeof JSON.parse !== 'function') {
|
399
|
+
JSON.parse = function (text, reviver) {
|
400
|
+
|
401
|
+
// The parse method takes a text and an optional reviver function, and returns
|
402
|
+
// a JavaScript value if the text is a valid JSON text.
|
403
|
+
|
404
|
+
var j;
|
405
|
+
|
406
|
+
function walk(holder, key) {
|
407
|
+
|
408
|
+
// The walk method is used to recursively walk the resulting structure so
|
409
|
+
// that modifications can be made.
|
410
|
+
|
411
|
+
var k, v, value = holder[key];
|
412
|
+
if (value && typeof value === 'object') {
|
413
|
+
for (k in value) {
|
414
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
415
|
+
v = walk(value, k);
|
416
|
+
if (v !== undefined) {
|
417
|
+
value[k] = v;
|
418
|
+
} else {
|
419
|
+
delete value[k];
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
}
|
424
|
+
return reviver.call(holder, key, value);
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
// Parsing happens in four stages. In the first stage, we replace certain
|
429
|
+
// Unicode characters with escape sequences. JavaScript handles many characters
|
430
|
+
// incorrectly, either silently deleting them, or treating them as line endings.
|
431
|
+
|
432
|
+
cx.lastIndex = 0;
|
433
|
+
if (cx.test(text)) {
|
434
|
+
text = text.replace(cx, function (a) {
|
435
|
+
return '\\u' +
|
436
|
+
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
437
|
+
});
|
438
|
+
}
|
439
|
+
|
440
|
+
// In the second stage, we run the text against regular expressions that look
|
441
|
+
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
442
|
+
// because they can cause invocation, and '=' because it can cause mutation.
|
443
|
+
// But just to be safe, we want to reject all unexpected forms.
|
444
|
+
|
445
|
+
// We split the second stage into 4 regexp operations in order to work around
|
446
|
+
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
447
|
+
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
448
|
+
// replace all simple value tokens with ']' characters. Third, we delete all
|
449
|
+
// open brackets that follow a colon or comma or that begin the text. Finally,
|
450
|
+
// we look to see that the remaining characters are only whitespace or ']' or
|
451
|
+
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
452
|
+
|
453
|
+
if (/^[\],:{}\s]*$/.
|
454
|
+
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
|
455
|
+
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
|
456
|
+
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
457
|
+
|
458
|
+
// In the third stage we use the eval function to compile the text into a
|
459
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
460
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
461
|
+
// in parens to eliminate the ambiguity.
|
462
|
+
|
463
|
+
j = eval('(' + text + ')');
|
464
|
+
|
465
|
+
// In the optional fourth stage, we recursively walk the new structure, passing
|
466
|
+
// each name/value pair to a reviver function for possible transformation.
|
467
|
+
|
468
|
+
return typeof reviver === 'function' ?
|
469
|
+
walk({'': j}, '') : j;
|
470
|
+
}
|
471
|
+
|
472
|
+
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
473
|
+
|
474
|
+
throw new SyntaxError('JSON.parse');
|
475
|
+
};
|
476
|
+
}
|
477
|
+
})();
|
478
|
+
|
479
|
+
/**
|
480
|
+
* Serialize an object to a JSON string.
|
481
|
+
*/
|
482
|
+
JSON.encode = JSON.stringify;
|
483
|
+
|
484
|
+
/**
|
485
|
+
* Deserialize an object from a JSON string.
|
486
|
+
*/
|
487
|
+
JSON.decode = JSON.parse;
|
488
|
+
|