Permalink
Browse files

early johnson work

  • Loading branch information...
1 parent f005194 commit f4b79ea8e561d38bf7a082a463ef57b1620d3078 @smparkes committed Oct 15, 2009
Showing with 641 additions and 13 deletions.
  1. +7 −5 .gitignore
  2. +75 −8 Rakefile
  3. +16 −0 bin/envjsrb
  4. +1 −0 lib/envjs.rb
  5. +54 −0 lib/envjs/net/file.rb
  6. +80 −0 lib/envjs/runtime.rb
  7. +26 −0 lib/envjs/tempfile.rb
  8. +382 −0 src/platform/johnson.js
View
@@ -1,6 +1,8 @@
-dist/env.*.*.*.js
-dist/env.rhino.*.*.*.js
-dist/env-js.*.jar
+/dist/env.*.*.*.js
+/dist/env.rhino.*.*.*.js
+/dist/env-js.*.jar
*~
-rhino/build
-jshost
+/rhino/build
+/jshost
+/dist/env.johnson.js
+/vendor
View
@@ -1,11 +1,78 @@
-# Ruby Rake file to allow automatic build testing on RunCodeRun.com
+# task :default => "rhino:test"
+task :default => "johnson:test"
-task :default => [:test]
-
-task :test do
- classpath = [
- File.join(".", "rhino", "ant.jar"),
+namespace :rhino do
+ desc "run tests aginst rhino"
+ task :test do
+ classpath = [
+ File.join(".", "rhino", "ant.jar"),
File.join(".", "rhino", "ant-launcher.jar")
- ].join(File::PATH_SEPARATOR)
- exec "java -cp #{classpath} org.apache.tools.ant.Main -emacs all"
+ ].join(File::PATH_SEPARATOR)
+ exec "java -cp #{classpath} org.apache.tools.ant.Main -emacs all"
+ end
+end
+
+task :test => "rhino:test"
+
+namespace :johnson do
+
+ desc "create a file that loads the individual source files"
+ task :load
+
+ desc "compile johnson files into a single js file"
+ task :compile do
+ require 'rexml/document'
+ include REXML
+ doc = Document.new( File.new( "build.xml" ) ).root
+ groups = {}
+ XPath.each( doc, "//concat" ) do |concat|
+ name = concat.attributes["destfile"]
+ files =
+ XPath.match( concat, "fileset/attribute::includes" ).
+ map { |a| a.value }
+ files.reject! { |f| f == "env.js" }
+ groups[name] = files
+ end
+
+ files = groups["${ENV_RHINO}"] + groups["${ENV_DIST}"]
+
+ files.map! { |f| f.sub!( "rhino", "johnson" ); "src/" + f }
+
+ system "rm -f dist/env.johnson.js"
+ system "cat #{files.join(' ')} > dist/env.johnson.js"
+ system "chmod 444 dist/env.johnson.js"
+
+ end
+
+ desc "run tests against johnson"
+ task :test => :compile do
+ ruby "-Ilib:vendor/johnson/lib bin/envjsrb test/primaryTests.js"
+ end
+
end
+
+desc "run tests on all platforms"
+task :test => "rhino:test"
+task :test => "johnson:test"
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ s.name = "envjs"
+ s.executables = "envjsrb"
+ s.summary = "Browser environment for javascript interpreters"
+ s.email = "smparkes@smparkes.net" # Just for the ruby part ...
+ s.homepage = "http://github.com/thatcher/env-js"
+ s.description = "Browser environment for javascript interpreters"
+ s.authors = ["John Resig", "Chris Thatcher", "Glen E. Ivey" ]
+ s.files =
+ FileList[ "",
+ "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
+ end
+rescue LoadError
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
+
+# Local Variables:
+# mode:ruby
+# End:
View
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'johnson/tracemonkey'
+require 'johnson/cli'
+require 'envjs/runtime'
+
+RUNTIME = js = Johnson::Runtime.new
+RUNTIME.extend Envjs::Runtime
+RUNTIME.load "dist/env.johnson.js"
+RUNTIME.evaluate(Johnson::CLI::JS)
+
+ARGV.each do |file|
+ RUNTIME.load file
+end
+
View
@@ -0,0 +1 @@
+module Envjs; end
View
@@ -0,0 +1,54 @@
+require 'net/protocol'
+
+module Envjs; end
+module Envjs::Net; end
+
+class Envjs::Net::File < Net::Protocol
+
+ class Get
+ attr_accessor :path
+ def initialize path
+ @path = path
+ end
+ end
+
+ def initialize host, port
+ end
+
+ def self.start host, port
+ new( host, port ).start
+ end
+
+ def start
+ self
+ end
+
+ class Response
+ def initialize path
+ @path = path
+ @file = File.new @path
+ end
+
+ def getHeaderFields
+ []
+ end
+
+ def getContentEncoding
+ nil
+ end
+
+ def getResponseCode
+ @file.nil? ? 404 : 200;
+ end
+
+ def getInputStream
+ @file
+ end
+
+ end
+
+ def request request
+ Response.new request.path
+ end
+
+end
View
@@ -0,0 +1,80 @@
+module Envjs; end
+
+module Envjs::Runtime
+
+ def self.extended object
+ object.instance_eval do
+
+ global_proto = global
+
+ set_window_string =
+ evaluate("function(o,id){o.toString=function(){return'[object Window '+id+']'}}")
+
+ evaluate <<'EOJS'
+print = function() {
+ var l = arguments.length
+ for( var i = 0; i < l; i++ ) {
+ Ruby.print( arguments[i].toString() );
+ if( i < l-1 ) {
+ Ruby.print(" ");
+ }
+ }
+ Ruby.print("\n");
+};
+EOJS
+
+ self.global = new_global( global_proto )
+
+ set_window_string.call(global,global.object_id)
+
+ global_proto.globalize = lambda do
+ g = new_global global_proto
+ set_window_string.call(g,g.object_id)
+ $stderr.print "kkkk ng ", global_proto, "\n"
+ $stderr.print "kkkk ng ", evaluate("this"), "\n"
+ $stderr.print "kkkk ng ", g, "\n"
+ g
+ end
+
+ global_proto.setScope = lambda do |f, scope|
+ prev = f
+ cur = get_parent( f )
+ while _next = get_parent( cur )
+ prev = cur
+ cur = _next
+ end
+ set_parent( prev, scope )
+ end
+
+ global_proto.getScope = lambda do |f, nothing|
+ cur = f
+ while prev = get_parent( cur )
+ cur = prev
+ end
+ cur
+ end
+
+ global_proto.configureScope = lambda do |f, scopes|
+ pairs = [ [ f, get_parent( f ) ] ]
+ set_parent( f, scopes[0] )
+ scopes.each_with_index do |scope, i|
+ pairs << [ scope, get_parent( scope ) ]
+ set_parent( scope, scopes[i+1] )
+ end
+ pairs
+ end
+
+ global_proto.restoreScope = lambda do |scopes|
+ scopes.each do |pair|
+ set_parent( pair[0], pair[1] )
+ end
+ end
+
+ global_proto.load = lambda do |f|
+ self.require f
+ end
+
+ end
+ end
+
+end
View
@@ -0,0 +1,26 @@
+require 'tempfile'
+
+module Envjs; end
+
+class Envjs::TempFile < Tempfile
+
+ def initialize pattern, suffix = nil
+ super(pattern)
+
+ if suffix
+ File.link path, ( path + "." + suffix )
+ File.unlink path
+ end
+
+ @suffix = suffix
+ end
+
+ def path
+ @suffix ? ( super + "." + @suffix ) : super
+ end
+
+ def getAbsolutePath
+ path
+ end
+
+end
Oops, something went wrong.

0 comments on commit f4b79ea

Please sign in to comment.