Skip to content

Commit

Permalink
define xhr on window
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsofapollo committed Aug 18, 2012
1 parent 1552d8a commit 4ed156d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 17 additions & 5 deletions lib/loader.js
@@ -1,9 +1,11 @@
const Cc = Components.classes;
const Ci = Components.interfaces;

const mozIJSSubScriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1']
.getService(Components.interfaces.mozIJSSubScriptLoader);

const mozIJSSubScriptLoader = Cc[
'@mozilla.org/moz/jssubscript-loader;1'
].getService(
Components.interfaces.mozIJSSubScriptLoader
);

var args = _ARGV.split(' ');

Expand All @@ -23,13 +25,14 @@ function importLib(file) {
// Map resource://xpcwindow/ to lib/
(function() {

var fileObj = Cc["@mozilla.org/file/local;1"]
var fileObj = Cc['@mozilla.org/file/local;1']
.createInstance(Ci.nsILocalFile);

fileObj.initWithPath(_ROOT);

let (ios = Components.classes['@mozilla.org/network/io-service;1']
let(ios = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService)) {

let protocolHandler =
ios.getProtocolHandler('resource')
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
Expand All @@ -44,6 +47,15 @@ var window = this.window = {
xpcComponents: Components,
xpcArgv: args,

get XMLHttpRequest() {
var comp = Components.Constructor(
'@mozilla.org/xmlextras/xmlhttprequest;1'
);

delete window.XMLHttpRequest;
return window.XMLHttpRequest = comp;
},

get TCPSocket() {
var comp = '@mozilla.org/tcp-socket;1';
//lazy get MozTCPSocket
Expand Down
6 changes: 1 addition & 5 deletions test/xhr-test.js
@@ -1,10 +1,6 @@
describe("xhr", function() {
describe('xhr', function() {

it('should work', function(done) {
var Cc = Components.classes,
Ci = Components.interfaces,
XMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1");

var xhr = new XMLHttpRequest();

xhr.open('GET', 'http://google.com', true);
Expand Down

0 comments on commit 4ed156d

Please sign in to comment.