declare var io ; module JS { export class XMLHttpRequest { static readonly UNSENT = 0 ; static readonly OPENED = 1 ; static readonly HEADERS_RECEIVED = 2 ; static readonly LOADING = 3 ; static readonly DONE = 4 ; public readyState : number ; public responseType : string ; public status : number ; public statusText : string ; public responseText : string ; private callbacks : Map < any > ; private url : string ; public open ( method , url , asyncType ) { this . url = url ; this . readyState = XMLHttpRequest . OPENED ; } public addEventListener ( eventName , cb , flag ? ) { if ( ! this . callbacks ) { this . callbacks = { } ; } this . callbacks [ eventName ] = cb ; } public removeEventListener ( eventName , cb , flag ? ) { if ( ! this . callbacks ) { return ; } delete this . callbacks [ eventName ] ; } public send ( body ? ) { this . readyState = XMLHttpRequest . LOADING ; const prefix = 'file://' ; const actualPrefix = this . url . substr ( 0 , prefix . length ) ; const absPath = actualPrefix === prefix ? this . url . substr ( prefix . length ) : this . url ; const file = table . pack ( io . open ( absPath , 'r' ) ) ; if ( file [ 1 ] ) { const data = file [ 1 ] . read ( '*all' ) ; this . responseText = string . gsub ( data , '^\xef\xbb\xbf' , '' ) ; this . status = 200 ; } else { this . status = 404 ; this . statusText = file [ 2 ] ; } this . readyState = XMLHttpRequest . DONE ; const readystatechangeCallback = this . callbacks [ 'readystatechange' ] ; if ( readystatechangeCallback ) { readystatechangeCallback ( ) ; } const loadendCallback = this . callbacks [ 'loadend' ] ; if ( loadendCallback ) { loadendCallback ( ) ; } } } }