Changeset 13839 for lang/javascript/clone
- Timestamp:
- 06/14/08 02:45:51 (5 years ago)
- Location:
- lang/javascript/clone/trunk
- Files:
-
- 2 modified
-
uneval.html (modified) (3 diffs)
-
uneval.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/clone/trunk/uneval.html
r2060 r13839 1 1 <head> 2 <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"> 2 3 <script src="uneval.js"></script> 3 4 <script> … … 13 14 'boolean' :false, 14 15 'number' :1, 15 'string' :'Can\'t you "uneval" this? \\',16 'string' :'Can\'t you\n\t"uneval" this? façade\\漢字', 16 17 'null' :null, 17 18 'undefined':undefined, … … 56 57 </dd> 57 58 <dt>stdout:</dt> 58 <dd>< div id="stdout"></div></dd>59 <dd><pre id="stdout"></pre></dd> 59 60 <dt>stderr:</dt> 60 61 <dd><div id="stderr"></div></dd> -
lang/javascript/clone/trunk/uneval.js
r12158 r13839 3 3 */ 4 4 5 (function(){ 6 // if uneval is predefined, skip it 7 try{ eval('uneval'); return; }catch(e){}; 8 5 try{ 6 eval('uneval'); 7 }catch(e){ 9 8 var protos = []; 9 var char2esc = {'\t':'t','\n':'n','\v':'v','\f':'f','\r':'\r', 10 '\'':'\'','\"':'\"','\\':'\\'}; 11 var escapeChar = function(c){ 12 if (c in char2esc) return '\\' + char2esc[c]; 13 var ord = c.charCodeAt(0); 14 return ord < 0x20 ? '\\x0' + ord.toString(16) 15 : ord < 0x7F ? '\\' + c 16 : ord < 0x100 ? '\\x' + ord.toString(16) 17 : ord < 0x1000 ? '\\u0' + ord.toString(16) 18 : '\\u' + ord.toString(16) 19 }; 10 20 var uneval_asis = function(o){ return o.toString() }; 11 12 21 /* predefine objects where typeof(o) != 'object' */ 13 22 var name2uneval = { … … 15 24 'number': uneval_asis, 16 25 'string': function(o){ 17 return '\'' 18 + o.toString().replace(/[\\\"\']/g, function(m0){ 19 return '\\' + m0; 20 }) 21 + '\''; 26 return '\'' 27 + o.toString().replace(/[\x00-\x1F\'\"\\\u007F-\uFFFF]/g, escapeChar) 28 + '\'' 22 29 }, 23 30 'undefined': function(o){ return 'undefined' }, … … 68 75 return func(o, np); 69 76 } 70 } )();77 } 71 78 72 (function(){ 73 try{ eval('clone'); return; }catch(e){}; 79 try{ 80 eval('clone'); 81 } 82 catch(e){ 74 83 clone = function(o){ 75 try{76 return eval(uneval(o));77 }catch(e){78 throw(e);79 }84 try{ 85 return eval(uneval(o)); 86 }catch(e){ 87 throw(e); 88 } 80 89 }; 81 } )();90 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)