Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
moving browser.js, testing browser.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Apr 30, 2008
1 parent bdaf170 commit faeef59
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
3 changes: 3 additions & 0 deletions js/johnson/browser.js
@@ -0,0 +1,3 @@
Johnson.require("johnson/browser/xmlw3cdom");
Johnson.require("johnson/browser/xmlsax");
Johnson.require("johnson/browser/env");
20 changes: 11 additions & 9 deletions browser/env.js → js/johnson/browser/env.js
Expand Up @@ -7,8 +7,6 @@
// The window Object
var window = this;

Johnson.require("xmlw3cdom");
Johnson.require("xmlsax");
Ruby.require("uri");

print = function(txt) { Ruby.puts(txt); };
Expand All @@ -31,14 +29,17 @@ print = function(txt) { Ruby.puts(txt); };

window.__defineSetter__("location", function(url){
var xhr = new XMLHttpRequest();
xhr.async = false;
xhr.open("GET", url);
xhr.onreadystatechange = function(){
curLocation = curLocation.merge(url);
window.document = xhr.responseXML;

var event = document.createEvent();
event.initEvent("load");
window.dispatchEvent( event );
if(window.document) {
var event = document.createEvent();
event.initEvent("load");
window.dispatchEvent( event );
}
};
xhr.send();
});
Expand All @@ -52,7 +53,7 @@ print = function(txt) { Ruby.puts(txt); };
return curLocation.toString();
},
toString: function(){
return this.to_s();
return this.href.toString();
}
};
});
Expand Down Expand Up @@ -585,7 +586,7 @@ print = function(txt) { Ruby.puts(txt); };
getResponseHeader: function(header){ },
send: function(data){
var self = this;

function makeRequest(){
var url = curLocation.merge(self.url);
var connection;
Expand All @@ -606,7 +607,7 @@ print = function(txt) { Ruby.puts(txt); };
connection = {
code: "200",
message: "Ok",
body: file.read()
body: file,
}
handleResponse();
} else {
Expand Down Expand Up @@ -651,6 +652,7 @@ print = function(txt) { Ruby.puts(txt); };
}

if (this.async)
// FIXME: This is segfaulting
new Ruby.Thread(function() { makeRequest(); });
else
makeRequest();
Expand Down Expand Up @@ -690,4 +692,4 @@ print = function(txt) { Ruby.puts(txt); };
responseText: "",
status: 0
};
})();
})();
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion lib/johnson.rb
Expand Up @@ -26,7 +26,6 @@
require "johnson/parser"

$LOAD_PATH.push(File.expand_path("#{File.dirname(__FILE__)}/../js"))
$LOAD_PATH.push(File.expand_path("#{File.dirname(__FILE__)}/../browser"))

module Johnson
PRELUDE = IO.read(File.dirname(__FILE__) + "/../js/johnson/prelude.js")
Expand Down
17 changes: 17 additions & 0 deletions test/johnson/browser_test.rb
@@ -0,0 +1,17 @@
require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))

module Johnson
class BrowserTest < Johnson::TestCase
def setup
@context = Johnson::Context.new
@context.evaluate('Johnson.require("johnson/browser");')
end

def test_set_location_returns_location
filename = "file://#{File.expand_path(__FILE__)}"
@context.evaluate("window.location = '#{filename}'")
uri = URI.parse(filename)
assert_equal(uri.to_s, @context.evaluate('window.location').to_s)
end
end
end

0 comments on commit faeef59

Please sign in to comment.