Bug 44848 - xmlhttprequest event javascript String functions not available
Summary: xmlhttprequest event javascript String functions not available
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: PC Linux
: P2 Major
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-29 19:46 PDT by ss
Modified: 2014-04-24 16:45 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ss 2010-08-29 19:46:03 PDT
In a xmlhttprequest progress event callback. I try to use 
var t = "test" ;
var p = t.subStr(2);

and it fails

the javascript string functions are not available
 

CODE *****

function maChat() {
	this.url = "/mafw/chat.ma";
}
maChat.prototype = new maWeb( this.url );

function callback( evt, maweb ) {
	var t = "test";
	var p = t.subStr(2);
	var obj = maweb.getObj( evt );
	var stat = maweb.getStat( evt );
	alert( stat["code"]+stat["text"]+" "+ JSON.stringify( obj ) );
}

function sendmsg( ) {
	var cmd = {};
	cmd["type"] = "cmd";
	cmd["cmd"] = "initdata";
	cmd["me"] = 0;

	try {
		var conn = new maWeb( "http://localhost/mafw/chat.ma" );
		conn.send( JSON.stringify ( cmd ), callback );
	} catch (e ) {
		alert (e);
	}
//	try {
//		var conn1 = new maChat();
//		conn1.send( JSON.stringify ( cmd ), callback );
//	} catch (e ) {
//		alert (e);
//	}
};


function sendpush() {
	var cmd = {};
	cmd["type"] = "cmd";
	cmd["cmd"] = "initdata";
	cmd["me"] = 0;

	try {
		var conn = new maWeb( "http://localhost/mafw/chat.psh", true );
		conn.setProgress( callback );
		conn.send( JSON.stringify ( cmd ), callback );
	} catch (e ) {
		alert (e);
	}
}


CODE2 *********************************

function maWeb( url, push, method ) {
	this.method = "POST";
	this.multi = false;
	this.url = url;
	this.self = this;
	this.oldLen = 0;
	
	if ( method != undefined )
		this.method = method;
		
	if ( push != undefined )
		this.multi = push;

	var req = new XMLHttpRequest();
	this._req = req;
	req.multipart = this.multi;
	
	this.send = function( data, loadcb ) {
		var self = this;
		this._req.onload = function( evt ) {
			loadcb( evt, self );
			return false;
		};
		this._req.open( this.method, this.url, true );
		try {
			this._req.send( data );
		} catch (e) {
			alert( e );
		}
	};	
			
	this.setProgress = function( func ) {
		var self = this;
		self._req.onprogress = function ( evt ) {
			return func( evt, self );
		}	
	};	
	
	this.addCallback = function( name, func ) {
		var self = this;
		var cb = function ( evt ) {
			var r = evt.target;
			var s = r.responseText.length;
			func( evt, self );
		}
		switch( name ) { 
		case "loadstart":
			req.onloadstart  = cb;
			break;
		case "progress":
			req.onprogress  = cb;
			break;
		case "abort":
			req.onabort  = cb;
			break;
		case "error":
			req.onerror  = cb;
			break;
		default:
			req.addEventListener( name, function ( evt ) {
				func( evt, self );
			}, false);
		};
	};
	
	this.abort = function() {
		req.abort();
	};
	
	this.getObj = function( evt ) {
		var r = evt.target;
		var str;
		switch ( r.readyState ) {
		case 4:	//Firefox
		case 2:	//Chrome
			str = r.responseText;
			break;
		case 3: //Chrome
			str = r.responseText.subStr( this.oldLen );
			this.oldLen = r.responseText.length;
			break;
		default:
			break;			
		};
		try {
			var obj = JSON.parse( str );
		} catch (e) {
			alert( e );
		}
		return obj
	};
	
	this.getStat = function( evt ) {
		var r = evt.target;
		var stat = {};
		stat["code"] = r.status;
		stat["text"] = r.statusText;
		return stat;
	}
};
Comment 1 Darin Adler 2014-04-24 16:45:18 PDT
Moving all JavaScriptGlue bugs to JavaScriptCore. The JavaScriptGlue framework itself is long gone. And most of the more recent bugs put in this component were put there by people who thought this was for some other aspect of “JavaScript glue” and have nothing to do with the actual original reason for the existence of this component, which was an OS-X-only framework named JavaScriptGlue.