envjs19 0.3.8.20101029121421
Sign up to get free protection for your applications and to get access to all the features.
- data/.jslintrbrc +30 -0
- data/.project +17 -0
- data/CHANGELOG.rdoc +57 -0
- data/DTD/xhtml-lat1.ent +196 -0
- data/DTD/xhtml-special.ent +80 -0
- data/DTD/xhtml-symbol.ent +237 -0
- data/DTD/xhtml.soc +14 -0
- data/DTD/xhtml1-frameset.dtd +1235 -0
- data/DTD/xhtml1-strict.dtd +978 -0
- data/DTD/xhtml1-transitional.dtd +1201 -0
- data/DTD/xhtml1.dcl +192 -0
- data/Makefile +7 -0
- data/Manifest.txt +280 -0
- data/README.rdoc +65 -0
- data/Rakefile +196 -0
- data/Wakefile +11 -0
- data/bin/envjsrb +257 -0
- data/build.properties +9 -0
- data/build.xml +247 -0
- data/gm/jquery.js +6002 -0
- data/gm/mainx.js +2648 -0
- data/gm/sensx.js +135 -0
- data/gm/t.js +6 -0
- data/gm/x.html +76 -0
- data/htmlparser/BrowserTreeBuilder.java +456 -0
- data/htmlparser/README +34 -0
- data/htmlparser/build.sh +38 -0
- data/jsl/jsl +0 -0
- data/jsl/jsl.default.conf +129 -0
- data/jsl/jsl.exe +0 -0
- data/lib/envjs.rb +35 -0
- data/lib/envjs/event_loop.js +206 -0
- data/lib/envjs/net.rb +3 -0
- data/lib/envjs/net/cgi.rb +94 -0
- data/lib/envjs/net/file.rb +69 -0
- data/lib/envjs/options.rb +11 -0
- data/lib/envjs/runtime.rb +346 -0
- data/lib/envjs/tempfile.rb +24 -0
- data/licenses/GPL-LICENSE.txt +278 -0
- data/licenses/MIT-LICENSE.txt +20 -0
- data/src/base64.js +80 -0
- data/src/build.js +6 -0
- data/src/cruft/bad.html +24 -0
- data/src/cruft/dom.js +606 -0
- data/src/cruft/element.js +297 -0
- data/src/cruft/good.html +30 -0
- data/src/cruft/good.js +32 -0
- data/src/cruft/internal.js +81 -0
- data/src/cruft/parser.js +458 -0
- data/src/css/properties.js +293 -0
- data/src/css/rule.js +22 -0
- data/src/css/sizzle.js +717 -0
- data/src/css/stylesheet.js +52 -0
- data/src/dom/attr.js +55 -0
- data/src/dom/cdatasection.js +31 -0
- data/src/dom/characterdata.js +119 -0
- data/src/dom/comment.js +30 -0
- data/src/dom/doctype.js +9 -0
- data/src/dom/document.js +1023 -0
- data/src/dom/dom.js +134 -0
- data/src/dom/element.js +217 -0
- data/src/dom/entities.js +273 -0
- data/src/dom/exception.js +28 -0
- data/src/dom/fragment.js +37 -0
- data/src/dom/implementation.js +140 -0
- data/src/dom/instruction.js +51 -0
- data/src/dom/namednodemap.js +374 -0
- data/src/dom/namespace.js +50 -0
- data/src/dom/node.js +618 -0
- data/src/dom/nodelist.js +195 -0
- data/src/dom/parser.js +1207 -0
- data/src/dom/text.js +73 -0
- data/src/event/event.js +47 -0
- data/src/event/mouseevent.js +4 -0
- data/src/event/uievent.js +8 -0
- data/src/html/a.js +110 -0
- data/src/html/anchor.js +80 -0
- data/src/html/area.js +57 -0
- data/src/html/base.js +26 -0
- data/src/html/blockquote-q.js +19 -0
- data/src/html/body.js +19 -0
- data/src/html/button.js +21 -0
- data/src/html/canvas.js +14 -0
- data/src/html/col-colgroup.js +49 -0
- data/src/html/collection.js +72 -0
- data/src/html/cookie.js +153 -0
- data/src/html/del-ins.js +25 -0
- data/src/html/div.js +28 -0
- data/src/html/document.js +364 -0
- data/src/html/element.js +382 -0
- data/src/html/fieldset.js +19 -0
- data/src/html/form.js +484 -0
- data/src/html/frame.js +89 -0
- data/src/html/frameset.js +25 -0
- data/src/html/head.js +44 -0
- data/src/html/html.js +0 -0
- data/src/html/htmlparser.js +340 -0
- data/src/html/iframe.js +26 -0
- data/src/html/image.js +0 -0
- data/src/html/img.js +62 -0
- data/src/html/input-elements.js +307 -0
- data/src/html/input.js +65 -0
- data/src/html/label.js +26 -0
- data/src/html/legend.js +19 -0
- data/src/html/link.js +82 -0
- data/src/html/map.js +22 -0
- data/src/html/meta.js +37 -0
- data/src/html/object.js +89 -0
- data/src/html/optgroup.js +25 -0
- data/src/html/option.js +103 -0
- data/src/html/param.js +38 -0
- data/src/html/script.js +122 -0
- data/src/html/select.js +132 -0
- data/src/html/style.js +31 -0
- data/src/html/table.js +199 -0
- data/src/html/tbody-thead-tfoot.js +92 -0
- data/src/html/td-th.js +18 -0
- data/src/html/textarea.js +31 -0
- data/src/html/title.js +20 -0
- data/src/html/tr.js +114 -0
- data/src/intro.js +141 -0
- data/src/outro.js +70 -0
- data/src/parser/html5.detailed.js +10762 -0
- data/src/parser/html5.min.js +503 -0
- data/src/parser/html5.pretty.js +10815 -0
- data/src/parser/intro.js +42 -0
- data/src/parser/outro.js +9 -0
- data/src/platform/core.js +323 -0
- data/src/platform/johnson.js +484 -0
- data/src/platform/rhino.js +327 -0
- data/src/platform/static/intro.js +41 -0
- data/src/platform/static/outro.js +30 -0
- data/src/profile/aop.js +238 -0
- data/src/profile/profile.js +402 -0
- data/src/serializer/xml.js +21 -0
- data/src/svg/animatedstring.js +25 -0
- data/src/svg/document.js +25 -0
- data/src/svg/element.js +22 -0
- data/src/svg/locatable.js +17 -0
- data/src/svg/rect.js +18 -0
- data/src/svg/rectelement.js +24 -0
- data/src/svg/stylable.js +49 -0
- data/src/svg/svgelement.js +22 -0
- data/src/svg/transformable.js +15 -0
- data/src/window/css.js +15 -0
- data/src/window/dialog.js +16 -0
- data/src/window/document.js +28 -0
- data/src/window/event.js +265 -0
- data/src/window/history.js +62 -0
- data/src/window/location.js +156 -0
- data/src/window/navigator.js +48 -0
- data/src/window/screen.js +53 -0
- data/src/window/timer.js +21 -0
- data/src/window/window.js +284 -0
- data/src/window/xhr.js +135 -0
- data/src/xpath/expression.js +49 -0
- data/src/xpath/implementation.js +2505 -0
- data/src/xpath/result.js +67 -0
- data/src/xpath/util.js +551 -0
- data/src/xpath/xmltoken.js +149 -0
- data/src/xslt/COPYING +34 -0
- data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
- data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
- data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
- data/src/xslt/ajaxslt-0.8.1/README +102 -0
- data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
- data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
- data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
- data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
- data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
- data/src/xslt/implementation.js +625 -0
- data/src/xslt/processor.js +37 -0
- data/src/xslt/util.js +449 -0
- data/test/base64.js +80 -0
- data/test/call-load-test.js +15 -0
- data/test/data.js +45 -0
- data/test/debug.js +53 -0
- data/test/firebug/errorIcon.png +0 -0
- data/test/firebug/firebug.css +209 -0
- data/test/firebug/firebug.html +23 -0
- data/test/firebug/firebug.js +672 -0
- data/test/firebug/firebugx.js +10 -0
- data/test/firebug/infoIcon.png +0 -0
- data/test/firebug/warningIcon.png +0 -0
- data/test/fixtures/html/events.html +171 -0
- data/test/fixtures/html/iframe1.html +46 -0
- data/test/fixtures/html/iframe1a.html +46 -0
- data/test/fixtures/html/iframe2.html +45 -0
- data/test/fixtures/html/iframe3.html +28 -0
- data/test/fixtures/html/iframeN.html +57 -0
- data/test/fixtures/html/malformed.html +181 -0
- data/test/fixtures/html/scope.html +81 -0
- data/test/fixtures/html/trivial.html +19 -0
- data/test/fixtures/html/with_js.html +26 -0
- data/test/fixtures/images/icon-blue.png +0 -0
- data/test/fixtures/js/external_script.js +1 -0
- data/test/fixtures/js/script.js +1 -0
- data/test/fixtures/js/script_error.js +2 -0
- data/test/foo.html +8 -0
- data/test/foo.js +40 -0
- data/test/html/events.html +171 -0
- data/test/html/iframe1.html +46 -0
- data/test/html/iframe1a.html +46 -0
- data/test/html/iframe2.html +45 -0
- data/test/html/iframe3.html +30 -0
- data/test/html/iframeN.html +57 -0
- data/test/html/malformed.html +181 -0
- data/test/html/scope.html +87 -0
- data/test/html/script.js +1 -0
- data/test/html/trivial.html +19 -0
- data/test/html/with_js.html +26 -0
- data/test/index.html +328 -0
- data/test/java-prototype.js +9 -0
- data/test/jquery.js +6002 -0
- data/test/primary-tests.js +26 -0
- data/test/prototype-test.js +13 -0
- data/test/qunit.js +61 -0
- data/test/qunit/qunit/qunit.css +17 -0
- data/test/qunit/qunit/qunit.js +997 -0
- data/test/scope.html +19 -0
- data/test/scope.rb +24 -0
- data/test/smp/dmathieu/index.html +8 -0
- data/test/specs/dist/env.spec.js +1534 -0
- data/test/specs/envjs.spec.css +46 -0
- data/test/specs/parser/html.js +31 -0
- data/test/specs/parser/spec.html +40 -0
- data/test/specs/parser/xml.js +31 -0
- data/test/specs/qunit.bdd.js +210 -0
- data/test/specs/qunit.css +17 -0
- data/test/specs/qunit.js +997 -0
- data/test/specs/template/spec-0.js +31 -0
- data/test/specs/template/spec-1.js +31 -0
- data/test/specs/template/spec.html +40 -0
- data/test/specs/window/css.js +23 -0
- data/test/specs/window/dialog.js +25 -0
- data/test/specs/window/document.js +23 -0
- data/test/specs/window/event.js +25 -0
- data/test/specs/window/history.js +34 -0
- data/test/specs/window/location.js +34 -0
- data/test/specs/window/navigator.js +71 -0
- data/test/specs/window/screen.js +42 -0
- data/test/specs/window/spec.html +48 -0
- data/test/specs/window/timer.js +26 -0
- data/test/specs/window/window.js +53 -0
- data/test/specs/xhr/spec.html +47 -0
- data/test/specs/xhr/xhr.js +31 -0
- data/test/test.js +10 -0
- data/test/unit/dom.js +44 -0
- data/test/unit/elementmembers.js +92 -0
- data/test/unit/events.js +195 -0
- data/test/unit/fixtures/external_script.js +1 -0
- data/test/unit/form.js +40 -0
- data/test/unit/iframe.js +234 -0
- data/test/unit/insertion.js +23 -0
- data/test/unit/multi-window.js +212 -0
- data/test/unit/nu.validator.js +34 -0
- data/test/unit/onload.js +90 -0
- data/test/unit/parser.js +122 -0
- data/test/unit/prototypecompat.js +22 -0
- data/test/unit/proxy.js +6 -0
- data/test/unit/scope.js +209 -0
- data/test/unit/timer.js +115 -0
- data/test/unit/window.js +57 -0
- data/test/x.js +1 -0
- data/test/y.js +1 -0
- metadata +367 -0
data/lib/envjs/net.rb
ADDED
@@ -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,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
|