envjs19 0.3.8.20101029121421

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/lib/envjs/net.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'envjs'
2
+
3
+ module Envjs::Net; end
@@ -0,0 +1,94 @@
1
+ require 'net/protocol'
2
+
3
+ require 'envjs/net'
4
+
5
+ class Envjs::Net::CGI
6
+
7
+ def save_and_set k, v
8
+ @saved[k] = ENV[k]
9
+ ENV[k] = v
10
+ end
11
+
12
+ def restore
13
+ @saved.keys.each do |k|
14
+ ENV[k] = @saved[k]
15
+ end
16
+ @saved = {}
17
+ end
18
+
19
+ def initialize xhr, data
20
+ if (match = %r((.*\.php)(\?(.*))?).match xhr.url).nil?
21
+ raise "Not CGI"
22
+ end
23
+
24
+ @saved = {}
25
+
26
+ begin
27
+
28
+ # p match[0]
29
+
30
+ path = match[1]
31
+ path.sub! %r(^file://), ""
32
+
33
+ save_and_set( "GATEWAY_INTERFACE", "CGI/1.1" )
34
+
35
+ save_and_set( "REQUEST_METHOD", xhr["method"] )
36
+ if ( match[3] )
37
+ save_and_set( "QUERY_STRING", match[3] )
38
+ end
39
+
40
+ if ct = xhr["headers"]["Content-Type"]
41
+ save_and_set( "CONTENT_TYPE", ct )
42
+ end
43
+
44
+ if data
45
+ save_and_set( "CONTENT_LENGTH", data.length.to_s )
46
+ end
47
+
48
+ xhr["headers"].each do |k,v|
49
+ k.gsub!("-","_")
50
+ k = "HTTP_" + k
51
+ save_and_set( k, v )
52
+ end
53
+
54
+ result = nil
55
+
56
+ save_and_set( "PATH_INFO", path )
57
+ save_and_set( "PATH_TRANSLATED", path )
58
+ save_and_set( "REDIRECT_STATUS", "200" )
59
+
60
+ open("|php-cgi", "r+") do |php|
61
+ if data
62
+ php.write data
63
+ php.flush
64
+ end
65
+ result = php.read
66
+ end
67
+
68
+ result && result = result.split("\r\n")
69
+ @headers = {}
70
+ while line = result.shift
71
+ break if line == ""
72
+ match = /([^:]*):\s*(.*)/.match line
73
+ @headers[match[1]]=match[2]
74
+ end
75
+ # p "q", result.join("\r\n")
76
+ @body = result.join("\r\n")
77
+ ensure
78
+ restore
79
+ end
80
+
81
+ end
82
+
83
+ def each
84
+ @headers.each do |k,v|
85
+ yield k, v
86
+ end
87
+ end
88
+
89
+ def finish
90
+ end
91
+
92
+ attr_reader :body
93
+
94
+ end
@@ -0,0 +1,69 @@
1
+ require 'net/protocol'
2
+
3
+ require 'envjs/net'
4
+
5
+ class Envjs::Net::File < Net::Protocol
6
+
7
+ class Get
8
+ attr_accessor :path
9
+ def initialize path
10
+ @path = path
11
+ end
12
+ end
13
+
14
+ def initialize host, port
15
+ end
16
+
17
+ def self.start host, port
18
+ new( host, port ).start
19
+ end
20
+
21
+ def start
22
+ self
23
+ end
24
+
25
+ def finish
26
+ end
27
+
28
+ def request request
29
+ Response.new request.path
30
+ end
31
+
32
+ class Response
33
+ def initialize path
34
+ @path = path
35
+ @file = File.new @path
36
+ @body = @file.read
37
+ @code = @file.nil? ? "404" : "200";
38
+ @file.close
39
+ end
40
+
41
+ def [] *args
42
+ nil
43
+ end
44
+
45
+ def each &block
46
+ end
47
+
48
+ def getHeaderFields
49
+ []
50
+ end
51
+
52
+ def getContentEncoding
53
+ nil
54
+ end
55
+
56
+ def getResponseCode
57
+ @file.nil? ? 404 : 200;
58
+ end
59
+
60
+
61
+ def getInputStream
62
+ self
63
+ end
64
+
65
+ attr_reader :body, :code
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,11 @@
1
+ require 'optparse'
2
+
3
+ $envjsrb_wake = false
4
+
5
+ OptionParser.new do |o|
6
+
7
+ o.on("--wake") do |path|
8
+ $envjsrb_wake = true
9
+ end
10
+
11
+ end.parse!
@@ -0,0 +1,346 @@
1
+ require 'envjs'
2
+ require "open-uri"
3
+ require 'pathname'
4
+ require 'envjs/net/file'
5
+
6
+ $wake_info = []
7
+
8
+ module Envjs::Runtime
9
+
10
+ def self.extended object
11
+ object.instance_eval do
12
+
13
+ outer = nil
14
+ scripts = {}
15
+
16
+ master = global["$master"] = evaluate("new Object", nil, nil, nil, global)
17
+
18
+ ( class << self; self; end ).send :define_method, :master do
19
+ master
20
+ end
21
+
22
+ ( class << self; self; end ).send :define_method, :evaluate do |*args|
23
+ ( script, file, line, global, scope, fn ) = *args
24
+ scope ||= outer["$inner"]
25
+ raise "cannot evaluate nil script" if script.nil?
26
+ raise "cannot evaluate without a scope" if scope.nil?
27
+ raise "outer given when inner needed" if !scope == global and !scope["isInner"]
28
+ # print "eval in " + script[0,50].inspect + scope.inspect + " " + ( scope ? scope.isInner.inspect : "none" ) + "\n"
29
+ global = nil
30
+ # scope ||= inner
31
+ if fn
32
+ compiled_script = scripts[fn]
33
+ end
34
+ compiled_script ||= compile(script, file, line, global)
35
+ raise "hell" if !compiled_script
36
+ if fn && !scripts[fn]
37
+ scripts[fn] = compiled_script
38
+ end
39
+ save = master["first_script_window"]
40
+ if false
41
+ p scope
42
+ if master["first_script_window"]
43
+ print "ignored: " + ( scope["location"] ? scope["location"]["href"] : "nil" ) + " using " + ( master["first_script_window"]["location"] ? master["first_script_window"]["location"]["href"] : "nil" ) + "\n"
44
+ else
45
+ print "pushing into " + ( scope["location"] ? scope["location"]["href"] : "nil" ) + "\n"
46
+ end
47
+ end
48
+
49
+ master["first_script_window"] ||= scope
50
+ raise "hell" if !master["first_script_window"]["isInner"] && master["first_script_window"] != self.global
51
+ v = nil
52
+ begin
53
+ v = evaluate_compiled_script(compiled_script,scope)
54
+ # p "pe", v, compiled_script, scope
55
+ rescue Exception => e
56
+ # p "oopsrt", e
57
+ raise e
58
+ ensure
59
+ master["first_script_window"] = save
60
+ end
61
+ # print "done\n"
62
+ v
63
+ end
64
+
65
+ evaluate( <<'EOJS', nil, nil, nil, global )
66
+ print = function() {
67
+ var l = arguments.length
68
+ for( var i = 0; i < l; i++ ) {
69
+ var s;
70
+ if ( arguments[i] === null ) {
71
+ s = "null";
72
+ } else if ( arguments[i] === undefined ) {
73
+ s = "undefined"
74
+ } else {
75
+ s = arguments[i].toString();
76
+ }
77
+ Ruby.print(s);
78
+ if( i < l-1 ) {
79
+ Ruby.print(" ");
80
+ }
81
+ }
82
+ Ruby.print("\n");
83
+ Ruby['$stdout'].flush();
84
+ };
85
+ EOJS
86
+
87
+ evaluate <<'EOJS', nil, nil, nil, global
88
+ debug = function() {
89
+ var l = arguments.length
90
+ for( var i = 0; i < l; i++ ) {
91
+ var s;
92
+ if ( arguments[i] === null ) {
93
+ s = "null";
94
+ } else if ( arguments[i] === undefined ) {
95
+ s = "undefined"
96
+ } else {
97
+ s = arguments[i].toString();
98
+ }
99
+ Ruby['$stderr'].print(s);
100
+ if( i < l-1 ) {
101
+ Ruby['$stderr'].print(" ");
102
+ }
103
+ }
104
+ Ruby['$stderr'].print("\n");
105
+ Ruby['$stderr'].flush();
106
+ };
107
+ EOJS
108
+
109
+ evaluate <<'EOJS', nil, nil, nil, global
110
+ puts = function() {
111
+ var l = arguments.length
112
+ for( var i = 0; i < l; i++ ) {
113
+ var s;
114
+ if ( arguments[i] === null ) {
115
+ s = "null";
116
+ } else if ( arguments[i] === undefined ) {
117
+ s = "undefined"
118
+ } else {
119
+ s = arguments[i].toString();
120
+ }
121
+ Ruby.print(s);
122
+ Ruby.eval("$stdout.flush")
123
+ }
124
+ };
125
+ EOJS
126
+
127
+ master["runtime"] = self
128
+ window_index = -1
129
+ master["next_window_index"] = lambda { window_index += 1 }
130
+ master.symbols = [ "Johnson", "Ruby", "print", "debug", "puts", "load", "reload", "whichInterpreter", "multiwindow", "seal" ]
131
+ master.symbols.each { |symbol| master[symbol] = global[symbol] }
132
+ master["seal"] = lambda do |*args|
133
+ object, deep = *args
134
+ seal object, deep
135
+ end
136
+
137
+ master.whichInterpreter = "Johnson"
138
+
139
+ master.multiwindow = true
140
+
141
+ # calling this from JS is hosed; the ruby side is confused, maybe because HTTPHeaders is mixed in?
142
+ master.add_req_field = lambda { |r,k,v| r.add_field(k,v) }
143
+
144
+ top_level_js = nil
145
+
146
+ add_dep = nil
147
+
148
+ add_dep = lambda do |w, f|
149
+ if $envjsrb_wake
150
+ $wake_info << "##file://#{f}"
151
+ end
152
+ end
153
+
154
+ (class << self; self; end).send :define_method, :top_level_load do |path|
155
+ if $envjsrb_wake
156
+ $wake_info << "##{path}" if path
157
+ end
158
+ end
159
+
160
+ master.load = lambda { |*files|
161
+ if files.length == 2 && !(String === files[1])
162
+ # now = Time.now
163
+ f = files[0]
164
+ w = files[1]
165
+ # p "load", f, w
166
+
167
+ # Hmmm ...
168
+ uri = URI.parse f
169
+
170
+ if uri.scheme == nil
171
+ uri.scheme = "file"
172
+ begin
173
+ uri.path = Pathname.new(uri.path).realpath.to_s
174
+ rescue Errno::ENOENT; end
175
+ uri = URI.parse uri.to_s
176
+ end
177
+
178
+ uri_s = uri.to_s.sub %r(^file:/([^/])), 'file:///\1'
179
+
180
+ if uri.scheme == "file"
181
+ uri_s = uri.path
182
+ elsif uri.scheme == "data"
183
+ raise "implement 0"
184
+ end
185
+
186
+ v = open(uri_s).read.gsub(/\A#!.*$/, '')
187
+ loc = nil
188
+ add_dep.call w, f
189
+ evaluate(v, f, 1, w, w, f)
190
+ else
191
+ load *files
192
+ end
193
+ }
194
+
195
+ ( class << self; self; end ).send :define_method, :load do |*files|
196
+ files.map { |f|
197
+ # Hmmm ...
198
+
199
+ uri = URI.parse f
200
+ if uri.scheme == nil
201
+ uri.scheme = "file"
202
+ begin
203
+ uri.path = Pathname.new(uri.path).realpath.to_s
204
+ rescue Errno::ENOENT; end
205
+ uri = URI.parse uri.to_s
206
+ end
207
+ uri_s = uri.to_s.sub %r(^file:/([^/])), 'file:///\1'
208
+
209
+ if uri.scheme == "file"
210
+ begin
211
+ super uri.path
212
+ rescue Exception => e
213
+ if outer["$inner"]["onerror"]
214
+ # outer["$inner"]["onerror"].call e
215
+ evaluate("function(fn,scope,e){fn.call(scope,e)}").call(outer["$inner"]["onerror"], outer["$inner"], e)
216
+ else
217
+ raise e
218
+ end
219
+ end
220
+ elsif uri.scheme == "data"
221
+ raise "implement 1"
222
+ elsif uri.scheme == "javascript"
223
+ evaluate(URI.decode(uri.opaque),URI.decode(uri_s),1)
224
+ else
225
+ raise "hell 1: " + uri.inspect
226
+ end
227
+
228
+ # v = open(uri_s).read.gsub(/\A#!.*$/, '')
229
+ # loc = nil
230
+ # add_dep.call w, f
231
+ # evaluate(v, f, 1, w, w, f)
232
+ # evaluate(File.read(f).gsub(/\A#!.*$/, ''), f, 1)
233
+
234
+ }.last
235
+ end
236
+
237
+ master.reload = lambda { |*files|
238
+ if files.length == 2 && !(String === files[1])
239
+ f = files[0]
240
+ w = files[1]
241
+ v = open(f).read.gsub(/\A#!.*$/, '')
242
+ loc = nil
243
+ add_dep.call w, f
244
+ reevaluate(v, f, 1, w, w, f)
245
+ else
246
+ reload *files
247
+ end
248
+ }
249
+
250
+ master.evaluate = lambda { |v,w|
251
+ evaluate(v,"inline",1,w,w);
252
+ }
253
+
254
+ master.new_split_global_outer = lambda { new_split_global_outer }
255
+ master.new_split_global_inner = lambda { |outer,_| new_split_global_inner outer }
256
+
257
+ # create an proto window object and proxy
258
+
259
+ outer = new_split_global_outer
260
+ inner = new_split_global_inner( outer )
261
+
262
+ master.symbols.each do |symbol|
263
+ inner[symbol] = master[symbol]
264
+ end
265
+
266
+ inner["$inner"] = inner
267
+ inner["$master"] = master
268
+ inner["$options"] = evaluate("new Object", nil, nil, nil, inner);
269
+ inner["$options"].proxy = outer
270
+
271
+ inner.evaluate = lambda { |s|
272
+ return master.evaluate.call(s,inner);
273
+ }
274
+
275
+ inner.load = lambda { |*files|
276
+ files.each do |f|
277
+ master['load'].call f, inner
278
+ end
279
+ }
280
+
281
+ inner.reload = lambda { |*files|
282
+ files.each do |f|
283
+ master.reload.call f, inner
284
+ end
285
+ }
286
+
287
+ ( class << self; self; end ).send :define_method, :wait do
288
+ master["finalize"] && master.finalize.call
289
+ master.eventLoop && master.eventLoop.wait
290
+ end
291
+
292
+ ( class << self; self; end ).send :define_method, :_become_first_script_window do
293
+ # p "heh ++++++++++++++++++++++++++++", inner, master.first_script_window
294
+ inner = master.first_script_window
295
+ end
296
+
297
+ ( class << self; self; end ).send :define_method, :reevaluate do |*args|
298
+ ( script, file, line, global, scope, fn ) = *args
299
+ raise "cannot evaluate nil script" if script.nil?
300
+ # print "eval in " + script[0,50].inspect + (scope ? scope.toString() : "nil") + "\n"
301
+ global = nil
302
+ scope ||= inner
303
+ compiled_script = compile(script, file, line, global)
304
+ if fn
305
+ scripts[fn] = compiled_script
306
+ end
307
+ begin
308
+ evaluate_compiled_script(compiled_script,scope)
309
+ rescue Exception => e
310
+ p e
311
+ raise e
312
+ end
313
+ end
314
+
315
+ ( class << self; self; end ).send :define_method, :"[]" do |key|
316
+ # key == "this" && evaluate("this", nil, nil, nil, inner) || @envjs[key]
317
+ key == "this" && outer || outer[key]
318
+ end
319
+
320
+ ( class << self; self; end ).send :define_method, :"[]=" do |k,v|
321
+ # inner[k] = v
322
+ outer[k] = v
323
+ end
324
+
325
+ master['load'].call Envjs::EVENT_LOOP, global
326
+
327
+ static = new_global
328
+
329
+ master.symbols.each do |symbol|
330
+ static[symbol] = master[symbol]
331
+ end
332
+
333
+ static["$master"] = master
334
+
335
+ # fake it ...
336
+ static["isInner"] = true
337
+ master['load'].call Envjs::STATIC, static
338
+ master["static"] = static
339
+
340
+ master['load'].call Envjs::ENVJS, inner
341
+
342
+ inner = nil
343
+ end
344
+ end
345
+
346
+ end