capability.js
2.49 KB
//>>built
define(["dojo","dijit","dojox"],function(l,q,b){l.provide("dojox.secure.capability");b.secure.badProps=/^__|^(apply|call|callee|caller|constructor|eval|prototype|this|unwatch|valueOf|watch)$|__$/;b.secure.capability={keywords:"break case catch const continue debugger default delete do else enum false finally for function if in instanceof new null yield return switch throw true try typeof var void while".split(" "),validate:function(a,g,b){function l(a,m){var c={};a.replace(/#\d+/g,function(a){a=h[a.substring(1)];
for(var f in a){if("|this| keyword in object literal without a Class call"==f)throw f;"this"==f&&a[":method"]&&1==a["this"]&&(f="|this| keyword in object literal without a Class call");":method"!=f&&(c[f]=2)}});a.replace(/(\W|^)([a-z_\$A-Z][\w_\$]*)/g,function(a,f,d){if("_"==d.charAt(0))throw Error("Names may not start with _");c[d]=1});return c}function n(a,m,c,e,f,b){function d(a,d,b,c){c.replace(/,?([a-z\$A-Z][_\w\$]*)/g,function(a,d){if("Class"==d)throw Error("Class is reserved");delete k[d]})}
b.replace(/(^|,)0:\s*function#(\d+)/g,function(a,d,b){h[b][":method"]=1});b=b.replace(/(^|[^_\w\$])Class\s*\(\s*([_\w\$]+\s*,\s*)*#(\d+)/g,function(a,d,b,c){delete h[c]["|this| keyword in object literal without a Class call"];return(d||"")+(b||"")+"#"+c});k=l(b,m);m&&d(a,c,c,f);b.replace(/(\W|^)(var) ([ \t,_\w\$]+)/g,d);return(c||"")+(e||"")+"#"+(h.push(k)-1)}for(var p=this.keywords,e=0;e<p.length;e++)b[p[e]]=!0;var h=[];if(a.match(/[\u200c-\u200f\u202a-\u202e\u206a-\u206f\uff00-\uffff]/))throw Error("Illegal unicode characters detected");
if(a.match(/\/\*@cc_on/))throw Error("Conditional compilation token is not allowed");a=a.replace(/\\["'\\\/bfnrtu]/g,"@").replace(/\/\/.*|\/\*[\w\W]*?\*\/|("[^"]*")|('[^']*')/g,function(a){return a.match(/^\/\/|^\/\*/)?" ":"0"}).replace(/\.\s*([a-z\$_A-Z][\w\$_]*)|([;,{])\s*([a-z\$_A-Z][\w\$_]*\s*):/g,function(a,b,c,e){b=b||e;if(/^__|^(apply|call|callee|caller|constructor|eval|prototype|this|unwatch|valueOf|watch)$|__$/.test(b))throw Error("Illegal property name "+b);return c&&c+"0:"||"~"});a.replace(/([^\[][\]\}]\s*=)|((\Wreturn|\S)\s*\[\s*\+?)|([^=!][=!]=[^=])/g,
function(a){if(!a.match(/((\Wreturn|[=\&\|\:\?\,])\s*\[)|\[\s*\+$/))throw Error("Illegal operator "+a.substring(1));});a=a.replace(new RegExp("("+g.join("|")+")[\\s~]*\\(","g"),function(a){return"new("});var k;do g=a.replace(/((function|catch)(\s+[_\w\$]+)?\s*\(([^\)]*)\)\s*)?{([^{}]*)}/g,n);while(g!=a&&(a=g));n(0,0,0,0,0,a);for(e in k)if(!(e in b))throw Error("Illegal reference to "+e);}}});