Anonymous avatar Anonymous committed 4bc6704

more xhr impl
compilation step for JS
spidermonkey dependency

Comments (0)

Files changed (4)

 ^src/.+\.o$
 ^ebin/
-^lib/
+^lib/
+^js/.+\.jsc$
 APPS = $(wildcard $(ERL_DIR)/*.app)
 APP_TARGETS = $(addprefix $(EBIN_DIR)/,$(notdir $(APPS)))
 
+JS_FILES = $(wildcard js/*.js)
+JSC_FILES = $(addsuffix .jsc,$(notdir $(basename $(JS_FILES))))
+JSC_TARGETS = $(addprefix js/,$(JSC_FILES))
+
 #Compile flags
 CXXFLAGS  = -I./include $(V8_INC) $(ERL_INC) -g -Wall
 
 
 localdirs: $(LIB_DIR) $(EBIN_DIR)
 
-all: localdirs $(LIB_TARGETS) $(BEAM_TARGETS) $(APP_TARGETS)
+all: localdirs $(LIB_TARGETS) $(BEAM_TARGETS) $(APP_TARGETS) $(JSC_TARGETS)
 
 $(SRC_DIR)/%.o: $(SRC_DIR)/%.cc
 	$(CPP) -c $(CXXFLAGS) -o $@ $<
 	rm -f src/*.o
 	rm -rf $(LIB_DIR)
 	rm -rf $(EBIN_DIR)
+	rm -f $(JSC_TARGETS)
 
 .PHONY: all clean erl localdirs
 
+js/%.jsc: js/%.js
+	js -s -C $<
+	touch $@

js/basic.js

-true;
 var SecurityError = makeError();
 var NotSupportedError = makeError();
 var InvalidStateError = makeError();
+var NetworkError = makeError();
 
 
 // TODO: Headers needs to append values for SOME keys... not sure which yet.
 			}
 		}
 		return out.join('');
+	},
+
+	'toObject': function() {
+		var headers = {};
+		oeach.call(this, this.canonical, function(key, value) {
+			headers[this.original[key]] = value;
+		});
+		return headers;
 	}
 };
 
 	},
 
 	'send': function(data) {
-		// TODO
+		if (this.readyState != this.OPENED) {
+			throw new InvalidStateError('XHR not OPENED');
+		}
+
+		if (this.sent) {
+			throw new InvalidStateError('XHR already sent');
+		}
+
+		if (this.method.match(/GET|HEAD/i)) {
+			data = null;
+		}
+
+		this.requestBody = data;
+		this.error = false;
+
+		var request = {
+			'async': this.async,
+			'method': this.method, 
+			'user': this.user,
+			'password': this.password,
+			'body': this.requestBody,
+			'headers': this.requestHeaders.toObject(),
+			'onNetworkError': method(this, 'onNetworkError')
+		};
+		
+		if (this.async) {
+			this.sent = true;
+			this.onreadystatechange();
+			request.onHeaders = method(this, 'onHeaders');
+			request.onData = method(this, 'onData');
+		}
+
+		this.requestId = v8.http.request(request);
+	},
+
+	'onHeaders': function(headers) {
+		this.responseHeaders = new Headers(headers);
+		this.readyState = this.HEADERS_RECEIVED;
+		this.onreadystatechange();
+	},
+
+	// FIXME: this isn't quite right yet.
+	'onData': function(data, done) {
+		this.responseText = data;
+		this.readyState = done ? this.DONE : this.LOADING;
+		this.onreadystatechange();
+	},
+
+	'onNetworkError': function() {
+		extend(this, {
+			'responseText': null,
+			'responseXML': null
+		});
+		this.requestHeaders.clear();
+		this.readyState = this.DONE;
+		
+		if (async) {
+			this.onreadystatechange();
+		} else {
+			throw new NetworkError();
+		}
 	},
 
 	'abort': function() {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.