sproutit-narwhal 0.1.106

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. data/DISTRIBUTION.yml +15 -0
  2. data/README.md +86 -0
  3. data/Rakefile +349 -0
  4. data/VERSION.yml +7 -0
  5. data/bin/activate +50 -0
  6. data/bin/activate.bash +50 -0
  7. data/bin/activate.cmd +3 -0
  8. data/bin/js +67 -0
  9. data/bin/json +2 -0
  10. data/bin/narwhal +67 -0
  11. data/bin/narwhal.cmd +29 -0
  12. data/bin/sea +45 -0
  13. data/bin/sea.cmd +25 -0
  14. data/bin/tusk +2 -0
  15. data/bin/tusk.cmd +5 -0
  16. data/catalog.json +902 -0
  17. data/docs/available-packages.md +32 -0
  18. data/docs/browser-api-plan.md +290 -0
  19. data/docs/browser-api.md +153 -0
  20. data/docs/download.md +25 -0
  21. data/docs/engines.md +32 -0
  22. data/docs/json-tool.md +121 -0
  23. data/docs/lib/binary.wiki +242 -0
  24. data/docs/lib/file.wiki +325 -0
  25. data/docs/lib/os/popen.md +70 -0
  26. data/docs/modules.md +38 -0
  27. data/docs/narwhal.md +487 -0
  28. data/docs/packages-howto.md +32 -0
  29. data/docs/packages.md +30 -0
  30. data/docs/posts/2009-07-29-hello-0.1.md +19 -0
  31. data/docs/quick-start.md +69 -0
  32. data/docs/sea.md +49 -0
  33. data/engines/browser/lib/binary.js +2 -0
  34. data/engines/browser/lib/reactor.js +21 -0
  35. data/engines/browser/lib/system.js +3 -0
  36. data/engines/default/lib/array.js +164 -0
  37. data/engines/default/lib/binary-engine.js +53 -0
  38. data/engines/default/lib/binary.js +755 -0
  39. data/engines/default/lib/date.js +8 -0
  40. data/engines/default/lib/file-engine.js +119 -0
  41. data/engines/default/lib/function.js +119 -0
  42. data/engines/default/lib/global.js +11 -0
  43. data/engines/default/lib/io-engine.js +26 -0
  44. data/engines/default/lib/json.js +488 -0
  45. data/engines/default/lib/object.js +69 -0
  46. data/engines/default/lib/os-engine.js +3 -0
  47. data/engines/default/lib/reactor.js +12 -0
  48. data/engines/default/lib/string.js +84 -0
  49. data/engines/default/lib/system.js +20 -0
  50. data/engines/default/lib/worker.js +133 -0
  51. data/engines/jsc/README.md +18 -0
  52. data/engines/jsc/bootstrap.js +53 -0
  53. data/engines/jsc/deps/http-parser/LICENSE +77 -0
  54. data/engines/jsc/deps/http-parser/README.md +145 -0
  55. data/engines/jsc/deps/http-parser/http_parser.c +6087 -0
  56. data/engines/jsc/deps/http-parser/http_parser.h +141 -0
  57. data/engines/jsc/deps/http-parser/http_parser.rl +500 -0
  58. data/engines/jsc/deps/http-parser/test.c +858 -0
  59. data/engines/jsc/include/binary-engine.h +11 -0
  60. data/engines/jsc/include/io-engine.h +23 -0
  61. data/engines/jsc/include/narwhal.h +427 -0
  62. data/engines/jsc/lib/file-engine.js +31 -0
  63. data/engines/jsc/lib/http.js +1 -0
  64. data/engines/jsc/lib/io-engine.js +202 -0
  65. data/engines/jsc/lib/os-engine.js +25 -0
  66. data/engines/jsc/lib/system.js +18 -0
  67. data/engines/jsc/lib/zip.js +1 -0
  68. data/engines/jsc/narwhal-jsc.c +273 -0
  69. data/engines/jsc/narwhal.c +29 -0
  70. data/engines/jsc/package.json +8 -0
  71. data/engines/jsc/src/binary-engine.cc +290 -0
  72. data/engines/jsc/src/file-engine.cc +405 -0
  73. data/engines/jsc/src/io-engine.cc +423 -0
  74. data/engines/jsc/src/jack/handler/jill.cc +710 -0
  75. data/engines/jsc/src/os-engine.cc +210 -0
  76. data/engines/rhino/bin/narwhal-rhino +68 -0
  77. data/engines/rhino/bin/narwhal-rhino.cmd +34 -0
  78. data/engines/rhino/bootstrap.js +119 -0
  79. data/engines/rhino/jars/jline.jar +0 -0
  80. data/engines/rhino/jars/jna.jar +0 -0
  81. data/engines/rhino/jars/js.jar +0 -0
  82. data/engines/rhino/lib/binary-engine.js +83 -0
  83. data/engines/rhino/lib/concurrency.js +6 -0
  84. data/engines/rhino/lib/event-queue.js +18 -0
  85. data/engines/rhino/lib/file-engine.js +216 -0
  86. data/engines/rhino/lib/http-client-engine.js +90 -0
  87. data/engines/rhino/lib/http-engine.js +10 -0
  88. data/engines/rhino/lib/io-engine.js +347 -0
  89. data/engines/rhino/lib/md5-engine.js +40 -0
  90. data/engines/rhino/lib/os-engine.js +150 -0
  91. data/engines/rhino/lib/packages-engine.js +71 -0
  92. data/engines/rhino/lib/sandbox-engine.js +70 -0
  93. data/engines/rhino/lib/system.js +38 -0
  94. data/engines/rhino/lib/worker-engine.js +23 -0
  95. data/engines/rhino/lib/zip.js +78 -0
  96. data/engines/rhino/package.json +4 -0
  97. data/engines/secure/lib/file.js +6 -0
  98. data/engines/secure/lib/system.js +6 -0
  99. data/engines/template/bin/narwhal-engine-name +32 -0
  100. data/engines/template/bootstrap.js +40 -0
  101. data/engines/template/lib/file-engine.js +118 -0
  102. data/engines/template/lib/system.js +17 -0
  103. data/examples/browser-deployment-jackconfig.js +35 -0
  104. data/examples/fibonacci-worker.js +35 -0
  105. data/examples/fibonacci.js +19 -0
  106. data/examples/hello +2 -0
  107. data/examples/narwhal +3 -0
  108. data/examples/not-quite-a-quine.js +1 -0
  109. data/extconf.rb +44 -0
  110. data/gem_bin/narwhal +5 -0
  111. data/gem_bin/sea +4 -0
  112. data/gem_bin/tusk +4 -0
  113. data/lib/args.js +849 -0
  114. data/lib/base16.js +16 -0
  115. data/lib/base64.js +120 -0
  116. data/lib/codec/base64.js +8 -0
  117. data/lib/crc32.js +60 -0
  118. data/lib/file-bootstrap.js +187 -0
  119. data/lib/file.js +659 -0
  120. data/lib/hash.js +28 -0
  121. data/lib/hashp.js +65 -0
  122. data/lib/html.js +16 -0
  123. data/lib/http-client.js +134 -0
  124. data/lib/http.js +17 -0
  125. data/lib/io.js +98 -0
  126. data/lib/jsmin.js +315 -0
  127. data/lib/jsonpath.js +89 -0
  128. data/lib/logger.js +55 -0
  129. data/lib/md4.js +146 -0
  130. data/lib/md5.js +164 -0
  131. data/lib/mime.js +166 -0
  132. data/lib/narwhal.js +102 -0
  133. data/lib/narwhal/client.js +261 -0
  134. data/lib/narwhal/compile.js +99 -0
  135. data/lib/narwhal/env.js +140 -0
  136. data/lib/narwhal/inline.js +106 -0
  137. data/lib/narwhal/json.js +324 -0
  138. data/lib/narwhal/json.md +178 -0
  139. data/lib/narwhal/repl.js +96 -0
  140. data/lib/narwhal/server-test.js +6 -0
  141. data/lib/narwhal/server.js +270 -0
  142. data/lib/narwhal/tusk.js +170 -0
  143. data/lib/narwhal/tusk/bin.js +13 -0
  144. data/lib/narwhal/tusk/bundle.js +0 -0
  145. data/lib/narwhal/tusk/catalog.js +22 -0
  146. data/lib/narwhal/tusk/clone.js +66 -0
  147. data/lib/narwhal/tusk/consolidate.js +25 -0
  148. data/lib/narwhal/tusk/create-catalog.js +80 -0
  149. data/lib/narwhal/tusk/engine.js +42 -0
  150. data/lib/narwhal/tusk/freeze.js +0 -0
  151. data/lib/narwhal/tusk/init.js +56 -0
  152. data/lib/narwhal/tusk/install.js +288 -0
  153. data/lib/narwhal/tusk/list.js +20 -0
  154. data/lib/narwhal/tusk/orphans.js +0 -0
  155. data/lib/narwhal/tusk/reheat.js +15 -0
  156. data/lib/narwhal/tusk/remove.js +15 -0
  157. data/lib/narwhal/tusk/search.js +145 -0
  158. data/lib/narwhal/tusk/update.js +21 -0
  159. data/lib/narwhal/tusk/upgrade.js +0 -0
  160. data/lib/os.js +33 -0
  161. data/lib/packages.js +423 -0
  162. data/lib/printf.js +169 -0
  163. data/lib/promise.js +352 -0
  164. data/lib/querystring.js +176 -0
  165. data/lib/ref-send.js +257 -0
  166. data/lib/regexp.js +12 -0
  167. data/lib/sandbox.js +422 -0
  168. data/lib/sha.js +112 -0
  169. data/lib/sha256.js +102 -0
  170. data/lib/struct.js +228 -0
  171. data/lib/term.js +179 -0
  172. data/lib/test/assert.js +95 -0
  173. data/lib/test/equiv.js +188 -0
  174. data/lib/test/jsdump.js +165 -0
  175. data/lib/test/runner.js +129 -0
  176. data/lib/unload.js +13 -0
  177. data/lib/uri.js +378 -0
  178. data/lib/url.js +5 -0
  179. data/lib/utf8.js +64 -0
  180. data/lib/util.js +985 -0
  181. data/lib/uuid.js +89 -0
  182. data/lib/xregexp.js +521 -0
  183. data/local.json.template +1 -0
  184. data/narwhal.gemspec +105 -0
  185. data/narwhal.js +213 -0
  186. data/package.json +26 -0
  187. data/packages/readline/engines/default/lib/readline.js +4 -0
  188. data/packages/readline/engines/rhino/lib/readline.js +6 -0
  189. data/packages/readline/package.json +5 -0
  190. data/sources.json +207 -0
  191. data/tests/all-tests.js +17 -0
  192. data/tests/args.js +31 -0
  193. data/tests/args/domain.js +215 -0
  194. data/tests/args/options.js +36 -0
  195. data/tests/args/shifting.js +92 -0
  196. data/tests/args/validation.js +31 -0
  197. data/tests/base64.js +23 -0
  198. data/tests/commonjs.js +3 -0
  199. data/tests/commonjs/all-tests.js +12 -0
  200. data/tests/commonjs/bytearray-encodings-tests.js +69 -0
  201. data/tests/commonjs/bytearray-tests.js +465 -0
  202. data/tests/commonjs/bytestring-encodings-tests.js +89 -0
  203. data/tests/commonjs/bytestring-tests.js +263 -0
  204. data/tests/commonjs/es5/all-tests.js +3 -0
  205. data/tests/commonjs/es5/bind.js +29 -0
  206. data/tests/commonjs/file-tests.js +315 -0
  207. data/tests/commonjs/file/dirname.js +31 -0
  208. data/tests/commonjs/file/extension.js +45 -0
  209. data/tests/commonjs/file/is-absolute.js +11 -0
  210. data/tests/commonjs/file/iterator.js +101 -0
  211. data/tests/commonjs/file/normal.js +27 -0
  212. data/tests/commonjs/file/path.js +17 -0
  213. data/tests/commonjs/file/relative.js +42 -0
  214. data/tests/commonjs/file/resolve.js +44 -0
  215. data/tests/commonjs/module-tests.js +9 -0
  216. data/tests/commonjs/modules/absolute/b.js +1 -0
  217. data/tests/commonjs/modules/absolute/program.js +5 -0
  218. data/tests/commonjs/modules/absolute/submodule/a.js +3 -0
  219. data/tests/commonjs/modules/absolute/test.js +9 -0
  220. data/tests/commonjs/modules/all-tests.js +47 -0
  221. data/tests/commonjs/modules/config.js +11 -0
  222. data/tests/commonjs/modules/cyclic/a.js +4 -0
  223. data/tests/commonjs/modules/cyclic/b.js +4 -0
  224. data/tests/commonjs/modules/cyclic/program.js +10 -0
  225. data/tests/commonjs/modules/cyclic/test.js +9 -0
  226. data/tests/commonjs/modules/determinism/program.js +3 -0
  227. data/tests/commonjs/modules/determinism/submodule/a.js +8 -0
  228. data/tests/commonjs/modules/determinism/submodule/b.js +2 -0
  229. data/tests/commonjs/modules/determinism/test.js +9 -0
  230. data/tests/commonjs/modules/exactExports/a.js +3 -0
  231. data/tests/commonjs/modules/exactExports/program.js +4 -0
  232. data/tests/commonjs/modules/exactExports/test.js +9 -0
  233. data/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js +0 -0
  234. data/tests/commonjs/modules/hasOwnProperty/program.js +3 -0
  235. data/tests/commonjs/modules/hasOwnProperty/test.js +9 -0
  236. data/tests/commonjs/modules/hasOwnProperty/toString.js +0 -0
  237. data/tests/commonjs/modules/method/a.js +12 -0
  238. data/tests/commonjs/modules/method/program.js +8 -0
  239. data/tests/commonjs/modules/method/test.js +9 -0
  240. data/tests/commonjs/modules/missing/program.js +8 -0
  241. data/tests/commonjs/modules/missing/test.js +9 -0
  242. data/tests/commonjs/modules/monkeys/a.js +1 -0
  243. data/tests/commonjs/modules/monkeys/program.js +4 -0
  244. data/tests/commonjs/modules/monkeys/test.js +9 -0
  245. data/tests/commonjs/modules/nested/a/b/c/d.js +3 -0
  246. data/tests/commonjs/modules/nested/program.js +3 -0
  247. data/tests/commonjs/modules/nested/test.js +9 -0
  248. data/tests/commonjs/modules/relative/program.js +5 -0
  249. data/tests/commonjs/modules/relative/submodule/a.js +1 -0
  250. data/tests/commonjs/modules/relative/submodule/b.js +2 -0
  251. data/tests/commonjs/modules/relative/test.js +9 -0
  252. data/tests/commonjs/modules/transitive/a.js +1 -0
  253. data/tests/commonjs/modules/transitive/b.js +1 -0
  254. data/tests/commonjs/modules/transitive/c.js +3 -0
  255. data/tests/commonjs/modules/transitive/program.js +3 -0
  256. data/tests/commonjs/modules/transitive/test.js +9 -0
  257. data/tests/file/all-tests.js +61 -0
  258. data/tests/file/fnmatch.js +102 -0
  259. data/tests/file/glob.js +466 -0
  260. data/tests/file/match.js +102 -0
  261. data/tests/global.js +6 -0
  262. data/tests/global/array.js +19 -0
  263. data/tests/hashes.js +94 -0
  264. data/tests/html.js +13 -0
  265. data/tests/io/stringio.js +21 -0
  266. data/tests/os/all-tests.js +4 -0
  267. data/tests/os/popen.js +41 -0
  268. data/tests/os/system.js +22 -0
  269. data/tests/printf.js +123 -0
  270. data/tests/query-string.js +87 -0
  271. data/tests/sandbox/byte-io.js +20 -0
  272. data/tests/sandbox/fileName.js +3 -0
  273. data/tests/sandbox/foo.js +0 -0
  274. data/tests/sandbox/reload.js +79 -0
  275. data/tests/string.js +35 -0
  276. data/tests/uri.js +41 -0
  277. data/tests/util/all-tests.js +79 -0
  278. data/tests/util/array.js +207 -0
  279. data/tests/util/array/is-arguments.js +29 -0
  280. data/tests/util/array/is-array-like.js +29 -0
  281. data/tests/util/case.js +9 -0
  282. data/tests/util/collection.js +104 -0
  283. data/tests/util/eq.js +57 -0
  284. data/tests/util/expand.js +45 -0
  285. data/tests/util/object.js +125 -0
  286. data/tests/util/operator.js +25 -0
  287. data/tests/util/range.js +19 -0
  288. data/tests/util/repr.js +26 -0
  289. data/tests/util/string.js +34 -0
  290. data/tests/util/unique.js +12 -0
  291. metadata +434 -0
@@ -0,0 +1,95 @@
1
+ var equiv = require("./equiv").equiv,
2
+ jsDump = require("./jsdump").jsDump,
3
+ util = require("../util");
4
+
5
+ var assert = exports;
6
+
7
+ function fail(message) {
8
+ throw new AssertionError(message);
9
+ }
10
+
11
+ assert.isTrue = function(assertion, message) {
12
+ if (assertion !== true)
13
+ fail((message || "") + "\nExpected true." +
14
+ "\nActual = " + assertion);
15
+ }
16
+
17
+ assert.isFalse = function(assertion, message) {
18
+ if (assertion !== false)
19
+ fail((message || "") + "\nExpected false." +
20
+ "\nActual = " + assertion);
21
+ }
22
+
23
+ assert.isNull = function(assertion, message) {
24
+ if (assertion !== null)
25
+ fail((message || "") + "\nExpected null." +
26
+ "\nActual = " + assertion);
27
+ }
28
+
29
+ assert.isNaN = function(assertion, message) {
30
+ if (!isNaN(assertion))
31
+ fail((message || "") + "\nExpected NaN." +
32
+ "\nActual = " + assertion);
33
+ }
34
+
35
+ assert.isEqual = function(expected, actual, message) {
36
+ if (expected !== actual)
37
+ fail((message || "") + "\nExpected equal to = " + jsDump.parse(expected) +
38
+ "\nActual = " + jsDump.parse(actual));
39
+ }
40
+
41
+ assert.is = function (expected, actual, message) {
42
+ if (!util.is(expected, actual))
43
+ fail((message || "") + "\nExpected identical = " + jsDump.parse(expected) +
44
+ "\nActual = " + jsDump.parse(actual));
45
+ };
46
+
47
+ assert.isSame = function(expected, actual, message) {
48
+ if (!equiv(expected, actual))
49
+ fail((message || "") + "\nExpected same as = " + jsDump.parse(expected) +
50
+ "\nActual = " + jsDump.parse(actual));
51
+ }
52
+
53
+ assert.eq = function (expected, actual, message) {
54
+ if (!util.eq(expected, actual))
55
+ fail((message || "") + "\nExpected equal = " + jsDump.parse(expected) +
56
+ "\nActual = " + jsDump.parse(actual));
57
+ };
58
+
59
+
60
+ assert.isDiff = function(expected, actual, message) {
61
+ if (equiv(expected, actual))
62
+ fail((message || "") + "\nExpected different than = " + jsDump.parse(expected) +
63
+ "\nActual = " + jsDump.parse(actual));
64
+ }
65
+
66
+ assert.throwsError = function(block, type, message) {
67
+ var threw = false,
68
+ exception = null;
69
+
70
+ try {
71
+ block();
72
+ } catch (e) {
73
+ threw = true;
74
+ exception = e;
75
+ }
76
+
77
+ if (!threw)
78
+ fail("Expected exception" + (message ? ": " + message : ""));
79
+
80
+ if (type !== undefined && !(exception instanceof type))
81
+ fail("Expected exception type '"+type+
82
+ "', actually '"+exception+"'" + (message ? ": " + message : ""));
83
+ }
84
+
85
+
86
+ var AssertionError = exports.AssertionError = function(message) {
87
+ this.name = "AssertionError";
88
+ this.message = message;
89
+
90
+ // this lets us get a stack trace in Rhino
91
+ if (typeof Packages !== "undefined")
92
+ this.rhinoException = Packages.org.mozilla.javascript.JavaScriptException(this, null, 0);
93
+ }
94
+
95
+ AssertionError.prototype = new Error();
data/lib/test/equiv.js ADDED
@@ -0,0 +1,188 @@
1
+ // Hoozit
2
+ // Determine what is o.
3
+ function hoozit(o) {
4
+ if (typeof o === "string") {
5
+ return "string";
6
+
7
+ } else if (typeof o === "boolean") {
8
+ return "boolean";
9
+
10
+ } else if (typeof o === "number") {
11
+
12
+ if (isNaN(o)) {
13
+ return "nan";
14
+ } else {
15
+ return "number";
16
+ }
17
+
18
+ } else if (typeof o === "undefined") {
19
+ return "undefined";
20
+
21
+ // consider: typeof null === object
22
+ } else if (o === null) {
23
+ return "null";
24
+
25
+ // consider: typeof [] === object
26
+ } else if (o instanceof Array) {
27
+ return "array";
28
+
29
+ // consider: typeof new Date() === object
30
+ } else if (o instanceof Date) {
31
+ return "date";
32
+
33
+ // consider: /./ instanceof Object;
34
+ // /./ instanceof RegExp;
35
+ // typeof /./ === "function"; // => false in IE and Opera,
36
+ // true in FF and Safari
37
+ } else if (o instanceof RegExp) {
38
+ return "regexp";
39
+
40
+ } else if (typeof o === "object") {
41
+ return "object";
42
+
43
+ } else if (o instanceof Function) {
44
+ return "function";
45
+ }
46
+ }
47
+
48
+ // Call the o related callback with the given arguments.
49
+ function bindCallbacks(o, callbacks, args) {
50
+ var prop = hoozit(o);
51
+ if (prop) {
52
+ if (hoozit(callbacks[prop]) === "function") {
53
+ return callbacks[prop].apply(callbacks, args);
54
+ } else {
55
+ return callbacks[prop]; // or undefined
56
+ }
57
+ }
58
+ }
59
+
60
+ // Equiv
61
+ // Test for equality any JavaScript type.
62
+ // Discussions and reference: http://philrathe.com/articles/equiv
63
+ // Test suites: http://philrathe.com/tests/equiv
64
+ // Author: Philippe Rathé <prathe@gmail.com>
65
+ var equiv = exports.equiv = function () {
66
+
67
+ var innerEquiv; // the real equiv function
68
+ var callers = []; // stack to decide between skip/abort functions
69
+
70
+
71
+ var callbacks = function () {
72
+
73
+ // for string, boolean, number and null
74
+ function useStrictEquality(b, a) {
75
+ return a === b;
76
+ }
77
+
78
+ return {
79
+ "string": useStrictEquality,
80
+ "boolean": useStrictEquality,
81
+ "number": useStrictEquality,
82
+ "null": useStrictEquality,
83
+ "undefined": useStrictEquality,
84
+
85
+ "nan": function (b) {
86
+ return isNaN(b);
87
+ },
88
+
89
+ "date": function (b, a) {
90
+ return hoozit(b) === "date" && a.valueOf() === b.valueOf();
91
+ },
92
+
93
+ "regexp": function (b, a) {
94
+ return hoozit(b) === "regexp" &&
95
+ a.source === b.source && // the regex itself
96
+ a.global === b.global && // and its modifers (gmi) ...
97
+ a.ignoreCase === b.ignoreCase &&
98
+ a.multiline === b.multiline;
99
+ },
100
+
101
+ // - skip when the property is a method of an instance (OOP)
102
+ // - abort otherwise,
103
+ // initial === would have catch identical references anyway
104
+ "function": function () {
105
+ var caller = callers[callers.length - 1];
106
+ return caller !== Object &&
107
+ typeof caller !== "undefined";
108
+ },
109
+
110
+ "array": function (b, a) {
111
+ var i;
112
+ var len;
113
+
114
+ // b could be an object literal here
115
+ if ( ! (hoozit(b) === "array")) {
116
+ return false;
117
+ }
118
+
119
+ len = a.length;
120
+ if (len !== b.length) { // safe and faster
121
+ return false;
122
+ }
123
+ for (i = 0; i < len; i++) {
124
+ if( ! innerEquiv(a[i], b[i])) {
125
+ return false;
126
+ }
127
+ }
128
+ return true;
129
+ },
130
+
131
+ "object": function (b, a) {
132
+ var i;
133
+ var eq = true; // unless we can proove it
134
+ var aProperties = [], bProperties = []; // collection of strings
135
+
136
+ // comparing constructors is more strict than using instanceof
137
+ if ( a.constructor !== b.constructor) {
138
+ return false;
139
+ }
140
+
141
+ // stack constructor before traversing properties
142
+ callers.push(a.constructor);
143
+
144
+ for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
145
+
146
+ aProperties.push(i); // collect a's properties
147
+
148
+ if ( ! innerEquiv(a[i], b[i])) {
149
+ eq = false;
150
+ }
151
+ }
152
+
153
+ callers.pop(); // unstack, we are done
154
+
155
+ for (i in b) {
156
+ bProperties.push(i); // collect b's properties
157
+ }
158
+
159
+ // Ensures identical properties name
160
+ return eq && innerEquiv(aProperties.sort(), bProperties.sort());
161
+ }
162
+ };
163
+ }();
164
+
165
+ innerEquiv = function () { // can take multiple arguments
166
+ var args = Array.prototype.slice.apply(arguments);
167
+ if (args.length < 2) {
168
+ return true; // end transition
169
+ }
170
+
171
+ return (function (a, b) {
172
+ if (a === b) {
173
+ return true; // catch the most you can
174
+
175
+ } else if (typeof a !== typeof b || a === null || b === null || typeof a === "undefined" || typeof b === "undefined") {
176
+ return false; // don't lose time with error prone cases
177
+
178
+ } else {
179
+ return bindCallbacks(a, callbacks, [b, a]);
180
+ }
181
+
182
+ // apply transition with (1..n) arguments
183
+ })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1));
184
+ };
185
+
186
+ return innerEquiv;
187
+
188
+ }();
@@ -0,0 +1,165 @@
1
+ /**
2
+ * jsDump
3
+ * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
4
+ * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)
5
+ * Date: 5/15/2008
6
+ * @projectDescription Advanced and extensible data dumping for Javascript.
7
+ * @version 1.0.0
8
+ * @author Ariel Flesler
9
+ */
10
+ var jsDump;
11
+
12
+ (function(){
13
+ function quote( str ){
14
+ return '"' + str.toString().replace(/"/g, '\\"') + '"';
15
+ };
16
+ function literal( o ){
17
+ return o + '';
18
+ };
19
+ function join( pre, arr, post ){
20
+ var s = jsDump.separator(),
21
+ base = jsDump.indent(),
22
+ inner = jsDump.indent(1);
23
+ if( arr.join )
24
+ arr = arr.join( ',' + s + inner );
25
+ if( !arr )
26
+ return pre + post;
27
+ return [ pre, inner + arr, base + post ].join(s);
28
+ };
29
+ function array( arr ){
30
+ var i = arr.length, ret = Array(i);
31
+ this.up();
32
+ while( i-- )
33
+ ret[i] = this.parse( arr[i] );
34
+ this.down();
35
+ return join( '[', ret, ']' );
36
+ };
37
+
38
+ var reName = /^function (\w+)/;
39
+
40
+ jsDump = {
41
+ parse:function( obj, type ){//type is used mostly internally, you can fix a (custom)type in advance
42
+ var parser = this.parsers[ type || this.typeOf(obj) ];
43
+ type = typeof parser;
44
+
45
+ return type == 'function' ? parser.call( this, obj ) :
46
+ type == 'string' ? parser :
47
+ this.parsers.error;
48
+ },
49
+ typeOf:function( obj ){
50
+ var type = typeof obj,
51
+ f = 'function';//we'll use it 3 times, save it
52
+ return type != 'object' && type != f ? type :
53
+ !obj ? 'null' :
54
+ obj.exec ? 'regexp' :// some browsers (FF) consider regexps functions
55
+ obj.getHours ? 'date' :
56
+ obj.scrollBy ? 'window' :
57
+ obj.nodeName == '#document' ? 'document' :
58
+ obj.nodeName ? 'node' :
59
+ obj.item ? 'nodelist' : // Safari reports nodelists as functions
60
+ obj.callee ? 'arguments' :
61
+ obj.call || obj.constructor != Array && //an array would also fall on this hack
62
+ (obj+'').indexOf(f) != -1 ? f : //IE reports functions like alert, as objects
63
+ 'length' in obj ? 'array' :
64
+ type;
65
+ },
66
+ separator:function(){
67
+ return this.multiline ? this.HTML ? '<br />' : '\n' : this.HTML ? '&nbsp;' : ' ';
68
+ },
69
+ indent:function( extra ){// extra can be a number, shortcut for increasing-calling-decreasing
70
+ if( !this.multiline )
71
+ return '';
72
+ var chr = this.indentChar;
73
+ if( this.HTML )
74
+ chr = chr.replace(/\t/g,' ').replace(/ /g,'&nbsp;');
75
+ return Array( this._depth_ + (extra||0) ).join(chr);
76
+ },
77
+ up:function( a ){
78
+ this._depth_ += a || 1;
79
+ },
80
+ down:function( a ){
81
+ this._depth_ -= a || 1;
82
+ },
83
+ setParser:function( name, parser ){
84
+ this.parsers[name] = parser;
85
+ },
86
+ // The next 3 are exposed so you can use them
87
+ quote:quote,
88
+ literal:literal,
89
+ join:join,
90
+ //
91
+ _depth_: 1,
92
+ // This is the list of parsers, to modify them, use jsDump.setParser
93
+ parsers:{
94
+ window: '[Window]',
95
+ document: '[Document]',
96
+ error:'[ERROR]', //when no parser is found, shouldn't happen
97
+ unknown: '[Unknown]',
98
+ 'null':'null',
99
+ undefined:'undefined',
100
+ 'function':function( fn ){
101
+ var ret = 'function',
102
+ name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE
103
+ if( name )
104
+ ret += ' ' + name;
105
+ ret += '(';
106
+
107
+ ret = [ ret, this.parse( fn, 'functionArgs' ), '){'].join('');
108
+ return join( ret, this.parse(fn,'functionCode'), '}' );
109
+ },
110
+ array: array,
111
+ nodelist: array,
112
+ arguments: array,
113
+ object:function( map ){
114
+ var ret = [ ];
115
+ this.up();
116
+ for( var key in map )
117
+ ret.push( this.parse(key,'key') + ': ' + this.parse(map[key]) );
118
+ this.down();
119
+ return join( '{', ret, '}' );
120
+ },
121
+ node:function( node ){
122
+ var open = this.HTML ? '&lt;' : '<',
123
+ close = this.HTML ? '&gt;' : '>';
124
+
125
+ var tag = node.nodeName.toLowerCase(),
126
+ ret = open + tag;
127
+
128
+ for( var a in this.DOMAttrs ){
129
+ var val = node[this.DOMAttrs[a]];
130
+ if( val )
131
+ ret += ' ' + a + '=' + this.parse( val, 'attribute' );
132
+ }
133
+ return ret + close + open + '/' + tag + close;
134
+ },
135
+ functionArgs:function( fn ){//function calls it internally, it's the arguments part of the function
136
+ var l = fn.length;
137
+ if( !l ) return '';
138
+
139
+ var args = Array(l);
140
+ while( l-- )
141
+ args[l] = String.fromCharCode(97+l);//97 is 'a'
142
+ return ' ' + args.join(', ') + ' ';
143
+ },
144
+ key:quote, //object calls it internally, the key part of an item in a map
145
+ functionCode:'[code]', //function calls it internally, it's the content of the function
146
+ attribute:quote, //onode calls it internally, it's an html attribute value
147
+ string:quote,
148
+ date:quote,
149
+ regexp:literal, //regex
150
+ number:literal,
151
+ 'boolean':literal
152
+ },
153
+ DOMAttrs:{//attributes to dump from nodes, name=>realName
154
+ id:'id',
155
+ name:'name',
156
+ 'class':'className'
157
+ },
158
+ HTML:false,//if true, entities are escaped ( <, >, \t, space and \n )
159
+ indentChar:' ',//indentation unit
160
+ multiline:true //if true, items in a collection, are separated by a \n, else just a space.
161
+ };
162
+
163
+ })();
164
+
165
+ exports.jsDump = jsDump;