question: private Object js_escape ( Object [ ] args ) { final int URL_XALPHAS = 1 , URL_XPALPHAS = 2 , URL_PATH = 4 ; String s = ScriptRuntime . toString ( args , 0 ) ; int mask = URL_XALPHAS | URL_XPALPHAS | URL_PATH ; if ( args . length > 1 ) { double d = ScriptRuntime . toNumber ( args [ 1 ] ) ; if ( d != d || ( ( mask = ( int ) d ) != d ) || 0 != ( mask & ~ ( URL_XALPHAS | URL_XPALPHAS | URL_PATH ) ) ) { throw Context . reportRuntimeError0 ( "msg.bad.esc.mask" ) ; } } StringBuffer sb = null ; for ( int k = 0 , L = s . length ( ) ; k != L ; ++ k ) { int c = s . charAt ( k ) ; if ( mask != 0 && ( ( c >= '0' && c <= '9' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= 'a' && c <= 'z' ) || c == '@' || c == '*' || c == '_' || c == '-' || c == '.' || ( 0 != ( mask & URL_PATH ) && ( c == '/' || c == '+' ) ) ) ) { if ( sb != null ) { sb . append ( ( char ) c ) ; } } else { if ( sb == null ) { sb = new StringBuffer ( L + 3 ) ; sb . append ( s ) ; sb . setLength ( k ) ; } int hexSize ; if ( c < 256 ) { if ( c == ' ' && mask == URL_XPALPHAS ) { sb . append ( '+' ) ; continue ; } sb . append ( '%' ) ; hexSize = 2 ; } else { sb . append ( '%' ) ; sb . append ( 'u' ) ; hexSize = 4 ; } for ( int shift = ( hexSize - 1 ) * 4 ; shift >= 0 ; shift -= 4 ) { int digit = 0xf & ( c > > shift ) ; int hc = ( digit < 10 ) ? '0' + digit : 'A' - 10 + digit ; sb . append ( ( char ) hc ) ; } } } return ( sb == null ) ? s : sb . toString ( ) ; }
target:  The global method escape, as per ECMA-262 15.1.2.4. Includes code for the 'mask' argument supported by the C escape method, which used to be part of the browser imbedding.  Blame for the strange constant names should be directed there.