Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / secure / capability.js @ 12

History | View | Annotate | Download (3.05 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.secure.capability"]){
9
dojo._hasResource["dojox.secure.capability"]=true;
10
dojo.provide("dojox.secure.capability");
11
dojox.secure.badProps=/^__|^(apply|call|callee|caller|constructor|eval|prototype|this|unwatch|valueOf|watch)$|__$/;
12
dojox.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"],validate:function(_1,_2,_3){
13
var _4=this.keywords;
14
for(var i=0;i<_4.length;i++){
15
_3[_4[i]]=true;
16
}
17
var _5="|this| keyword in object literal without a Class call";
18
var _6=[];
19
if(_1.match(/[\u200c-\u200f\u202a-\u202e\u206a-\u206f\uff00-\uffff]/)){
20
throw new Error("Illegal unicode characters detected");
21
}
22
if(_1.match(/\/\*@cc_on/)){
23
throw new Error("Conditional compilation token is not allowed");
24
}
25
_1=_1.replace(/\\["'\\\/bfnrtu]/g,"@").replace(/\/\/.*|\/\*[\w\W]*?\*\/|\/(\\[\/\\]|[^*\/])(\\.|[^\/\n\\])*\/[gim]*|("[^"]*")|('[^']*')/g,function(t){
26
return t.match(/^\/\/|^\/\*/)?" ":"0";
27
}).replace(/\.\s*([a-z\$_A-Z][\w\$_]*)|([;,{])\s*([a-z\$_A-Z][\w\$_]*\s*):/g,function(t,_7,_8,_9){
28
_7=_7||_9;
29
if(/^__|^(apply|call|callee|caller|constructor|eval|prototype|this|unwatch|valueOf|watch)$|__$/.test(_7)){
30
throw new Error("Illegal property name "+_7);
31
}
32
return (_8&&(_8+"0:"))||"~";
33
});
34
_1.replace(/([^\[][\]\}]\s*=)|((\Wreturn|\S)\s*\[\s*\+?)|([^=!][=!]=[^=])/g,function(_a){
35
if(!_a.match(/((\Wreturn|[=\&\|\:\?\,])\s*\[)|\[\s*\+$/)){
36
throw new Error("Illegal operator "+_a.substring(1));
37
}
38
});
39
_1=_1.replace(new RegExp("("+_2.join("|")+")[\\s~]*\\(","g"),function(_b){
40
return "new(";
41
});
42
function _c(_d,_e){
43
var _f={};
44
_d.replace(/#\d+/g,function(b){
45
var _10=_6[b.substring(1)];
46
for(var i in _10){
47
if(i==_5){
48
throw i;
49
}
50
if(i=="this"&&_10[":method"]&&_10["this"]==1){
51
i=_5;
52
}
53
if(i!=":method"){
54
_f[i]=2;
55
}
56
}
57
});
58
_d.replace(/(\W|^)([a-z_\$A-Z][\w_\$]*)/g,function(t,a,_11){
59
if(_11.charAt(0)=="_"){
60
throw new Error("Names may not start with _");
61
}
62
_f[_11]=1;
63
});
64
return _f;
65
};
66
var _12,_13;
67
function _14(t,_15,a,b,_16,_17){
68
_17.replace(/(^|,)0:\s*function#(\d+)/g,function(t,a,b){
69
var _18=_6[b];
70
_18[":method"]=1;
71
});
72
_17=_17.replace(/(^|[^_\w\$])Class\s*\(\s*([_\w\$]+\s*,\s*)*#(\d+)/g,function(t,p,a,b){
73
var _19=_6[b];
74
delete _19[_5];
75
return (p||"")+(a||"")+"#"+b;
76
});
77
_13=_c(_17,_15);
78
function _1a(t,a,b,_1b){
79
_1b.replace(/,?([a-z\$A-Z][_\w\$]*)/g,function(t,_1c){
80
if(_1c=="Class"){
81
throw new Error("Class is reserved");
82
}
83
delete _13[_1c];
84
});
85
};
86
if(_15){
87
_1a(t,a,a,_16);
88
}
89
_17.replace(/(\W|^)(var) ([ \t,_\w\$]+)/g,_1a);
90
return (a||"")+(b||"")+"#"+(_6.push(_13)-1);
91
};
92
do{
93
_12=_1.replace(/((function|catch)(\s+[_\w\$]+)?\s*\(([^\)]*)\)\s*)?{([^{}]*)}/g,_14);
94
}while(_12!=_1&&(_1=_12));
95
_14(0,0,0,0,0,_1);
96
for(i in _13){
97
if(!(i in _3)){
98
throw new Error("Illegal reference to "+i);
99
}
100
}
101
}};
102
}