envjs19 0.3.8.20101029121421

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. data/.jslintrbrc +30 -0
  2. data/.project +17 -0
  3. data/CHANGELOG.rdoc +57 -0
  4. data/DTD/xhtml-lat1.ent +196 -0
  5. data/DTD/xhtml-special.ent +80 -0
  6. data/DTD/xhtml-symbol.ent +237 -0
  7. data/DTD/xhtml.soc +14 -0
  8. data/DTD/xhtml1-frameset.dtd +1235 -0
  9. data/DTD/xhtml1-strict.dtd +978 -0
  10. data/DTD/xhtml1-transitional.dtd +1201 -0
  11. data/DTD/xhtml1.dcl +192 -0
  12. data/Makefile +7 -0
  13. data/Manifest.txt +280 -0
  14. data/README.rdoc +65 -0
  15. data/Rakefile +196 -0
  16. data/Wakefile +11 -0
  17. data/bin/envjsrb +257 -0
  18. data/build.properties +9 -0
  19. data/build.xml +247 -0
  20. data/gm/jquery.js +6002 -0
  21. data/gm/mainx.js +2648 -0
  22. data/gm/sensx.js +135 -0
  23. data/gm/t.js +6 -0
  24. data/gm/x.html +76 -0
  25. data/htmlparser/BrowserTreeBuilder.java +456 -0
  26. data/htmlparser/README +34 -0
  27. data/htmlparser/build.sh +38 -0
  28. data/jsl/jsl +0 -0
  29. data/jsl/jsl.default.conf +129 -0
  30. data/jsl/jsl.exe +0 -0
  31. data/lib/envjs.rb +35 -0
  32. data/lib/envjs/event_loop.js +206 -0
  33. data/lib/envjs/net.rb +3 -0
  34. data/lib/envjs/net/cgi.rb +94 -0
  35. data/lib/envjs/net/file.rb +69 -0
  36. data/lib/envjs/options.rb +11 -0
  37. data/lib/envjs/runtime.rb +346 -0
  38. data/lib/envjs/tempfile.rb +24 -0
  39. data/licenses/GPL-LICENSE.txt +278 -0
  40. data/licenses/MIT-LICENSE.txt +20 -0
  41. data/src/base64.js +80 -0
  42. data/src/build.js +6 -0
  43. data/src/cruft/bad.html +24 -0
  44. data/src/cruft/dom.js +606 -0
  45. data/src/cruft/element.js +297 -0
  46. data/src/cruft/good.html +30 -0
  47. data/src/cruft/good.js +32 -0
  48. data/src/cruft/internal.js +81 -0
  49. data/src/cruft/parser.js +458 -0
  50. data/src/css/properties.js +293 -0
  51. data/src/css/rule.js +22 -0
  52. data/src/css/sizzle.js +717 -0
  53. data/src/css/stylesheet.js +52 -0
  54. data/src/dom/attr.js +55 -0
  55. data/src/dom/cdatasection.js +31 -0
  56. data/src/dom/characterdata.js +119 -0
  57. data/src/dom/comment.js +30 -0
  58. data/src/dom/doctype.js +9 -0
  59. data/src/dom/document.js +1023 -0
  60. data/src/dom/dom.js +134 -0
  61. data/src/dom/element.js +217 -0
  62. data/src/dom/entities.js +273 -0
  63. data/src/dom/exception.js +28 -0
  64. data/src/dom/fragment.js +37 -0
  65. data/src/dom/implementation.js +140 -0
  66. data/src/dom/instruction.js +51 -0
  67. data/src/dom/namednodemap.js +374 -0
  68. data/src/dom/namespace.js +50 -0
  69. data/src/dom/node.js +618 -0
  70. data/src/dom/nodelist.js +195 -0
  71. data/src/dom/parser.js +1207 -0
  72. data/src/dom/text.js +73 -0
  73. data/src/event/event.js +47 -0
  74. data/src/event/mouseevent.js +4 -0
  75. data/src/event/uievent.js +8 -0
  76. data/src/html/a.js +110 -0
  77. data/src/html/anchor.js +80 -0
  78. data/src/html/area.js +57 -0
  79. data/src/html/base.js +26 -0
  80. data/src/html/blockquote-q.js +19 -0
  81. data/src/html/body.js +19 -0
  82. data/src/html/button.js +21 -0
  83. data/src/html/canvas.js +14 -0
  84. data/src/html/col-colgroup.js +49 -0
  85. data/src/html/collection.js +72 -0
  86. data/src/html/cookie.js +153 -0
  87. data/src/html/del-ins.js +25 -0
  88. data/src/html/div.js +28 -0
  89. data/src/html/document.js +364 -0
  90. data/src/html/element.js +382 -0
  91. data/src/html/fieldset.js +19 -0
  92. data/src/html/form.js +484 -0
  93. data/src/html/frame.js +89 -0
  94. data/src/html/frameset.js +25 -0
  95. data/src/html/head.js +44 -0
  96. data/src/html/html.js +0 -0
  97. data/src/html/htmlparser.js +340 -0
  98. data/src/html/iframe.js +26 -0
  99. data/src/html/image.js +0 -0
  100. data/src/html/img.js +62 -0
  101. data/src/html/input-elements.js +307 -0
  102. data/src/html/input.js +65 -0
  103. data/src/html/label.js +26 -0
  104. data/src/html/legend.js +19 -0
  105. data/src/html/link.js +82 -0
  106. data/src/html/map.js +22 -0
  107. data/src/html/meta.js +37 -0
  108. data/src/html/object.js +89 -0
  109. data/src/html/optgroup.js +25 -0
  110. data/src/html/option.js +103 -0
  111. data/src/html/param.js +38 -0
  112. data/src/html/script.js +122 -0
  113. data/src/html/select.js +132 -0
  114. data/src/html/style.js +31 -0
  115. data/src/html/table.js +199 -0
  116. data/src/html/tbody-thead-tfoot.js +92 -0
  117. data/src/html/td-th.js +18 -0
  118. data/src/html/textarea.js +31 -0
  119. data/src/html/title.js +20 -0
  120. data/src/html/tr.js +114 -0
  121. data/src/intro.js +141 -0
  122. data/src/outro.js +70 -0
  123. data/src/parser/html5.detailed.js +10762 -0
  124. data/src/parser/html5.min.js +503 -0
  125. data/src/parser/html5.pretty.js +10815 -0
  126. data/src/parser/intro.js +42 -0
  127. data/src/parser/outro.js +9 -0
  128. data/src/platform/core.js +323 -0
  129. data/src/platform/johnson.js +484 -0
  130. data/src/platform/rhino.js +327 -0
  131. data/src/platform/static/intro.js +41 -0
  132. data/src/platform/static/outro.js +30 -0
  133. data/src/profile/aop.js +238 -0
  134. data/src/profile/profile.js +402 -0
  135. data/src/serializer/xml.js +21 -0
  136. data/src/svg/animatedstring.js +25 -0
  137. data/src/svg/document.js +25 -0
  138. data/src/svg/element.js +22 -0
  139. data/src/svg/locatable.js +17 -0
  140. data/src/svg/rect.js +18 -0
  141. data/src/svg/rectelement.js +24 -0
  142. data/src/svg/stylable.js +49 -0
  143. data/src/svg/svgelement.js +22 -0
  144. data/src/svg/transformable.js +15 -0
  145. data/src/window/css.js +15 -0
  146. data/src/window/dialog.js +16 -0
  147. data/src/window/document.js +28 -0
  148. data/src/window/event.js +265 -0
  149. data/src/window/history.js +62 -0
  150. data/src/window/location.js +156 -0
  151. data/src/window/navigator.js +48 -0
  152. data/src/window/screen.js +53 -0
  153. data/src/window/timer.js +21 -0
  154. data/src/window/window.js +284 -0
  155. data/src/window/xhr.js +135 -0
  156. data/src/xpath/expression.js +49 -0
  157. data/src/xpath/implementation.js +2505 -0
  158. data/src/xpath/result.js +67 -0
  159. data/src/xpath/util.js +551 -0
  160. data/src/xpath/xmltoken.js +149 -0
  161. data/src/xslt/COPYING +34 -0
  162. data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
  163. data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
  164. data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
  165. data/src/xslt/ajaxslt-0.8.1/README +102 -0
  166. data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
  167. data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
  168. data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
  169. data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
  170. data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
  171. data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
  172. data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
  173. data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
  174. data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
  175. data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
  176. data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
  177. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
  178. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
  179. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
  180. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
  181. data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
  182. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
  183. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
  184. data/src/xslt/implementation.js +625 -0
  185. data/src/xslt/processor.js +37 -0
  186. data/src/xslt/util.js +449 -0
  187. data/test/base64.js +80 -0
  188. data/test/call-load-test.js +15 -0
  189. data/test/data.js +45 -0
  190. data/test/debug.js +53 -0
  191. data/test/firebug/errorIcon.png +0 -0
  192. data/test/firebug/firebug.css +209 -0
  193. data/test/firebug/firebug.html +23 -0
  194. data/test/firebug/firebug.js +672 -0
  195. data/test/firebug/firebugx.js +10 -0
  196. data/test/firebug/infoIcon.png +0 -0
  197. data/test/firebug/warningIcon.png +0 -0
  198. data/test/fixtures/html/events.html +171 -0
  199. data/test/fixtures/html/iframe1.html +46 -0
  200. data/test/fixtures/html/iframe1a.html +46 -0
  201. data/test/fixtures/html/iframe2.html +45 -0
  202. data/test/fixtures/html/iframe3.html +28 -0
  203. data/test/fixtures/html/iframeN.html +57 -0
  204. data/test/fixtures/html/malformed.html +181 -0
  205. data/test/fixtures/html/scope.html +81 -0
  206. data/test/fixtures/html/trivial.html +19 -0
  207. data/test/fixtures/html/with_js.html +26 -0
  208. data/test/fixtures/images/icon-blue.png +0 -0
  209. data/test/fixtures/js/external_script.js +1 -0
  210. data/test/fixtures/js/script.js +1 -0
  211. data/test/fixtures/js/script_error.js +2 -0
  212. data/test/foo.html +8 -0
  213. data/test/foo.js +40 -0
  214. data/test/html/events.html +171 -0
  215. data/test/html/iframe1.html +46 -0
  216. data/test/html/iframe1a.html +46 -0
  217. data/test/html/iframe2.html +45 -0
  218. data/test/html/iframe3.html +30 -0
  219. data/test/html/iframeN.html +57 -0
  220. data/test/html/malformed.html +181 -0
  221. data/test/html/scope.html +87 -0
  222. data/test/html/script.js +1 -0
  223. data/test/html/trivial.html +19 -0
  224. data/test/html/with_js.html +26 -0
  225. data/test/index.html +328 -0
  226. data/test/java-prototype.js +9 -0
  227. data/test/jquery.js +6002 -0
  228. data/test/primary-tests.js +26 -0
  229. data/test/prototype-test.js +13 -0
  230. data/test/qunit.js +61 -0
  231. data/test/qunit/qunit/qunit.css +17 -0
  232. data/test/qunit/qunit/qunit.js +997 -0
  233. data/test/scope.html +19 -0
  234. data/test/scope.rb +24 -0
  235. data/test/smp/dmathieu/index.html +8 -0
  236. data/test/specs/dist/env.spec.js +1534 -0
  237. data/test/specs/envjs.spec.css +46 -0
  238. data/test/specs/parser/html.js +31 -0
  239. data/test/specs/parser/spec.html +40 -0
  240. data/test/specs/parser/xml.js +31 -0
  241. data/test/specs/qunit.bdd.js +210 -0
  242. data/test/specs/qunit.css +17 -0
  243. data/test/specs/qunit.js +997 -0
  244. data/test/specs/template/spec-0.js +31 -0
  245. data/test/specs/template/spec-1.js +31 -0
  246. data/test/specs/template/spec.html +40 -0
  247. data/test/specs/window/css.js +23 -0
  248. data/test/specs/window/dialog.js +25 -0
  249. data/test/specs/window/document.js +23 -0
  250. data/test/specs/window/event.js +25 -0
  251. data/test/specs/window/history.js +34 -0
  252. data/test/specs/window/location.js +34 -0
  253. data/test/specs/window/navigator.js +71 -0
  254. data/test/specs/window/screen.js +42 -0
  255. data/test/specs/window/spec.html +48 -0
  256. data/test/specs/window/timer.js +26 -0
  257. data/test/specs/window/window.js +53 -0
  258. data/test/specs/xhr/spec.html +47 -0
  259. data/test/specs/xhr/xhr.js +31 -0
  260. data/test/test.js +10 -0
  261. data/test/unit/dom.js +44 -0
  262. data/test/unit/elementmembers.js +92 -0
  263. data/test/unit/events.js +195 -0
  264. data/test/unit/fixtures/external_script.js +1 -0
  265. data/test/unit/form.js +40 -0
  266. data/test/unit/iframe.js +234 -0
  267. data/test/unit/insertion.js +23 -0
  268. data/test/unit/multi-window.js +212 -0
  269. data/test/unit/nu.validator.js +34 -0
  270. data/test/unit/onload.js +90 -0
  271. data/test/unit/parser.js +122 -0
  272. data/test/unit/prototypecompat.js +22 -0
  273. data/test/unit/proxy.js +6 -0
  274. data/test/unit/scope.js +209 -0
  275. data/test/unit/timer.js +115 -0
  276. data/test/unit/window.js +57 -0
  277. data/test/x.js +1 -0
  278. data/test/y.js +1 -0
  279. metadata +367 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @author thatcher
3
+ */
4
+
5
+ (function(/*window,document*/){
6
+
7
+ var Html5Parser;
8
+
9
+ var psettimeout;
10
+
11
+ var sync = function(window,parser){
12
+ parser.ptimeouts = [];
13
+ parser.pschedule = function($schedule,timer,t) {
14
+ var old = psettimeout;
15
+ psettimeout = function(fn){
16
+ parser.ptimeouts.push(fn);
17
+ };
18
+ $schedule(window,timer,t);
19
+ psettimeout = old;
20
+ };
21
+ parser.pwait = function() {
22
+ var fn;
23
+ while ((fn = parser.ptimeouts.pop())) {
24
+ fn();
25
+ };
26
+ };
27
+ };
28
+
29
+ var async = function(window,parser) {
30
+ delete parser.ptimeouts;
31
+ parser.pschedule = function($schedule,timer,t) {
32
+ var old = psettimeout;
33
+ psettimeout = window.setTimeout;
34
+ $schedule(window,timer,t);
35
+ psettimeout = old;
36
+ };
37
+ parser.pwait = function(){
38
+ // $master.print("wait called");
39
+ window.$envx.wait(-1);
40
+ // $master.print("after wait");
41
+ };
42
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @author thatcher
3
+ */
4
+
5
+ envjs_init_5 = function() {
6
+ Html5Parser();
7
+ };
8
+
9
+ })();
@@ -0,0 +1,323 @@
1
+
2
+ /**
3
+ * @author thatcher
4
+ */
5
+ var Envjs = function(){
6
+ if(arguments.length === 2){
7
+ for ( var i in arguments[1] ) {
8
+ var g = arguments[1].__lookupGetter__(i),
9
+ s = arguments[1].__lookupSetter__(i);
10
+ if ( g || s ) {
11
+ if ( g ) { Envjs.__defineGetter__(i, g); }
12
+ if ( s ) { Envjs.__defineSetter__(i, s); }
13
+ } else {
14
+ Envjs[i] = arguments[1][i];
15
+ }
16
+ }
17
+ }
18
+
19
+ if (arguments[0] !== null && arguments[0] !== "") {
20
+ window.location = arguments[0];
21
+ }
22
+ };
23
+
24
+ /*
25
+ * core.js
26
+ */
27
+ (function($env){
28
+
29
+ //You can emulate different user agents by overriding these after loading env
30
+ $env.appCodeName = "Envjs";//eg "Mozilla"
31
+ $env.appName = "Resig/20070309 BirdDog/0.0.0.1";//eg "Gecko/20070309 Firefox/2.0.0.3"
32
+
33
+ //set this to true and see profile/profile.js to select which methods
34
+ //to profile
35
+ $env.profile = false;
36
+
37
+ $env.log = $env.log || function(msg, level){};
38
+
39
+ $env.DEBUG = 4;
40
+ $env.INFO = 3;
41
+ $env.WARN = 2;
42
+ $env.ERROR = 1;
43
+ $env.NONE = 0;
44
+
45
+ //set this if you want to get some internal log statements
46
+ $env.logLevel = $env.INFO;
47
+ $env.logLevel = $env.ERROR;
48
+ $env.logLevel = $env.DEBUG;
49
+ $env.logLevel = $env.WARN;
50
+
51
+ $env.debug = function(msg){
52
+ if($env.logLevel >= $env.DEBUG) {
53
+ $env.log(msg,"DEBUG");
54
+ }
55
+ };
56
+ $env.info = function(msg){
57
+ if($env.logLevel >= $env.INFO) {
58
+ $env.log(msg,"INFO");
59
+ }
60
+ };
61
+ $env.warn = function(msg){
62
+ if($env.logLevel >= $env.WARN) {
63
+ $env.log(msg,"WARNIING");
64
+ }
65
+ };
66
+ $env.error = function(msg, e){
67
+ if ($env.logLevel >= $env.ERROR) {
68
+ var line = $env.lineSource(e);
69
+ if ( line !== "" ) { line = " Line: "+ line ;}
70
+ $env.log(msg + line, 'ERROR');
71
+ if(e) {
72
+ $env.log(e || "", 'ERROR');
73
+ }
74
+ }
75
+ };
76
+
77
+ $env.debug("Initializing Core Platform Env");
78
+
79
+
80
+ // if we're running in an environment without env.js' custom extensions
81
+ // for manipulating the JavaScript scope chain, put in trivial emulations
82
+ $env.debug("performing check for custom Java methods in env-js.jar");
83
+ var countOfMissing = 0, dontCare;
84
+ try { dontCare = getFreshScopeObj; }
85
+ catch (ex){ getFreshScopeObj = function(){ return {}; };
86
+ countOfMissing++; }
87
+ try { dontCare = getProxyFor; }
88
+ catch (ex){ getProxyFor = function(obj){ return obj; };
89
+ countOfMissing++; }
90
+ try { dontCare = getScope; }
91
+ catch (ex){ getScope = function(){}; countOfMissing++; }
92
+ try { dontCare = setScope; }
93
+ catch (ex){ setScope = function(){}; countOfMissing++; }
94
+ try { dontCare = configureScope; }
95
+ catch (ex){ configureScope = function(){}; countOfMissing++; }
96
+ try { dontCare = restoreScope; }
97
+ catch (ex){ restoreScope = function(){}; countOfMissing++; }
98
+ try { $env.loadIntoFnsScope = loadIntoFnsScope; }
99
+ catch (ex){ $env.loadIntoFnsScope = load; countOfMissing++; }
100
+ if (countOfMissing != 0 && countOfMissing != 7)
101
+ $env.warn("Some but not all of scope-manipulation functions were " +
102
+ "not present in environment. JavaScript execution may " +
103
+ "not occur correctly.");
104
+
105
+ $env.lineSource = $env.lineSource || function(e){};
106
+
107
+ //resolves location relative to base or window location
108
+ $env.location = $env.location || function(path, base){};
109
+
110
+ $env.sync = $env.sync || function(fn){
111
+ return function(){ return fn.apply(this,arguments); };
112
+ };
113
+
114
+ $env.spawn = $env.spawn || function(fn) {
115
+ setTimeout(fn,0);
116
+ };
117
+
118
+ $env.sleep = $env.sleep || function(){};
119
+
120
+ $env.javaEnabled = false;
121
+
122
+ //Used in the XMLHttpRquest implementation to run a
123
+ // request in a seperate thread
124
+ $env.runAsync = $env.runAsync || function(fn){};
125
+
126
+ //Used to write to a local file
127
+ $env.writeToFile = $env.writeToFile || function(text, url){};
128
+
129
+ //Used to write to a local file
130
+ $env.writeToTempFile = $env.writeToTempFile || function(text, suffix){};
131
+
132
+ //Used to delete a local file
133
+ $env.deleteFile = $env.deleteFile || function(url){};
134
+
135
+ $env.connection = $env.connection || function(xhr, responseHandler, data){};
136
+
137
+ $env.parseHTML = function(htmlstring){};
138
+ $env.parseXML = function(xmlstring){};
139
+ $env.xpath = function(expression, doc){};
140
+
141
+ $env.tmpdir = '';
142
+ $env.os_name = '';
143
+ $env.os_arch = '';
144
+ $env.os_version = '';
145
+ $env.lang = '';
146
+ $env.platform = "";
147
+
148
+ $env.scriptTypes = {
149
+ "text/javascript" :true,
150
+ "text/envjs" :true
151
+ };
152
+
153
+ $env.onScriptLoadError = $env.onScriptLoadError || function(){};
154
+ $env.loadLocalScript = function(script, parser){
155
+ $env.debug("loading script ");
156
+ // print("loadloacl");
157
+ // try{throw new Error}catch(e){print(e.stack);}
158
+ var types, type, src, i, base,
159
+ docWrites = [],
160
+ write = document.write,
161
+ writeln = document.writeln,
162
+ okay = true;
163
+ // SMP: see also the note in html/document.js about script.type
164
+ var script_type = script.type === null ? "text/javascript" : script.type;
165
+ try{
166
+ if(script_type){
167
+ types = script_type?script_type.split(";"):[];
168
+ for(i=0;i<types.length;i++){
169
+ if($env.scriptTypes[types[i]]){
170
+ if(script.src){
171
+ $env.info("loading allowed external script: " + script.src);
172
+ //lets you register a function to execute
173
+ //before the script is loaded
174
+ if($env.beforeScriptLoad){
175
+ for(src in $env.beforeScriptLoad){
176
+ if(script.src.match(src)){
177
+ $env.beforeScriptLoad[src]();
178
+ }
179
+ }
180
+ }
181
+ base = "" + window.location;
182
+ var filename = $env.location(script.src, base );
183
+ try {
184
+ load(filename);
185
+ } catch(e) {
186
+ $env.warn("could not load script "+ filename +": "+e );
187
+ okay = false;
188
+ }
189
+ //lets you register a function to execute
190
+ //after the script is loaded
191
+ if($env.afterScriptLoad){
192
+ for(src in $env.afterScriptLoad){
193
+ if(script.src.match(src)){
194
+ $env.afterScriptLoad[src]();
195
+ }
196
+ }
197
+ }
198
+ }else{
199
+ $env.loadInlineScript(script);
200
+ }
201
+ }else{
202
+ if(!script.src && script_type == "text/javascript"){
203
+ $env.loadInlineScript(script);
204
+ } else {
205
+ // load prohbited ...
206
+ okay = false;
207
+ }
208
+ }
209
+ }
210
+ }else{
211
+ // SMP this branch is probably dead ...
212
+ //anonymous type and anonymous src means inline
213
+ if(!script.src){
214
+ $env.loadInlineScript(script);
215
+ }
216
+ }
217
+ }catch(e){
218
+ okay = false;
219
+ $env.error("Error loading script.", e);
220
+ $env.onScriptLoadError(script);
221
+ }finally{
222
+ /*if(parser){
223
+ parser.appendFragment(docWrites.join(''));
224
+ }
225
+ //return document.write to it's non-script loading form
226
+ document.write = write;
227
+ document.writeln = writeln;*/
228
+ }
229
+ return okay;
230
+ };
231
+ $env.loadInlineScript = $env.loadInlineScript || function(script){};
232
+
233
+ $env.loadFrame = function(frameElement, url){
234
+ try {
235
+ if (frameElement._content){
236
+ $env.unload(frameElement._content);
237
+ $env.reload(frameElement._content, url);
238
+ }
239
+ else {
240
+ var v = $env.newwindow($w,
241
+ frameElement.ownerDocument.parentWindow, url);
242
+ frameElement._content = v;
243
+ }
244
+ } catch(e){
245
+ $env.error("failed to load frame content: from " + url, e);
246
+ }
247
+ };
248
+
249
+ $env.reload = $env.reload || function(oldWindowProxy, url){
250
+ var newWindowProxy = $env.newwindow(
251
+ oldWindowProxy.opener,
252
+ oldWindowProxy.parent,
253
+ url);
254
+ var newWindow = newWindowProxy.__proto__;
255
+
256
+ oldWindowProxy.__proto__ = newWindow;
257
+ newWindow.$thisWindowsProxyObject = oldWindowProxy;
258
+ newWindow.document._parentWindow = oldWindowProxy;
259
+ };
260
+
261
+ $env.newwindow = $env.newwindow || function(openingWindow, parentArg, url){
262
+ var newWindow = $env.getFreshScopeObj();
263
+ var newProxy = $env.getProxyFor(newWindow);
264
+ newWindow.$thisWindowsProxyObject = newProxy;
265
+
266
+ var local__window__ = $env.window,
267
+ local_env = $env,
268
+ local_opener = openingWindow,
269
+ local_parent = parentArg ? parentArg : newWindow;
270
+
271
+ var inNewContext = function(){
272
+ local__window__(newWindow, // object to "window-ify"
273
+ local_env, // our scope for globals
274
+ local_parent, // win's "parent"
275
+ local_opener, // win's "opener"
276
+ local_parent.top, // win's "top"
277
+ false // this win isn't the original
278
+ );
279
+ print("QQ");
280
+ if (url)
281
+ // newWindow.__loadAWindowsDocument__(url);
282
+ $env.load(url);
283
+ };
284
+
285
+ var scopes = recordScopesOfKeyObjects(inNewContext);
286
+ setScopesOfKeyObjects(inNewContext, newWindow);
287
+ print("ZZ");
288
+ inNewContext(); // invoke local fn to window-ify new scope object
289
+ print("TT");
290
+ restoreScopesOfKeyObjects(inNewContext, scopes);
291
+ return newProxy;
292
+ };
293
+
294
+ function recordScopesOfKeyObjects(fnToExecInOtherContext){
295
+ return { // getScope()/setScope() from Window.java
296
+ frame : getScope(fnToExecInOtherContext),
297
+ window : getScope($env.window),
298
+ global_load : getScope($env.loadIntoFnsScope),
299
+ local_load : getScope($env.loadLocalScript)
300
+ };
301
+ }
302
+
303
+ function setScopesOfKeyObjects(fnToExecInOtherContext, windowObj){
304
+ setScope(fnToExecInOtherContext, windowObj);
305
+ setScope($env.window, windowObj);
306
+ setScope($env.loadIntoFnsScope, windowObj);
307
+ setScope($env.loadLocalScript, windowObj);
308
+ }
309
+
310
+ function restoreScopesOfKeyObjects(fnToExecInOtherContext, scopes){
311
+ setScope(fnToExecInOtherContext, scopes.frame);
312
+ setScope($env.window, scopes.window);
313
+ setScope($env.loadIntoFnsScope, scopes.global_load);
314
+ setScope($env.loadLocalScript, scopes.local_load);
315
+ }
316
+
317
+ })($env);
318
+
319
+ // Local Variables:
320
+ // espresso-indent-level:4
321
+ // c-basic-offset:4
322
+ // tab-width:4
323
+ // End:
@@ -0,0 +1,484 @@
1
+ $env.log = function(msg, level){
2
+ print(' '+ (level?level:'LOG') + ':\t['+ new Date()+"] {ENVJS} "+msg);
3
+ };
4
+
5
+ $env.location = function(path, base){
6
+ var debug = false;
7
+ debug && print("loc",path,base);
8
+ if ( path == "about:blank" ) {
9
+ return path;
10
+ }
11
+ var protocol = new RegExp('(^file\:|^http\:|^https\:|data:)');
12
+ var m = protocol.exec(path);
13
+ if(m&&m.length>1){
14
+ var url = Ruby.URI.parse(path);
15
+ var s = url.toString();
16
+ if ( s.substring(0,6) == "file:/" && s[6] != "/" ) {
17
+ s = "file://" + s.substring(5,s.length);
18
+ }
19
+ debug && print("YY",s);
20
+ return s;
21
+ }else if(base){
22
+ base = Ruby.URI.parse(base);
23
+ path = Ruby.URI.parse(path);
24
+ var b = Ruby.eval("lambda { |a,b| a+b; }");
25
+ base = b(base,path);
26
+ base = base + "";
27
+ var result = base;
28
+ // print("ZZ",result);
29
+ // ? This path only used for files?
30
+ if ( result.substring(0,6) == "file:/" && result[6] != "/" ) {
31
+ result = "file://" + result.substring(5,result.length);
32
+ }
33
+ if ( result.substring(0,7) == "file://" ) {
34
+ result = result.substring(7,result.length);
35
+ }
36
+ debug && print("ZZ",result);
37
+ return result;
38
+ }else{
39
+ //return an absolute url from a url relative to the window location
40
+ // print("hi", $master.first_script_window, $master.first_script_window && $master.first_script_window.location );
41
+ // if( ( base = window.location ) &&
42
+ if( ( base = ( ( $master.first_script_window && $master.first_script_window.location ) || window.location ) ) &&
43
+ ( base != "about:blank" ) &&
44
+ base.href &&
45
+ (base.href.length > 0) ) {
46
+
47
+ base_uri = Ruby.URI.parse(base.href);
48
+ new_uri = Ruby.URI.parse(path);
49
+ result = Ruby.eval("lambda { |a,b| a+b; }")(base_uri,new_uri)+"";
50
+ debug && print("IIII",result);
51
+ return result;
52
+
53
+ base = base.href.substring(0, base.href.lastIndexOf('/'));
54
+ var result;
55
+ // print("XXXXX",base);
56
+ if ( base[base.length-1] == "/" || path[0] == "/" ) {
57
+ result = base + path;
58
+ } else {
59
+ result = base + '/' + path;
60
+ }
61
+ if ( result.substring(0,6) == "file:/" && result[6] != "/" ) {
62
+ result = "file://" + result.substring(5,result.length);
63
+ }
64
+ debug && print("****",result);
65
+ return result;
66
+ } else {
67
+ // print("RRR",result);
68
+ return "file://"+Ruby.File.expand_path(path);
69
+ }
70
+ }
71
+ };
72
+
73
+ $env.connection = $master.connection || function(xhr, responseHandler, data){
74
+ var url = Ruby.URI.parse(xhr.url);
75
+ var connection;
76
+ var resp;
77
+ // print("xhr",xhr.url);
78
+ // print("xhr",url);
79
+ if ( /^file\:/.test(url) ) {
80
+ // experimental hack
81
+ try {
82
+ Ruby.eval("require 'envjs/net/cgi'");
83
+ resp = connection = new Ruby.Envjs.Net.CGI( xhr, data );
84
+ } catch(e) {
85
+ try{
86
+ if ( xhr.method == "PUT" ) {
87
+ var text = data || "" ;
88
+ $env.writeToFile(text, url);
89
+ } else if ( xhr.method == "DELETE" ) {
90
+ $env.deleteFile(url);
91
+ } else {
92
+ Ruby.eval("require 'envjs/net/file'");
93
+ var request = new Ruby.Envjs.Net.File.Get( url.path );
94
+ connection = Ruby.Envjs.Net.File.start( url.host, url.port );
95
+ resp = connection.request( request );
96
+ //try to add some canned headers that make sense
97
+
98
+ try{
99
+ if(xhr.url.match(/html$/)){
100
+ xhr.responseHeaders["Content-Type"] = 'text/html';
101
+ }else if(xhr.url.match(/.xml$/)){
102
+ xhr.responseHeaders["Content-Type"] = 'text/xml';
103
+ }else if(xhr.url.match(/.js$/)){
104
+ xhr.responseHeaders["Content-Type"] = 'text/javascript';
105
+ }else if(xhr.url.match(/.json$/)){
106
+ xhr.responseHeaders["Content-Type"] = 'application/json';
107
+ }else{
108
+ xhr.responseHeaders["Content-Type"] = 'text/plain';
109
+ }
110
+ //xhr.responseHeaders['Last-Modified'] = connection.getLastModified();
111
+ //xhr.responseHeaders['Content-Length'] = headerValue+'';
112
+ //xhr.responseHeaders['Date'] = new Date()+'';*/
113
+ }catch(e){
114
+ $env.warn('failed to load response headers',e);
115
+ }
116
+
117
+ }
118
+ } catch (e) {
119
+ connection = null;
120
+ xhr.readyState = 4;
121
+ if(e.toString().match(/Errno::ENOENT/)) {
122
+ xhr.status = "404";
123
+ xhr.statusText = "Not Found";
124
+ xhr.responseText = undefined;
125
+ } else {
126
+ xhr.status = "500";
127
+ xhr.statusText = "Local File Protocol Error";
128
+ xhr.responseText = "<html><head/><body><p>"+ e+ "</p></body></html>";
129
+ }
130
+ }
131
+ }
132
+ } else {
133
+ Ruby.eval("require 'net/http'");
134
+
135
+ var req;
136
+ var path;
137
+ try {
138
+ path = url.request_uri();
139
+ } catch(e) {
140
+ path = url.path;
141
+ }
142
+ if ( xhr.method == "GET" ) {
143
+ req = new Ruby.Net.HTTP.Get( path );
144
+ } else if ( xhr.method == "POST" ) {
145
+ req = new Ruby.Net.HTTP.Post( path );
146
+ } else if ( xhr.method == "PUT" ) {
147
+ req = new Ruby.Net.HTTP.Put( path );
148
+ }
149
+
150
+ for (var header in xhr.headers){
151
+ $master.add_req_field( req, header, xhr.headers[header] );
152
+ }
153
+
154
+ //write data to output stream if required
155
+ if(data&&data.length&&data.length>0){
156
+ if ( xhr.method == "PUT" || xhr.method == "POST" ) {
157
+ Ruby.eval("lambda { |req,data| req.body = data}").call(req,data);
158
+ // req.body = data;
159
+ }
160
+ }
161
+
162
+ try {
163
+ connection = Ruby.Net.HTTP.new( url.host, url.port );
164
+ if (url.scheme === "https") {
165
+ Ruby.eval("require 'net/https'");
166
+ connection.use_ssl = true;
167
+ }
168
+ connection.start();
169
+ resp = connection.request(req);
170
+ } catch(e) {
171
+ $env.warn("XHR net request failed: "+e);
172
+ // FIX: do the on error stuff ...
173
+ throw e;
174
+ }
175
+
176
+ }
177
+ if(connection){
178
+ try{
179
+ if (false) {
180
+ var respheadlength = connection.getHeaderFields().size();
181
+ // Stick the response headers into responseHeaders
182
+ for (var i = 0; i < respheadlength; i++) {
183
+ var headerName = connection.getHeaderFieldKey(i);
184
+ var headerValue = connection.getHeaderField(i);
185
+ if (headerName)
186
+ xhr.responseHeaders[headerName+''] = headerValue+'';
187
+ }
188
+ }
189
+ resp.each(function(k,v){
190
+ xhr.responseHeaders[k] = v;
191
+ });
192
+ }catch(e){
193
+ $env.error('failed to load response headers: '+e);
194
+ throw e;
195
+ }
196
+
197
+ xhr.readyState = 4;
198
+ xhr.status = parseInt(resp.code,10) || 0;
199
+ xhr.statusText = connection.responseMessage || "";
200
+
201
+ var contentEncoding = resp["Content-Encoding"] || "utf-8",
202
+ baos = new Ruby.StringIO,
203
+ length,
204
+ stream = null,
205
+ responseXML = null;
206
+
207
+ try{
208
+ var lower = contentEncoding.toLowerCase();
209
+ stream = ( lower == "gzip" || lower == "decompress" ) ?
210
+ ( Ruby.raise("java") && new java.util.zip.GZIPInputStream(resp.getInputStream()) ) : resp;
211
+ }catch(e){
212
+ if (resp.code == "404")
213
+ $env.info('failed to open connection stream \n' +
214
+ e.toString(), e);
215
+ else
216
+ $env.error('failed to open connection stream \n' +
217
+ e.toString(), e);
218
+ stream = resp;
219
+ }
220
+
221
+ baos.write(resp.body);
222
+
223
+ baos.close();
224
+ connection.finish();
225
+
226
+ xhr.responseText = baos.string();
227
+ }
228
+ if(responseHandler){
229
+ $env.debug('calling ajax response handler');
230
+ responseHandler();
231
+ }
232
+ };
233
+
234
+ var extract_line =
235
+ Ruby.eval(
236
+ "lambda { |e| \
237
+ begin; \
238
+ e.stack.to_s.split(%(\n))[1].match(/:([^:]*)$/)[1]; \
239
+ rescue; %(unknown); end; \
240
+ }");
241
+
242
+ var get_exception = window.get_exception =
243
+ Ruby.eval(" \
244
+ lambda { |e| \
245
+ estr = e.to_s; \
246
+ estr.gsub!(/(<br \\/>)+/, %( )); \
247
+ ss = ''; \
248
+ ss = ss + %(Exception: ) + estr + %(\n); \
249
+ begin; \
250
+ e.stack.to_s.split(%(\n)).each do |line| \
251
+ m = line.match(/(.*)@([^@]*)$/); \
252
+ m[2] == %(:0) && next; \
253
+ s = m[1]; \
254
+ s.gsub!(/(<br \\/>)+/, %( )); \
255
+ limit = 100; \
256
+ if ( s.length > limit ); \
257
+ s = s[0,limit] + %(...); \
258
+ end; \
259
+ ss = ss + m[2] + %( ) + s + %(\n); \
260
+ end; \
261
+ rescue; end; \
262
+ ss; \
263
+ } \
264
+ ");
265
+
266
+ var get_exception_trace = window.get_exception_trace =
267
+ Ruby.eval(" \
268
+ lambda { |e| \
269
+ estr = e.to_s; \
270
+ estr.gsub!(/(<br \\/>)+/, %( )); \
271
+ begin; \
272
+ ss = ''; \
273
+ e.stack.to_s.split(%(\n)).each do |line| \
274
+ m = line.match(/(.*)@([^@]*)$/); \
275
+ m[2] == %(:0) && next; \
276
+ s = m[1]; \
277
+ s.gsub!(/(<br \\/>)+/, %( )); \
278
+ limit = 100; \
279
+ if ( s.length > limit ); \
280
+ s = s[0,limit] + %(...); \
281
+ end; \
282
+ ss = ss + m[2] + %( ) + s +%(\n); \
283
+ end; \
284
+ rescue; end; \
285
+ ss; \
286
+ } \
287
+ ");
288
+
289
+ var print_exception = window.print_exception =
290
+ Ruby.eval(" \
291
+ lambda { |e| \
292
+ estr = e.to_s; \
293
+ estr.gsub!(/(<br \\/>)+/, %( )); \
294
+ $stderr.print(%(Exception: ),estr,%(\n)); \
295
+ begin; \
296
+ e.stack.to_s.split(%(\n)).each do |line| \
297
+ m = line.match(/(.*)@([^@]*)$/); \
298
+ m[2] == %(:0) && next; \
299
+ s = m[1]; \
300
+ s.gsub!(/(<br \\/>)+/, %( )); \
301
+ limit = 100; \
302
+ if ( s.length > limit ); \
303
+ s = s[0,limit] + %(...); \
304
+ end; \
305
+ $stderr.print(m[2],%( ),s,%(\n)); \
306
+ end; \
307
+ rescue; end; \
308
+ } \
309
+ ");
310
+
311
+ var print_exception_trace = window.print_exception_trace =
312
+ Ruby.eval(" \
313
+ lambda { |e| \
314
+ estr = e.to_s; \
315
+ estr.gsub!(/(<br \\/>)+/, %( )); \
316
+ begin; \
317
+ e.stack.to_s.split(%(\n)).each do |line| \
318
+ m = line.match(/(.*)@([^@]*)$/); \
319
+ m[2] == %(:0) && next; \
320
+ s = m[1]; \
321
+ s.gsub!(/(<br \\/>)+/, %( )); \
322
+ limit = 100; \
323
+ if ( s.length > limit ); \
324
+ s = s[0,limit] + %(...); \
325
+ end; \
326
+ $stderr.print(m[2],%( ),s,%(\n)); \
327
+ end; \
328
+ rescue; end; \
329
+ } \
330
+ ");
331
+
332
+ $env.lineSource = function(e){
333
+ if(e){
334
+ print_exception.call(e);
335
+ return extract_line.call(e);
336
+ } else {
337
+ return "";
338
+ }
339
+ };
340
+
341
+ $env.loadInlineScript = function(script){
342
+ var undef;
343
+ if (script.text === undef ||
344
+ script.text === null ||
345
+ script.text.match(/^\s*$/)) {
346
+ return;
347
+ }
348
+ var original_script_window = $master.first_script_window;
349
+ // debug("lis",original_script_window,original_script_window.isInner);
350
+ // debug("XX",window,window.isInner);
351
+ if ( !$master.first_script_window ) {
352
+ // $master.first_script_window = window;
353
+ }
354
+ // debug("lix",$master.first_script_window,$master.first_script_window.isInner,$w,$w.isInner);
355
+ try {
356
+ $master.evaluate(script.text,$inner);
357
+ } catch(e) {
358
+ $env.error("error evaluating script: "+script.text);
359
+ $env.error(e);
360
+ // try { throw new Error("here") } catch(b) { $env.error(b.stack); }
361
+ // throw e;
362
+ }
363
+ // $master.first_script_window = original_script_window;
364
+ // debug("lis",original_script_window,original_script_window.isInner);
365
+ };
366
+
367
+ $env.writeToTempFile = function(text, suffix){
368
+ $env.debug("writing text to temp url : " + suffix);
369
+ // print(text);
370
+ // Create temp file.
371
+ Ruby.eval("require 'envjs/tempfile'");
372
+ var temp = new Ruby.Envjs.TempFile( "envjs-tmp", suffix );
373
+
374
+ // Write to temp file
375
+ temp.write(text);
376
+ temp.close();
377
+ return temp.getAbsolutePath().toString()+'';
378
+ };
379
+
380
+ $env.writeToFile = function(text, url){
381
+ // print("writing text to url : " + url);
382
+ $env.debug("writing text to url : " + url);
383
+ if ( url.substring(0,7) == "file://" ) {
384
+ url = url.substring(7,url.length);
385
+ }
386
+ var file = Ruby.open( url, "w" );
387
+ // Write to temp file
388
+ file.write(text);
389
+ file.close();
390
+ };
391
+
392
+ $env.deleteFile = function(url){
393
+ Ruby.File.unlink(url);
394
+ };
395
+
396
+ $env.__eval__ = function(script,scope){
397
+ if (script == "")
398
+ return undefined;
399
+ try {
400
+ var scope = node;
401
+ var __scopes__ = [];
402
+ var original = script;
403
+ if(scope) {
404
+ // script = "(function(){return eval(original)}).call(__scopes__[0])";
405
+ script = "return (function(){"+original+"}).call(__scopes__[0])";
406
+ while(scope) {
407
+ __scopes__.push(scope);
408
+ scope = scope.parentNode;
409
+ script = "with(__scopes__["+(__scopes__.length-1)+"] ){"+script+"};";
410
+ }
411
+ }
412
+ script = "function(original,__scopes__){"+script+"}";
413
+ // print("scripta",script);
414
+ // print("scriptb",original);
415
+ var original_script_window = $master.first_script_window;
416
+ if ( !$master.first_script_window ) {
417
+ // $master.first_script_window = window;
418
+ }
419
+ // FIX!!!
420
+ var $inner = node.ownerDocument._parentWindow["$inner"];
421
+ var result = $master.evaluate(script,$inner)(original,__scopes__);
422
+ // $master.first_script_window = original_script_window;
423
+ return result;
424
+ }catch(e){
425
+ $warn("Exception during on* event eval: "+e);
426
+ throw e;
427
+ }
428
+ };
429
+
430
+ $env.newwindow = function(openingWindow, parentArg, url, outer,xhr_options){
431
+ // print(location);
432
+ // print("url",url,window.location,openingWindow);
433
+ // print("parent",parentArg);
434
+ var options = {
435
+ opener: openingWindow,
436
+ parent: parentArg,
437
+ url: $env.location(url),
438
+ xhr: xhr_options
439
+ };
440
+
441
+ // print("$w",$w);
442
+ // print("$ww",$w.window);
443
+ // print("$ww",$w === $w.window);
444
+ var pair = $env.new_window(outer);
445
+ var proxy = pair[0];
446
+ var new_window = pair[1];
447
+ options.proxy = proxy;
448
+ new_window.$options = options;
449
+ // print("$w",$w);
450
+ $master.load($master.Ruby.Envjs.ENVJS, new_window);
451
+ return proxy;
452
+ };
453
+
454
+ $env.reload = function(oldWindowProxy, url,options){
455
+ // print("reload",window,oldWindowProxy,url);
456
+ $env.newwindow( oldWindowProxy.opener,
457
+ oldWindowProxy.parent,
458
+ url,
459
+ oldWindowProxy,
460
+ options );
461
+ };
462
+
463
+ $env.sleep = function(n){Ruby.sleep(n/1000.);};
464
+
465
+ $env.loadIntoFnsScope = function(file) {
466
+ return load(file);
467
+ }
468
+
469
+ $env.runAsync = function(fn){
470
+ $env.debug("running async");
471
+
472
+ var run = $env.sync( function(){ fn(); } );
473
+
474
+ try{
475
+ $env.spawn(run);
476
+ }catch(e){
477
+ $env.error("error while running async", e);
478
+ }
479
+ };
480
+
481
+ // Local Variables:
482
+ // espresso-indent-level:4
483
+ // c-basic-offset:4
484
+ // End: