├── src ├── util │ ├── EncapsulationAnalysis │ │ ├── NewVersion │ │ │ ├── Tests │ │ │ │ ├── Cajita │ │ │ │ │ ├── cajitamin │ │ │ │ │ ├── test.js │ │ │ │ │ └── a.out │ │ │ │ ├── test20.js │ │ │ │ ├── test15.js │ │ │ │ ├── test13.js │ │ │ │ ├── test14.js │ │ │ │ ├── nativeTest1.js │ │ │ │ ├── test16.js │ │ │ │ ├── test23.js │ │ │ │ ├── globalVarTest2.js │ │ │ │ ├── test3.js │ │ │ │ ├── globalVarTest1.js │ │ │ │ ├── globalVarTest3.js │ │ │ │ ├── test6.js │ │ │ │ ├── test11.js │ │ │ │ ├── test19.js │ │ │ │ ├── test17.js │ │ │ │ ├── test18.js │ │ │ │ ├── test21.js │ │ │ │ ├── test12.js │ │ │ │ ├── AdsafeTests │ │ │ │ │ ├── test3.js │ │ │ │ │ ├── adsafeAnnTest2.js │ │ │ │ │ ├── test18.js │ │ │ │ │ ├── adsafeAnn2.js │ │ │ │ │ ├── adsafeAnnTest2Result │ │ │ │ │ ├── adsafeAnntes2Result │ │ │ │ │ └── adsafeAnntes3Result │ │ │ │ ├── test2.js │ │ │ │ ├── primTest1.js │ │ │ │ ├── provenanceTest1.js │ │ │ │ ├── test10.js │ │ │ │ ├── test4.js │ │ │ │ ├── provenanceTest2.js │ │ │ │ ├── test5.js │ │ │ │ ├── globalVarTest4.js │ │ │ │ ├── throwTest1.js │ │ │ │ ├── test1.js │ │ │ │ ├── test8.js │ │ │ │ ├── protoTest1.js │ │ │ │ ├── arrLengthTest1.js │ │ │ │ ├── test9.js │ │ │ │ ├── test7.js │ │ │ │ ├── table.js │ │ │ │ ├── runTestOld │ │ │ │ ├── CajitaTests │ │ │ │ │ ├── cajita.js │ │ │ │ │ └── cajita41.js │ │ │ │ ├── SealerUnsealer │ │ │ │ │ ├── suBroken.js │ │ │ │ │ └── suFixed.js │ │ │ │ ├── Mint │ │ │ │ │ └── mint.js │ │ │ │ └── PhuPhung │ │ │ │ │ ├── enfPolicyWorks.js │ │ │ │ │ └── enfPolicy.js │ │ │ ├── runTests │ │ │ ├── preciousDatalog.js │ │ │ ├── preciousDatalogAdsafe.js │ │ │ ├── preciousInverseDatalog.js │ │ │ └── datalogFieldNames.js │ │ └── datalogFieldNames.js │ └── sets.js ├── traits │ ├── Traits.png │ ├── README.md │ └── evolution-problem.js ├── ses │ ├── strict-debug-bug.html │ ├── amdTest1.js │ ├── amdTestDir │ │ └── amdTest2.js │ ├── amdTest.js │ ├── ses-usage-eval.js │ ├── amdTest3.js │ ├── ses-usage.js │ ├── contract │ │ ├── makeMint.es7 │ │ ├── makeMint.js │ │ ├── escrowExchange.es7 │ │ └── escrowExchange.js │ ├── hookupSES.js │ ├── hookupSESPlus.js │ ├── StringMap.js │ └── contractTest.js ├── q │ ├── Queue-harmony.js │ └── Queue.js └── proxies │ ├── testDirectProxies.html │ └── testFixedTrappingProxy.html ├── doc ├── esop13 │ ├── common.bib │ ├── llncs.doc │ ├── llncs.dvi │ ├── 5players.pdf │ ├── bw-mint.pdf │ ├── llncsdoc.pdf │ ├── cyclic-circuit.pdf │ ├── sprmindx.sty │ ├── remreset.sty │ ├── readme.txt │ └── llncsdoc.sty ├── proxies │ ├── MetaLevelShifting.png │ ├── bm │ │ ├── Proxies vs No Proxies BM.csv │ │ └── Proxies Benchmark.csv │ └── revocableRefManual.js ├── es5-states │ ├── es5-attr-states.odg │ ├── es5-attr-states.pdf │ └── es5-attr-states.png └── proxies-final │ ├── MetaLevelShifting.png │ ├── bm │ ├── Proxies vs No Proxies BM.csv │ └── Proxies Benchmark.csv │ └── revocableRefManual.js ├── site └── traits │ ├── images │ ├── download.png │ ├── header_bg.png │ ├── content_top.png │ └── content_bottom.png │ ├── sidebar.css │ ├── prettify.css │ └── test.html ├── tests ├── harmony │ ├── gentests │ ├── README │ ├── genhtmltests │ ├── TestCases │ │ ├── trap-arguments │ │ │ ├── util.js │ │ │ ├── fix.js │ │ │ ├── has.js │ │ │ ├── delete.js │ │ │ ├── hasOwn.js │ │ │ ├── enumerateOwn.js │ │ │ ├── get.js │ │ │ ├── set.js │ │ │ ├── enumerate.js │ │ │ ├── getOwnPropertyNames.js │ │ │ ├── defineProperty.js │ │ │ ├── getOwnPropertyDescriptor.js │ │ │ ├── getPropertyDescriptor.js │ │ │ └── invoke.js │ │ ├── doublelifting │ │ │ ├── fix.js │ │ │ ├── has.js │ │ │ ├── delete.js │ │ │ ├── hasOwn.js │ │ │ ├── enumerateOwn.js │ │ │ ├── set.js │ │ │ ├── get.js │ │ │ ├── enumerate.js │ │ │ ├── invoke.js │ │ │ ├── getOwnPropertyNames.js │ │ │ ├── defineProperty.js │ │ │ ├── getOwnPropertyDescriptor.js │ │ │ ├── getPropertyDescriptor.js │ │ │ └── util.js │ │ ├── defaultProto.js │ │ ├── trap-throws │ │ │ ├── get.js │ │ │ ├── fix.js │ │ │ ├── has.js │ │ │ ├── set.js │ │ │ ├── delete.js │ │ │ ├── invoke.js │ │ │ ├── enumerate.js │ │ │ ├── hasOwn.js │ │ │ ├── enumerateOwn.js │ │ │ ├── defineProperty.js │ │ │ ├── getOwnPropertyNames.js │ │ │ ├── util.js │ │ │ ├── getOwnPropertyDescriptor.js │ │ │ └── getPropertyDescriptor.js │ │ ├── invoke.js │ │ ├── denyfix.js │ │ ├── fixidentity.js │ │ ├── invokeDelegator.js │ │ ├── constructor.js │ │ ├── functionproxies.js │ │ └── handlersharing.js │ ├── license.html │ └── example.js ├── parser │ ├── unit.js │ └── parsertests.html └── unit.js ├── run-parser-tests.js ├── ProjectHome.md ├── load-ometa.js ├── SecureableES5.md ├── Makefile ├── SecureEcmaScript.md └── SafeMashups.md /src/util/EncapsulationAnalysis/NewVersion/Tests/Cajita/cajitamin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/Cajita/test.js: -------------------------------------------------------------------------------- 1 | var a = 10 2 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test20.js: -------------------------------------------------------------------------------- 1 | attacker = this 2 | -------------------------------------------------------------------------------- /doc/esop13/common.bib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/esop13/common.bib -------------------------------------------------------------------------------- /doc/esop13/llncs.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/esop13/llncs.doc -------------------------------------------------------------------------------- /doc/esop13/llncs.dvi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/esop13/llncs.dvi -------------------------------------------------------------------------------- /src/traits/Traits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/src/traits/Traits.png -------------------------------------------------------------------------------- /doc/esop13/5players.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/esop13/5players.pdf -------------------------------------------------------------------------------- /doc/esop13/bw-mint.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/esop13/bw-mint.pdf -------------------------------------------------------------------------------- /doc/esop13/llncsdoc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/esop13/llncsdoc.pdf -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test15.js: -------------------------------------------------------------------------------- 1 | attacker = Object.prototype.toString 2 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test13.js: -------------------------------------------------------------------------------- 1 | attacker = {a: function reachable(){}} 2 | -------------------------------------------------------------------------------- /src/traits/README.md: -------------------------------------------------------------------------------- 1 | The latest version of traits.js lives [here](https://github.com/traitsjs/traits.js). -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test14.js: -------------------------------------------------------------------------------- 1 | Array.prototype.concat(document); 2 | 3 | 4 | -------------------------------------------------------------------------------- /doc/esop13/cyclic-circuit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/esop13/cyclic-circuit.pdf -------------------------------------------------------------------------------- /site/traits/images/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/site/traits/images/download.png -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/nativeTest1.js: -------------------------------------------------------------------------------- 1 | var a = new Array(); 2 | 3 | //attacker = a 4 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test16.js: -------------------------------------------------------------------------------- 1 | Object.prototype.hasOwnProperty(document); 2 | 3 | -------------------------------------------------------------------------------- /doc/proxies/MetaLevelShifting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/proxies/MetaLevelShifting.png -------------------------------------------------------------------------------- /site/traits/images/header_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/site/traits/images/header_bg.png -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test23.js: -------------------------------------------------------------------------------- 1 | window[a] = function(){precious}; 2 | 3 | attacker = 0; 4 | -------------------------------------------------------------------------------- /doc/es5-states/es5-attr-states.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/es5-states/es5-attr-states.odg -------------------------------------------------------------------------------- /doc/es5-states/es5-attr-states.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/es5-states/es5-attr-states.pdf -------------------------------------------------------------------------------- /doc/es5-states/es5-attr-states.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/es5-states/es5-attr-states.png -------------------------------------------------------------------------------- /doc/esop13/sprmindx.sty: -------------------------------------------------------------------------------- 1 | delim_0 "\\idxquad " 2 | delim_1 "\\idxquad " 3 | delim_2 "\\idxquad " 4 | delim_n ",\\," 5 | -------------------------------------------------------------------------------- /site/traits/images/content_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/site/traits/images/content_top.png -------------------------------------------------------------------------------- /site/traits/sidebar.css: -------------------------------------------------------------------------------- 1 | /* this is the default float for the sidebar */ 2 | #sidebarContainer { 3 | float: right; 4 | } -------------------------------------------------------------------------------- /site/traits/images/content_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/site/traits/images/content_bottom.png -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/globalVarTest2.js: -------------------------------------------------------------------------------- 1 | a = function NOTreachable(){} 2 | 3 | attacker = window.b 4 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test3.js: -------------------------------------------------------------------------------- 1 | attacker = function reachable1(){return function reachble2(){}} 2 | -------------------------------------------------------------------------------- /doc/proxies-final/MetaLevelShifting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/doc/proxies-final/MetaLevelShifting.png -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/globalVarTest1.js: -------------------------------------------------------------------------------- 1 | var a = function reachable(){} 2 | 3 | attacker = window.a 4 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/globalVarTest3.js: -------------------------------------------------------------------------------- 1 | window.a = function reachable(){} 2 | 3 | attacker = a; 4 | 5 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test6.js: -------------------------------------------------------------------------------- 1 | function foo(){return function reachable(){}} 2 | 3 | attacker = foo() 4 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test11.js: -------------------------------------------------------------------------------- 1 | a = {} 2 | a[$A$Num(b)] = function reachable(){} 3 | 4 | attacker = a[n] 5 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test19.js: -------------------------------------------------------------------------------- 1 | var o = {}; 2 | 3 | o.f(function precious(){}); 4 | 5 | attacker = ""; 6 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test17.js: -------------------------------------------------------------------------------- 1 | Object.prototype.hasOwnProperty(document); 2 | attacker = function (f,x){f(x)} 3 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test18.js: -------------------------------------------------------------------------------- 1 | Array.prototype.concat(document); 2 | 3 | attacker = function (f){return f();} 4 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test21.js: -------------------------------------------------------------------------------- 1 | var ___; 2 | attacker = (function(){___ = {mark: function NOTreachable(){} }})() 3 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test12.js: -------------------------------------------------------------------------------- 1 | a = {} 2 | a[$A$Num(b)] = function reachable(){} 3 | 4 | attacker = a[$A$NativeNot(n)] 5 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/AdsafeTests/test3.js: -------------------------------------------------------------------------------- 1 | Object.prototype.h__ = document; 2 | 3 | 4 | // document should NOT be reachable 5 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test2.js: -------------------------------------------------------------------------------- 1 | Object.prototype.toString = function reachable(){}; 2 | 3 | attacker = Object.prototype.toString 4 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/primTest1.js: -------------------------------------------------------------------------------- 1 | attacker = Array; 2 | 3 | // Comment out the isNative flag for the primNum entry of astNumberMap 4 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/provenanceTest1.js: -------------------------------------------------------------------------------- 1 | function foo(){return 10;} 2 | function bar(){return document;} 3 | 4 | attacker = [foo,bar] 5 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/Cajita/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tvcutsem/es-lab/HEAD/src/util/EncapsulationAnalysis/NewVersion/Tests/Cajita/a.out -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test10.js: -------------------------------------------------------------------------------- 1 | a = {} 2 | a[0] = function reachable(){} 3 | 4 | a[1] = function reachable(){} 5 | 6 | attacker = a[$A$NativeNot(1)] 7 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test4.js: -------------------------------------------------------------------------------- 1 | a = {} 2 | 3 | a[$A$Num(b)] = function reachable(){}; 4 | 5 | attacker = a[0] 6 | 7 | // precious should be reachable 8 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/provenanceTest2.js: -------------------------------------------------------------------------------- 1 | function foo(){return 10;} 2 | function bar(){return [document, function xyz(){}];} 3 | 4 | attacker = [foo,bar] 5 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test5.js: -------------------------------------------------------------------------------- 1 | var a = {} 2 | var b = {toString: function(){a.foo = this.foo}, foo:function reachable(){}} 3 | c[b]; 4 | 5 | attacker = a 6 | 7 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/globalVarTest4.js: -------------------------------------------------------------------------------- 1 | window[$A$Native(c)] = function reachable(){} 2 | window[$A$Num(d)] = function NOTreachable(){} 3 | 4 | attacker = toString 5 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/throwTest1.js: -------------------------------------------------------------------------------- 1 | function f(g){ 2 | try{ 3 | g(); 4 | } 5 | catch(x){ 6 | x(function reachable(){}); 7 | } 8 | } 9 | 10 | attacker = f; 11 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test1.js: -------------------------------------------------------------------------------- 1 | a = {}; 2 | 3 | a['1'] = function NOTReachable(){}; 4 | 5 | a['getElementById'] = function reachable(){}; 6 | 7 | attacker = a[$A$NumNot(b)]; 8 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test8.js: -------------------------------------------------------------------------------- 1 | a = {} // This is an important line 2 | 3 | a[0] = function reachable(){} 4 | 5 | a[1] = function reachable(){} 6 | 7 | attacker = a[$A$Num(z)] 8 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/protoTest1.js: -------------------------------------------------------------------------------- 1 | var o = { ___nodes___: function reachable(){}}; 2 | 3 | function f(x){ 4 | 5 | x.g(x.___nodes___); 6 | 7 | } 8 | 9 | attacker = [f,o] 10 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/arrLengthTest1.js: -------------------------------------------------------------------------------- 1 | var o1 = {}; 2 | var o2 = {toString: function(){o1.b = this.foo; return 0;}, foo: function reachable(){}} 3 | var arr = []; 4 | 5 | arr.length = o2; 6 | 7 | attacker = o1; 8 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test9.js: -------------------------------------------------------------------------------- 1 | a = {} // This is an important line 2 | 3 | a[0] = function NOTreachable(){} 4 | 5 | a[1] = function NOTreachable(){} 6 | 7 | attacker = [a[$A$NumNot(1)], function reachable(){}] 8 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/AdsafeTests/adsafeAnnTest2.js: -------------------------------------------------------------------------------- 1 | 2 | function Bunch(nodes) { 3 | this.___Nodes___ = nodes; 4 | } 5 | 6 | 7 | 8 | attacker = new Bunch(document); 9 | 10 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/test7.js: -------------------------------------------------------------------------------- 1 | a = {} // This is an important line 2 | 3 | a[0] = function NOTreachable(){} 4 | 5 | a[1] = function reachable(){} 6 | 7 | attacker = a[1] 8 | 9 | // precious should not be reachable 10 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/AdsafeTests/test18.js: -------------------------------------------------------------------------------- 1 | 2 | function Bunch(nodes) { 3 | this.___Nodes___ = nodes; 4 | } 5 | 6 | 7 | 8 | attacker = new Bunch(document); 9 | //document should NOT be reachable 10 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/table.js: -------------------------------------------------------------------------------- 1 | var trustedTable = [function NOTreachable(){}]; 2 | 3 | attacker = { 4 | push: function reachable1(x){trustedTable.push(x);}, 5 | store: function reachable2(i,x){trustedTable[$A$Num(i)] = x;} 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/runTests: -------------------------------------------------------------------------------- 1 | testsize=$1 2 | tests=`ls ./Tests/*.js` 3 | for testName in $tests 4 | do 5 | echo Running TEST $testName 6 | cat $testName 7 | echo '\n-------------' 8 | node v8analyzer.js $testName out -cloneNative >>dump 9 | cat out 10 | echo '\n\n******************************************' 11 | done 12 | 13 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/AdsafeTests/adsafeAnn2.js: -------------------------------------------------------------------------------- 1 | attacker = (function () { 2 | 3 | 4 | 5 | // Return the ADSAFE object. 6 | 7 | return [ 8 | function (array) { 9 | 10 | b = Array.prototype.concat(array.___nodes___); 11 | }, 12 | {___nodes___:[document]} 13 | ]; 14 | }()); 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/ses/strict-debug-bug.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Turn on "Start Debugging JavaScript", open the JavaScript 4 | console, refresh, and then type "2+3" in the JavaScript console. 5 | If it shows an Error with an closed triangle, open the triangle to 6 | see the error. 7 | 13 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/AdsafeTests/adsafeAnnTest2Result: -------------------------------------------------------------------------------- 1 | (NOTES: 2 | (1) We map all functions to the corresponding declaration sites. Multiple instances of the same declaration site are shown as the same function 3 | (2) Native prototype functions and attacker created functions are not shown 4 | ) 5 | 6 | Functions and DOM objects that the attacker can potentially hold are: 7 | 8 | Total number of functions = 0 -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/AdsafeTests/adsafeAnntes2Result: -------------------------------------------------------------------------------- 1 | (NOTES: 2 | (1) We map all functions to the corresponding declaration sites. Multiple instances of the same declaration site are shown as the same function 3 | (2) Native prototype functions and attacker created functions are not shown 4 | ) 5 | 6 | Functions and DOM objects that the attacker can potentially hold are: 7 | 8 | Total number of functions = 0 -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/runTestOld: -------------------------------------------------------------------------------- 1 | testFileName='./Tests/test' 2 | outFileName='testOutput' 3 | #echo $testFileName 4 | count=1 5 | testsize=`expr $1 + 1` 6 | while [ $count -lt $testsize ] 7 | do 8 | testName=$testFileName$count.js 9 | echo Running TEST $testName 10 | cat $testName 11 | echo '\n-------------' 12 | node v8analyzer.js $testName out -cloneNative >>dump 13 | cat out 14 | echo '\n\n******************************************' 15 | count=`expr $count + 1` 16 | done 17 | 18 | -------------------------------------------------------------------------------- /site/traits/prettify.css: -------------------------------------------------------------------------------- 1 | .str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun{color:#660}.pln{color:#000}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec{color:#606}pre.prettyprint{padding:2px;border:1px solid #888}@media print{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun{color:#440}.pln{color:#000}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}} 2 | pre { 3 | font-size: 1.3em; 4 | } 5 | pre.prettyprint.noborder { 6 | border:none; 7 | padding-left: 20px; 8 | } -------------------------------------------------------------------------------- /tests/harmony/gentests: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | verbose='false' 3 | 4 | while getopts "vh" OPTION 5 | do 6 | case $OPTION in 7 | v) 8 | verbose='true' 9 | ;; 10 | h) 11 | echo 'usage: '$0' [-v]' 12 | exit 0 13 | ;; 14 | *) 15 | # unrecognized args, quit 16 | exit 0 17 | ;; 18 | esac 19 | done 20 | # Reset $@ 21 | #shift `echo $OPTIND-1 | bc` 22 | 23 | echo '// this file was generated by '$0 $@ 24 | echo 'load("consolerunner.js");' 25 | for file in `find TestCases -name '*.js'` 26 | do 27 | echo 'load("'$file'");' 28 | done 29 | echo 'ES5Harness.startTesting('$verbose');' 30 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/CajitaTests/cajita.js: -------------------------------------------------------------------------------- 1 | 2 | attacker = (function(global) { 3 | 4 | 5 | 6 | 7 | function readPub(obj, name) { 8 | 9 | return obj.c(); 10 | 11 | return obj[name]; 12 | 13 | } 14 | 15 | 16 | 17 | 18 | function enforceStaticPath(result) { 19 | 20 | 21 | 22 | enforceStaticPath(readPub(result)); 23 | 24 | } 25 | 26 | 27 | 28 | enforceStaticPath({}) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Object.prototype.___nodes___ = function precious(){}; 37 | 38 | 39 | })(); 40 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/CajitaTests/cajita41.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | attacker = (function(global) { 4 | 5 | 6 | function hasOwnPropertyO(obj, name) { 7 | 8 | if ( obj[$A$AdsafeReject(name)] === obj) { return true; } 9 | } 10 | 11 | 12 | 13 | function handleGenericMethod(obj, name, func) { 14 | obj[$A$AdsafeReject(name)] = func 15 | } 16 | 17 | 18 | 19 | 20 | 21 | 22 | /// Object 23 | 24 | handleGenericMethod(Object.prototype, 'hasOwnProperty', 25 | function hasOwnPropertyHandler(name) { 26 | return hasOwnPropertyO(this, name); 27 | }); 28 | })(); 29 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/SealerUnsealer/suBroken.js: -------------------------------------------------------------------------------- 1 | function Brand() { 2 | var flag = false; 3 | var squirrel = null; 4 | 5 | return { 6 | seal: function(payload) { 7 | return function box() { 8 | squirrel = payload; 9 | flag = true; 10 | } 11 | box.toString = function() { 12 | return "(box)"; 13 | } 14 | }, 15 | unseal: function(box) { 16 | flag = false; 17 | squirrel = null; 18 | box(); 19 | if (!flag) { 20 | throw 'Invalid Box'; 21 | } 22 | return squirrel; 23 | } 24 | }; 25 | } 26 | 27 | 28 | 29 | var brand = Brand(); 30 | 31 | function precious(){} 32 | 33 | attacker = {go: function goFunction(){brand.unseal(brand.seal(precious))}, 34 | unseal: brand.unseal} 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/AdsafeTests/adsafeAnntes3Result: -------------------------------------------------------------------------------- 1 | (NOTES: 2 | (1) We map all functions to the corresponding declaration sites. Multiple instances of the same declaration site are shown as the same function 3 | (2) Native prototype functions and attacker created functions are not shown 4 | ) 5 | 6 | Functions and DOM objects that the attacker can potentially hold are: 7 | 8 | Line No: 238---(function (id,f){root=(document["getElementById"](id+" "));newroot=(make_root(root,id));dom=newroot[0];f(dom,adsafe_lib);adsafe_lib={}}) 9 | 10 | Line No: 216---(function (text){quest("",this["___nodes___"]);return {}}) 11 | 12 | Line No: 259---(function (name,f){if (!adsafe_id){return error()}adsafe_lib[($A$AdsafeRejectNot(name))]=(f(adsafe_lib))}) 13 | 14 | Total number of functions = 3 -------------------------------------------------------------------------------- /tests/harmony/README: -------------------------------------------------------------------------------- 1 | This ES-Harmony Test Suite is an adaptation of the ES5 Conformance Test Suite that can run in a stand-alone shell (i.e. doesn't require a browser). 2 | 3 | Writing tests 4 | ------------- 5 | Create *.js files adhering to the ES5 Conformance Test suite format in the TestCases subdirectory. See example.js for a skeleton unit test. 6 | Have a look at the bottom of the file consolerunner.js for a list of utility assertion functions. 7 | 8 | Running the tests 9 | ----------------- 10 | First, generate a file that loads all test code by invoking: 11 | gentests > tests.js 12 | 13 | To run the tests, simply load the generated file with your favorite javascript shell, e.g.: 14 | js tests.js 15 | 16 | The shell should support 'load(string)' and 'print(string)' globals. 17 | 18 | The gentests script accepts a single '-v' verbose option that will also print passing tests. -------------------------------------------------------------------------------- /doc/proxies/bm/Proxies vs No Proxies BM.csv: -------------------------------------------------------------------------------- 1 | Operation,TM - Proxies,TM + Proxies,Operation,Relative overhead 2 | delete,0.00042,0.00041,delete,0.97619047619048 3 | getPrototypeOf,0.00047,0.00046,getPrototypeOf,0.97872340425532 4 | construct,0.00061,0.0006,construct,0.98360655737705 5 | hasOwn,0.00081,0.00081,hasOwn,1 6 | get,0.00038,0.00038,get,1 7 | set,0.0004,0.0004,set,1 8 | enumerate,0.00158,0.00158,enumerate,1 9 | ===,0.00043,0.00043,===,1 10 | getOwnPropertyDescriptor,0.00148,0.0015,getOwnPropertyDescriptor,1.01351351351351 11 | invoke,0.00049,0.0005,invoke,1.02040816326531 12 | call,0.00047,0.00048,call,1.02127659574468 13 | enumerateOwn,0.0009,0.00092,enumerateOwn,1.02222222222222 14 | has,0.00041,0.00042,has,1.02439024390244 15 | typeof,0.00038,0.00039,typeof,1.02631578947368 16 | defineProperty,0.00101,0.00107,defineProperty,1.05940594059406 17 | instanceof,0.00049,0.00053,instanceof,1.08163265306122 -------------------------------------------------------------------------------- /doc/proxies-final/bm/Proxies vs No Proxies BM.csv: -------------------------------------------------------------------------------- 1 | Operation,TM - Proxies,TM + Proxies,Operation,Relative overhead 2 | delete,0.00042,0.00041,delete,0.97619047619048 3 | getPrototypeOf,0.00047,0.00046,getPrototypeOf,0.97872340425532 4 | construct,0.00061,0.0006,construct,0.98360655737705 5 | hasOwn,0.00081,0.00081,hasOwn,1 6 | get,0.00038,0.00038,get,1 7 | set,0.0004,0.0004,set,1 8 | enumerate,0.00158,0.00158,enumerate,1 9 | ===,0.00043,0.00043,===,1 10 | getOwnPropertyDescriptor,0.00148,0.0015,getOwnPropertyDescriptor,1.01351351351351 11 | invoke,0.00049,0.0005,invoke,1.02040816326531 12 | call,0.00047,0.00048,call,1.02127659574468 13 | enumerateOwn,0.0009,0.00092,enumerateOwn,1.02222222222222 14 | has,0.00041,0.00042,has,1.02439024390244 15 | typeof,0.00038,0.00039,typeof,1.02631578947368 16 | defineProperty,0.00101,0.00107,defineProperty,1.05940594059406 17 | instanceof,0.00049,0.00053,instanceof,1.08163265306122 -------------------------------------------------------------------------------- /src/ses/amdTest1.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Trivial test of simple AMD loader. 17 | * Tests simple named case. No dependencies. 18 | * @requires define 19 | */ 20 | 21 | define('amdTest1', [], function() { 22 | "use strict"; 23 | 24 | return 'this'; 25 | }); 26 | -------------------------------------------------------------------------------- /src/ses/amdTestDir/amdTest2.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Trivial test of simple AMD loader. 17 | * Nested named module. No dependencies. 18 | * @requires define 19 | */ 20 | 21 | define('amdTestDir/amdTest2', [], function() { 22 | "use strict"; 23 | 24 | return ' is a '; 25 | }); 26 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/SealerUnsealer/suFixed.js: -------------------------------------------------------------------------------- 1 | function Brand(){ 2 | var flag = false; 3 | var payload = null; 4 | 5 | return { 6 | seal: function (payloadToSeal){ 7 | function box(){ 8 | flag = true; 9 | payload = payloadToSeal; 10 | } 11 | box.toString = function(){return "(box)";} 12 | return box; 13 | }, 14 | unseal: function(box){ 15 | flag = false; 16 | payload = null; 17 | try{ 18 | box(); 19 | if (!flag) 20 | { throw 'Invalid Box'} 21 | else{ 22 | return payload; 23 | } 24 | }finally{ 25 | flag = false; 26 | payload = null; 27 | } 28 | } 29 | } 30 | }; 31 | 32 | var brand = Brand(); 33 | 34 | var box = brand.seal(function precious(){}); 35 | 36 | //attacker = [box,brand.seal] 37 | 38 | attacker = {go: function goFunction(){brand.unseal(brand.seal(precious))}, 39 | unseal: brand.unseal} 40 | -------------------------------------------------------------------------------- /site/traits/test.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | traits.js unit tests 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | 23 |

traits.js QUnit tests

24 |

25 |

26 |
    27 | 28 | 29 | -------------------------------------------------------------------------------- /src/ses/amdTest.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Trivial test of simple AMD loader. 17 | * Tests anon case. Tests importing other modules. 18 | * @requires define 19 | */ 20 | 21 | define(['amdTest1', 'amdTestDir/amdTest2', 'amdTest3'], 22 | function(amdTest1, amdTest2, amdTest3) { 23 | "use strict"; 24 | 25 | debugger; // See if we can step into amdTest3.js 26 | var text3 = amdTest3(); 27 | return amdTest1 + amdTest2 + text3; 28 | }); 29 | -------------------------------------------------------------------------------- /doc/proxies/bm/Proxies Benchmark.csv: -------------------------------------------------------------------------------- 1 | direct,proxy,Operation,Direct,Proxy,Operation,Relative performance,overhead 2 | 0.00039,0.00039,typeof,0.39,0.39,typeof,1,0 3 | 0.00043,0.00043,===,0.43,0.43,===,1,0 4 | 0.00046,0.00046,getPrototypeOf,0.46,0.46,getPrototypeOf,1,0 5 | 0.00051,0.00052,instanceof,0.51,0.52,instanceof,1.01960784313725,0.01 6 | 0.00148,0.00189,getOwnPD,1.48,1.89,getOwnPD,1.27702702702703,0.41 7 | 0.00047,0.00061,call,0.47,0.61,call,1.29787234042553,0.14 8 | 0.00091,0.00121,enumerateOwn,0.91,1.21,enumerateOwn,1.32967032967033,0.3 9 | 0.0005,0.00084,invoke,0.5,0.84,invoke,1.68,0.34 10 | 0.00042,0.00071,delete,0.42,0.71,delete,1.69047619047619,0.29 11 | 0.00106,0.00181,defineProperty,1.06,1.81,defineProperty,1.70754716981132,0.75 12 | 0.00041,0.00073,has,0.41,0.73,has,1.78048780487805,0.32 13 | 0.0006,0.00108,construct,0.6,1.08,construct,1.8,0.48 14 | 0.00081,0.00146,hasOwn,0.81,1.46,hasOwn,1.80246913580247,0.65 15 | 0.00041,0.00074,set,0.41,0.74,set,1.80487804878049,0.33 16 | 0.00039,0.00073,get,0.39,0.73,get,1.87179487179487,0.34 17 | 0.00158,0.00667,enumerate,1.58,4,enumerate,2.53164556962025,2.42 -------------------------------------------------------------------------------- /doc/proxies-final/bm/Proxies Benchmark.csv: -------------------------------------------------------------------------------- 1 | direct,proxy,Operation,Direct,Proxy,Operation,Relative performance,overhead 2 | 0.00039,0.00039,typeof,0.39,0.39,typeof,1,0 3 | 0.00043,0.00043,===,0.43,0.43,===,1,0 4 | 0.00046,0.00046,getPrototypeOf,0.46,0.46,getPrototypeOf,1,0 5 | 0.00051,0.00052,instanceof,0.51,0.52,instanceof,1.01960784313725,0.01 6 | 0.00148,0.00189,getOwnPD,1.48,1.89,getOwnPD,1.27702702702703,0.41 7 | 0.00047,0.00061,call,0.47,0.61,call,1.29787234042553,0.14 8 | 0.00091,0.00121,enumerateOwn,0.91,1.21,enumerateOwn,1.32967032967033,0.3 9 | 0.0005,0.00084,invoke,0.5,0.84,invoke,1.68,0.34 10 | 0.00042,0.00071,delete,0.42,0.71,delete,1.69047619047619,0.29 11 | 0.00106,0.00181,defineProperty,1.06,1.81,defineProperty,1.70754716981132,0.75 12 | 0.00041,0.00073,has,0.41,0.73,has,1.78048780487805,0.32 13 | 0.0006,0.00108,construct,0.6,1.08,construct,1.8,0.48 14 | 0.00081,0.00146,hasOwn,0.81,1.46,hasOwn,1.80246913580247,0.65 15 | 0.00041,0.00074,set,0.41,0.74,set,1.80487804878049,0.33 16 | 0.00039,0.00073,get,0.39,0.73,get,1.87179487179487,0.34 17 | 0.00158,0.00667,enumerate,1.58,4,enumerate,2.53164556962025,2.42 -------------------------------------------------------------------------------- /src/ses/ses-usage-eval.js: -------------------------------------------------------------------------------- 1 | // To start SES under nodejs 2 | // Adapted from https://gist.github.com/3669482 3 | 4 | // Running the following command in a directory with the SES sources 5 | // $ node ses-usage.js 6 | // Should print something like 7 | // Max Severity: Safe spec violation(1). 8 | // 414 Apparently fine 9 | // 24 Deleted 10 | // 1 Skipped 11 | // Max Severity: Safe spec violation(1). 12 | // initSES succeeded. 13 | // hi 14 | 15 | var unsafeEval = eval; 16 | var global = this; 17 | 18 | var FS = require("fs"); 19 | var src = ''; 20 | [ 21 | "logger.js", 22 | "repairES5.js", 23 | "debug.js", 24 | "StringMap.js", 25 | "whitelist.js", 26 | "atLeastFreeVarNames.js", 27 | "startSES.js", 28 | "ejectorsGuardsTrademarks.js", 29 | "hookupSESPlus.js", 30 | ].forEach(function (path) { 31 | console.log("Running: " + path); 32 | src += FS.readFileSync(path); 33 | }); 34 | 35 | unsafeEval(src); 36 | 37 | global.cajaVM.eval("console.log('hi');"); 38 | console.log(global); 39 | console.log(Object.getOwnPropertyNames(global).sort().join('\n')); 40 | -------------------------------------------------------------------------------- /doc/proxies/revocableRefManual.js: -------------------------------------------------------------------------------- 1 | function makeRevocableRef(target) { 2 | var enabled = true; 3 | return { 4 | caretaker: Proxy.create({ 5 | get: function(rcvr, name) { 6 | if (!enabled) { throw new Error("revoked"); } 7 | return target[name]; 8 | }, 9 | has: function(name) { 10 | if (!enabled) { throw new Error("revoked"); } 11 | return name in target; 12 | } 13 | // ... and so on for all other traps 14 | }, Object.getPrototypeOf(target)), 15 | revoker: { 16 | revoke: function() { enabled = false; } 17 | } 18 | }; 19 | }; 20 | 21 | function assert(b, reason) { 22 | if (!b) throw new Error('assertion failed: '+reason); 23 | } 24 | 25 | var o = { m: function() { return 1; }}; 26 | var ref = makeRevocableRef(o); 27 | var r = ref.caretaker; 28 | assert(o.m()===1, 'invoking o.m directly'); 29 | assert(r.m()===1, 'invoking o.m through revocable ref'); 30 | ref.revoker.revoke(); 31 | try { 32 | r.m(); 33 | assert(false, 'expected r.m to throw revoked exception'); 34 | } catch (e) { 35 | assert(e.message==='revoked', 'r.m throws revoked'); 36 | } 37 | print('ok'); -------------------------------------------------------------------------------- /doc/proxies-final/revocableRefManual.js: -------------------------------------------------------------------------------- 1 | function makeRevocableRef(target) { 2 | var enabled = true; 3 | return { 4 | caretaker: Proxy.create({ 5 | get: function(rcvr, name) { 6 | if (!enabled) { throw new Error("revoked"); } 7 | return target[name]; 8 | }, 9 | has: function(name) { 10 | if (!enabled) { throw new Error("revoked"); } 11 | return name in target; 12 | } 13 | // ... and so on for all other traps 14 | }, Object.getPrototypeOf(target)), 15 | revoker: { 16 | revoke: function() { enabled = false; } 17 | } 18 | }; 19 | }; 20 | 21 | function assert(b, reason) { 22 | if (!b) throw new Error('assertion failed: '+reason); 23 | } 24 | 25 | var o = { m: function() { return 1; }}; 26 | var ref = makeRevocableRef(o); 27 | var r = ref.caretaker; 28 | assert(o.m()===1, 'invoking o.m directly'); 29 | assert(r.m()===1, 'invoking o.m through revocable ref'); 30 | ref.revoker.revoke(); 31 | try { 32 | r.m(); 33 | assert(false, 'expected r.m to throw revoked exception'); 34 | } catch (e) { 35 | assert(e.message==='revoked', 'r.m throws revoked'); 36 | } 37 | print('ok'); -------------------------------------------------------------------------------- /tests/harmony/genhtmltests: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | verbose='false' 3 | 4 | while getopts "vh" OPTION 5 | do 6 | case $OPTION in 7 | v) 8 | verbose='true' 9 | ;; 10 | h) 11 | echo 'usage: '$0' [-v]' 12 | exit 0 13 | ;; 14 | *) 15 | # unrecognized args, quit 16 | exit 0 17 | ;; 18 | esac 19 | done 20 | # Reset $@ 21 | #shift `echo $OPTIND-1 | bc` 22 | 23 | cat < 25 | 26 | 27 | Proxies unit tests 28 | 29 | 30 | 38 | EOF 39 | 40 | echo '' 41 | for file in `find TestCases -name '*.js'` 42 | do 43 | echo '' 44 | done 45 | 46 | echo '' 47 | echo '' 48 | cat < 50 | 51 | 52 | EOF -------------------------------------------------------------------------------- /src/ses/amdTest3.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Trivial test of simple AMD loader. 17 | * Tests anon case. No dependencies. With Axel's CommonJS Adapter 18 | * boilerplate. See http://www.2ality.com/2011/11/module-gap.html 19 | * 20 | * @requires define, require 21 | * @overrides module 22 | */ 23 | 24 | ({ define: typeof define === "function" ? 25 | define : 26 | function(A,F) { module.exports = F.apply(null, A.map(require)); }}). 27 | define([], function() { 28 | "use strict"; 29 | 30 | return function() { 31 | return 'test'; 32 | }; 33 | }); 34 | -------------------------------------------------------------------------------- /src/ses/ses-usage.js: -------------------------------------------------------------------------------- 1 | // To start SES under nodejs 2 | // Adapted from https://gist.github.com/3669482 3 | 4 | // Running the following command in a directory with the SES sources 5 | // $ node ses-usage.js 6 | // Should print something like 7 | // Max Severity: Safe spec violation(1). 8 | // 414 Apparently fine 9 | // 24 Deleted 10 | // 1 Skipped 11 | // Max Severity: Safe spec violation(1). 12 | // initSES succeeded. 13 | // hi 14 | 15 | var FS = require("fs"); 16 | var VM = require("vm"); 17 | 18 | var context = VM.createContext({ 19 | console: console, 20 | hack: function (cajaVM) { 21 | console.log(cajaVM); 22 | var f = cajaVM.compileExpr("console.log('hi')"); 23 | f({console: console}); 24 | } 25 | }); 26 | 27 | [ 28 | "logger.js", 29 | "repairES5.js", 30 | "debug.js", 31 | "StringMap.js", 32 | "whitelist.js", 33 | "atLeastFreeVarNames.js", 34 | "startSES.js", 35 | "ejectorsGuardsTrademarks.js", 36 | "hookupSESPlus.js", 37 | ].forEach(function (path) { 38 | console.log("Running: " + path); 39 | VM.runInContext(FS.readFileSync(path), context, path); 40 | }); 41 | 42 | VM.runInContext("hack(cajaVM)", context); 43 | -------------------------------------------------------------------------------- /doc/esop13/remreset.sty: -------------------------------------------------------------------------------- 1 | 2 | % remreset package 3 | %%%%%%%%%%%%%%%%%% 4 | 5 | % Copyright 1997 David carlisle 6 | % This file may be distributed under the terms of the LPPL. 7 | % See 00readme.txt for details. 8 | 9 | % 1997/09/28 David Carlisle 10 | 11 | % LaTeX includes a command \@addtoreset that is used to declare that 12 | % a counter should be reset every time a second counter is incremented. 13 | 14 | % For example the book class has a line 15 | % \@addtoreset{footnote}{chapter} 16 | % So that the footnote counter is reset each chapter. 17 | 18 | % If you wish to bas a new class on book, but without this counter 19 | % being reset, then standard LaTeX gives no simple mechanism to do 20 | % this. 21 | 22 | % This package defines |\@removefromreset| which just undoes the effect 23 | % of \@addtorest. So for example a class file may be defined by 24 | 25 | % \LoadClass{book} 26 | % \@removefromreset{footnote}{chapter} 27 | 28 | 29 | \def\@removefromreset#1#2{{% 30 | \expandafter\let\csname c@#1\endcsname\@removefromreset 31 | \def\@elt##1{% 32 | \expandafter\ifx\csname c@##1\endcsname\@removefromreset 33 | \else 34 | \noexpand\@elt{##1}% 35 | \fi}% 36 | \expandafter\xdef\csname cl@#2\endcsname{% 37 | \csname cl@#2\endcsname}}} 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/ses/contract/makeMint.es7: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | 17 | 18 | 19 | 20 | var makeMint = () => { 21 | var m = new WeakMap(); 22 | var makePurse = () => mint(0); 23 | 24 | var mint = balance => { 25 | var purse = def({ 26 | getBalance: () => balance, 27 | makePurse: makePurse, 28 | deposit: (amount, srcP) => 29 | Q(srcP).then(src => { 30 | Nat(balance + amount); 31 | m.get(src)(Nat(amount)); 32 | balance += amount; 33 | }) 34 | }); 35 | var decr = amount => { balance = Nat(balance - amount); }; 36 | m.set(purse, decr); 37 | return purse; 38 | }; 39 | return mint; 40 | }; 41 | -------------------------------------------------------------------------------- /src/q/Queue-harmony.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | /** 17 | * An infinite queue where (promises for) values can be dequeued 18 | * before they are enqueued. 19 | * 20 | *

    Based on a similar example in Flat Concurrent Prolog, perhaps by 21 | * Ehud (Udi) Shapiro. 22 | * 23 | * @author Mark S. Miller 24 | */ 25 | function Queue() { 26 | var ends = Q.defer(); 27 | return Object.freeze({ 28 | enqueue: function(elem) { 29 | var next = Q.defer(); 30 | ends.resolve(Object.freeze({head: elem, tail: next.promise})); 31 | ends.resolve = next.resolve; 32 | }, 33 | dequeue: function() { 34 | var result = Q(ends.promise).head; 35 | ends.promise = Q(ends.promise).tail; 36 | return result; 37 | } 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/preciousDatalog.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * Generates initial datalog field names with the appropriate domain size. 17 | The domain size is computed using the value of the counter inside the encoder. 18 | * @Author 19 | Ankur Taly (ataly@stanford.edu) 20 | * @arguments 21 | - getEncoderCount : (_ -> nat) returns the current count of the encoder. 22 | * @provides genDatalogFieldNames 23 | * Assumes: 24 | */ 25 | this.genPreciousConstraints = function genDatalogPreciousConstraints(encodeVar, encodeField, encodeLoc,encodeCon) { 26 | 27 | var constraint = " Precious(l) :- Precious(n), HPtsTo(l," + encodeField('$A$AdsafeRejectNot') + ",n). \n"; 28 | return constraint; 29 | 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/q/Queue.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | /** 17 | * An infinite queue where (promises for) values can be dequeued 18 | * before they are enqueued. 19 | * 20 | *

    Based on a similar example in Flat Concurrent Prolog, perhaps by 21 | * Ehud (Udi) Shapiro. 22 | * 23 | * @author Mark S. Miller 24 | */ 25 | function Queue() { 26 | var ends = Q.defer(); 27 | return Object.freeze({ 28 | enqueue: function(elem) { 29 | var next = Q.defer(); 30 | ends.resolve(Object.freeze({head: elem, tail: next.promise})); 31 | ends.resolve = next.resolve; 32 | }, 33 | dequeue: function() { 34 | var result = Q.get(ends.promise, 'head'); 35 | ends.promise = Q.get(ends.promise, 'tail'); 36 | return result; 37 | } 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/preciousDatalogAdsafe.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * Generates initial datalog field names with the appropriate domain size. 17 | The domain size is computed using the value of the counter inside the encoder. 18 | * @Author 19 | Ankur Taly (ataly@stanford.edu) 20 | * @arguments 21 | - getEncoderCount : (_ -> nat) returns the current count of the encoder. 22 | * @provides genDatalogFieldNames 23 | * Assumes: 24 | */ 25 | this.genPreciousConstraints = function genDatalogPreciousConstraints(encodeVar, encodeField, encodeLoc,encodeCon) { 26 | 27 | var constraint = " Precious(l) :- Precious(n), HPtsTo(l," + encodeField('$A$AdsafeRejectNot') + ",n). \n"; 28 | return constraint; 29 | 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /run-parser-tests.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // @author tomvc 16 | 17 | load("load-ometa.js") 18 | load("src/parser/unicode.js") 19 | load("src/parser/es5parser.js") 20 | load("third_party/json2.js"); 21 | load("tests/parser/unit.js"); 22 | load("tests/parser/parsertests.js"); 23 | 24 | // instead of loading the entire Prototype library... 25 | Array.prototype.each = function(fun) { 26 | for (var i = 0; i < this.length; i++) { 27 | fun(this[i]); 28 | }; 29 | return undefined; 30 | }; 31 | 32 | // switch second argument to 'true' if you want to see passing tests as well as failing tests 33 | var lextest = makeUnitTest("Lexer", false); 34 | this.unit = lextest; 35 | this.lexerTestSuite(); 36 | 37 | var parsetest = makeUnitTest("Parser", false); 38 | this.unit = parsetest; 39 | this.parserTestSuite(); 40 | -------------------------------------------------------------------------------- /doc/esop13/readme.txt: -------------------------------------------------------------------------------- 1 | Dear LLNCS user, 2 | 3 | The files in this directory belong to the LaTeX2e package for 4 | Lecture Notes in Computer Science (LNCS) of Springer-Verlag. 5 | 6 | It consists of the following files: 7 | 8 | readme.txt this file 9 | 10 | history.txt the version history of the package 11 | 12 | llncs.cls the LaTeX2e document class 13 | 14 | llncs.dem the sample input file 15 | 16 | llncs.doc the documentation of the class (LaTeX source) 17 | llncsdoc.pdf the documentation of the class (PDF version) 18 | llncsdoc.sty the modification of the class for the documentation 19 | llncs.ind an external (faked) author index file 20 | subjidx.ind subject index demo from the Springer book package 21 | llncs.dvi the resultig DVI file (remember to use binary transfer!) 22 | 23 | sprmindx.sty supplementary style file for MakeIndex 24 | (usage: makeindex -s sprmindx.sty ) 25 | 26 | splncs.bst old BibTeX style for use with llncs.cls 27 | 28 | splncs_srt.bst ditto with aphabetic sorting 29 | 30 | splncs03.bst current LNCS BibTeX style with aphabetic sorting 31 | 32 | aliascnt.sty part of the Oberdiek bundle; allows more control over 33 | the counters associated to any numbered item 34 | remreset.sty by David Carlisle 35 | -------------------------------------------------------------------------------- /ProjectHome.md: -------------------------------------------------------------------------------- 1 | Ecmascript 5, proxies and traits are discussed in these [talks](http://code.google.com/p/es-lab/wiki/Talks). 2 | 3 | ### Script Compartments ### 4 | 5 | These abstractions compose well. For example, in an SES frame as initialized by initSES.js 6 | ``` 7 | var compartment1 = makeMembrane(cajaVM.eval); 8 | var eval1 = compartment1.wrapper; 9 | var gate1 = compartment1.gate; 10 | var badCode = //... obtain potentially malicious code from somewhere ... 11 | var result = eval1(badCode); 12 | //... use result ... 13 | gate1.revoke(); 14 | //... contents of compartment gone and collectible ... 15 | ``` 16 | 17 | A membrane around an SES `eval` creates a compartment in which one can run potentially malicious code, confident that the resulting potentially malicious objects can interact with the world outside this compartment _only_ as permitted by the objects you provide them. Once the compartment is revoked, not only is all their connectivity severed, it is severed in ways the garbage collector can recognize. Given a good enough collector, these hostile objects cannot even continue to occupy your memory. 18 | 19 | On browsers supporting SES and the [Uniform Messaging Policy](http://dev.w3.org/2006/waf/UMP/), we can [mashup](SafeMashups.md) code from multiple origins without the usual vulnerabilities. 20 | 21 | # News # 22 | 23 | [SES announcement on es-discuss](https://mail.mozilla.org/pipermail/es-discuss/2010-August/011684.html) -------------------------------------------------------------------------------- /src/ses/contract/makeMint.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | define('contract/makeMint', ['Q'], function(Q) { 16 | "use strict"; 17 | var def = cajaVM.def; 18 | var Nat = cajaVM.Nat; 19 | 20 | var makeMint = function() { 21 | var m = new WeakMap(); 22 | var makePurse = function() { return mint(0); }; 23 | 24 | var mint = function(balance) { 25 | var purse = def({ 26 | getBalance: function() { return balance; }, 27 | makePurse: makePurse, 28 | deposit: function(amount, srcP) { 29 | return Q(srcP).then(function(src) { 30 | Nat(balance + amount); 31 | m.get(src)(Nat(amount)); 32 | balance += amount; 33 | }); } 34 | }); 35 | var decr = function(amount) { balance = Nat(balance - amount); }; 36 | m.set(purse, decr); 37 | return purse; 38 | }; 39 | return mint; 40 | }; 41 | 42 | return makeMint; 43 | }); 44 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/Mint/mint.js: -------------------------------------------------------------------------------- 1 | function Brand(){ 2 | var flag = false; 3 | var payload = null; 4 | 5 | return { 6 | seal: function (payloadToSeal){ 7 | function box(){ 8 | flag = true; 9 | payload = payloadToSeal; 10 | } 11 | box.toString = function(){return "(box)";} 12 | return box; 13 | }, 14 | unseal: function(box){ 15 | flag = false; 16 | payload = null; 17 | try{ 18 | box(); 19 | if (!flag){ throw 'Invalid Box'} 20 | return payload; 21 | }finally{ 22 | flag = false; 23 | payload = null; 24 | } 25 | } 26 | } 27 | }; 28 | 29 | 30 | attacker = (function Mint(){ 31 | var brand = Brand(); 32 | return function Purse(balance){ 33 | // no enforceNat line. 34 | function decr(amount){ 35 | balance = balance - amount; 36 | } 37 | return { 38 | getBalance: function(){return balance;}, 39 | makePurse: function(){return Purse(0);}, 40 | getDecr: function(){return brand.seal(decr);}, 41 | deposit: function(amount,src){ 42 | var box = src.getDecr(); 43 | var decr = brand.unseal(box); 44 | var newBal = balance + amount; 45 | decr(amount); 46 | balance = newBal;} 47 | } 48 | } 49 | })(); 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/proxies/testDirectProxies.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | Test Direct Proxies 24 | 25 | 26 | 27 | 39 | 40 | 41 | 42 |

    43 | 44 | 45 | -------------------------------------------------------------------------------- /src/proxies/testFixedTrappingProxy.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | Test Fixable Proxies 24 | 25 | 26 | 27 | 39 | 40 | 41 | 42 | 43 |
    44 | 45 | 46 | -------------------------------------------------------------------------------- /src/ses/hookupSES.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Call {@code ses.startSES} to turn this frame into a 17 | * SES environment following object-capability rules. 18 | * 19 | *

    Assumes ES5 plus WeakMap. Compatible with ES5-strict or 20 | * anticipated ES6. 21 | * 22 | * @author Mark S. Miller 23 | * @requires this 24 | * @overrides ses, hookupSESModule 25 | */ 26 | 27 | (function hookupSESModule(global) { 28 | "use strict"; 29 | 30 | try { 31 | if (!ses.okToLoad()) { 32 | return; 33 | } 34 | 35 | ses.startSES(global, 36 | ses.whitelist, 37 | ses.limitSrcCharset, 38 | ses.atLeastFreeVarNames, 39 | function () { return {}; }); 40 | } catch (err) { 41 | ses.updateMaxSeverity(ses.severities.NOT_SUPPORTED); 42 | ses.logger.error('hookupSES failed with: ' + err, err); 43 | } finally { 44 | // Balanced by beginStartup in logger.js 45 | ses.logger.endStartup(); 46 | } 47 | })(this); 48 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/datalogFieldNames.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * Generates initial datalog field names with the appropriate domain size. 17 | The domain size is computed using the value of the counter inside the encoder. 18 | * @Author 19 | Ankur Taly (ataly@stanford.edu) 20 | * @arguments 21 | - getEncoderCount : (_ -> nat) returns the current count of the encoder. 22 | * @provides genDatalogFieldNames 23 | * Assumes: 24 | */ 25 | this.genDatalogFieldNames = function genDatalogFieldNames(getEncoderVarCount, getEncoderLocCount, getEncoderFieldCount) { 26 | 27 | var numVar = getEncoderVarCount() + 1; 28 | var numLoc = getEncoderLocCount() + 1; 29 | var numField = getEncoderFieldCount() + 1; 30 | 31 | var constraint = 32 | '.basedir "Results" \n' + 33 | "L " + numLoc + " name.map \n" + 34 | "F " + numField + " name.map \n" + 35 | "V " + numVar + " name.map \n" + 36 | "I 100 name.map \n" ; 37 | 38 | return constraint; 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/ses/hookupSESPlus.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Call {@code ses.startSES} to turn this frame into a 17 | * SES environment following object-capability rules. 18 | * 19 | *

    Assumes ES5 plus WeakMap. Compatible with ES5-strict or 20 | * anticipated ES6. 21 | * 22 | * @author Mark S. Miller 23 | * @requires this 24 | * @overrides ses, hookupSESPlusModule 25 | */ 26 | 27 | (function hookupSESPlusModule(global) { 28 | "use strict"; 29 | 30 | try { 31 | if (!ses.okToLoad()) { 32 | return; 33 | } 34 | 35 | ses.startSES(global, 36 | ses.whitelist, 37 | ses.limitSrcCharset, 38 | ses.atLeastFreeVarNames, 39 | ses.ejectorsGuardsTrademarks); 40 | } catch (err) { 41 | ses.updateMaxSeverity(ses.severities.NOT_SUPPORTED); 42 | ses.logger.error('hookupSESPlus failed with: ', err); 43 | } finally { 44 | // Balanced by beginStartup in logger.js 45 | ses.logger.endStartup(); 46 | } 47 | })(this); 48 | -------------------------------------------------------------------------------- /doc/esop13/llncsdoc.sty: -------------------------------------------------------------------------------- 1 | % This is LLNCSDOC.STY the modification of the 2 | % LLNCS class file for the documentation of 3 | % the class itself. 4 | % 5 | \def\AmS{{\protect\usefont{OMS}{cmsy}{m}{n}% 6 | A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}} 7 | \def\AmSTeX{{\protect\AmS-\protect\TeX}} 8 | % 9 | \def\ps@myheadings{\let\@mkboth\@gobbletwo 10 | \def\@oddhead{\hbox{}\hfil\small\rm\rightmark 11 | \qquad\thepage}% 12 | \def\@oddfoot{}\def\@evenhead{\small\rm\thepage\qquad 13 | \leftmark\hfil}% 14 | \def\@evenfoot{}\def\sectionmark##1{}\def\subsectionmark##1{}} 15 | \ps@myheadings 16 | % 17 | \setcounter{tocdepth}{2} 18 | % 19 | \renewcommand{\labelitemi}{--} 20 | \newenvironment{alpherate}% 21 | {\renewcommand{\labelenumi}{\alph{enumi})}\begin{enumerate}}% 22 | {\end{enumerate}\renewcommand{\labelenumi}{enumi}} 23 | % 24 | \def\bibauthoryear{\begingroup 25 | \def\thebibliography##1{\section*{References}% 26 | \small\list{}{\settowidth\labelwidth{}\leftmargin\parindent 27 | \itemindent=-\parindent 28 | \labelsep=\z@ 29 | \usecounter{enumi}}% 30 | \def\newblock{\hskip .11em plus .33em minus -.07em}% 31 | \sloppy 32 | \sfcode`\.=1000\relax}% 33 | \def\@cite##1{##1}% 34 | \def\@lbibitem[##1]##2{\item[]\if@filesw 35 | {\def\protect####1{\string ####1\space}\immediate 36 | \write\@auxout{\string\bibcite{##2}{##1}}}\fi\ignorespaces}% 37 | \begin{thebibliography}{} 38 | \bibitem[1982]{clar:eke3} Clarke, F., Ekeland, I.: Nonlinear 39 | oscillations and boundary-value problems for Hamiltonian systems. 40 | Arch. Rat. Mech. Anal. {\bf 78} (1982) 315--333 41 | \end{thebibliography} 42 | \endgroup} 43 | -------------------------------------------------------------------------------- /load-ometa.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Modified OMeta Startup script based on third_party/ometa/ometa-rhino.js 16 | // @author tomvc 17 | load("third_party/ometa/lib.js") 18 | load("third_party/ometa/ometa-base.js") 19 | load("third_party/ometa/parser.js") 20 | load("third_party/ometa/bs-js-compiler.js") 21 | load("third_party/ometa/bs-ometa-compiler.js") 22 | load("third_party/ometa/bs-ometa-optimizer.js") 23 | load("third_party/ometa/bs-ometa-js-compiler.js") 24 | 25 | alert = print; 26 | 27 | OMetaLib = { 28 | translateCode: function(s) { 29 | var translationError = function(m, i) { alert("Translation error - please tell Alex about this!"); throw fail }, 30 | tree = BSOMetaJSParser.matchAll(s, "topLevel", undefined, function(m, i) { throw fail.delegated({errorPos: i}) }) 31 | return BSOMetaJSTranslator.match(tree, "trans", undefined, translationError) 32 | }, 33 | 34 | ometa: function(s) { return eval(this.translateCode(s)) }, 35 | 36 | compile: function(inputFile) { 37 | print(this.translateCode(read(inputFile))); 38 | } 39 | } -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/preciousInverseDatalog.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * Generates initial datalog field names with the appropriate domain size. 17 | The domain size is computed using the value of the counter inside the encoder. 18 | * @Author 19 | Ankur Taly (ataly@stanford.edu) 20 | * @arguments 21 | - getEncoderCount : (_ -> nat) returns the current count of the encoder. 22 | * @provides genDatalogFieldNames 23 | * Assumes: 24 | */ 25 | this.genPreciousConstraints = function genDatalogFieldNames(encodeVar, encodeField, encodeLoc,encodeCon) { 26 | 27 | var constraint = " Precious(l) :- Precious(m), HPtsTo(l," + encodeField('$A$AdsafeRejectNot') + ",m). \n"; 28 | 29 | constraint = constraint + 'RPrecious(l:L,m:L) \n' + 30 | 31 | 'RPrecious(l,m) :- IPrecious(l), Precious(m), HPtsTo(l," + encodeField('$A$AdsafeRejectNot') + ",m). \n' + 32 | 33 | 'Precious(m) :- RPrecious(l,m) .\n' + 34 | 35 | 'HPtsTo(l," + encodeField('$A$AdsafeRejectNot') + ",m) :- RPrecious(l,m) .\n' 36 | 37 | return constraint; 38 | 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/datalogFieldNames.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * Generates initial datalog field names with the appropriate domain size. 17 | The domain size is computed using the value of the counter inside the encoder. 18 | * @Author 19 | Ankur Taly (ataly@stanford.edu) 20 | * @arguments 21 | - getEncoderCount : (_ -> nat) returns the current count of the encoder. 22 | * @provides genDatalogFieldNames 23 | * Assumes: 24 | */ 25 | this.genDatalogFieldNames = function genDatalogFieldNames(getEncoderVarCount, getEncoderLocCount, getEncoderFieldCount, getEncodeConCount) { 26 | 27 | var numVar = getEncoderVarCount() + 1; 28 | var numLoc = getEncoderLocCount() + 1; 29 | var numField = getEncoderFieldCount() + 1; 30 | // var numCon = getEncoderConCount() + 1; 31 | var constraint = 32 | '.basedir "Results" \n' + 33 | "L " + numLoc + " name.map \n" + 34 | "F " + numField + " name.map \n" + 35 | "V " + numVar + " name.map \n" + 36 | // "C " + numCon + " name.map \n" + 37 | "I 100 name.map \n";1 38 | 39 | return constraint; 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/ses/contract/escrowExchange.es7: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | 17 | 18 | var escrowExchange = (a, b) => { // a from Alice, b from Bob 19 | var decide; 20 | var decisionP = Q.promise(resolve => { decide = resolve; }); 21 | 22 | var transfer = (srcPurseP, dstPurseP, amount) => { 23 | var makeEscrowPurseP = Q.join(srcPurseP ! makePurse, 24 | dstPurseP ! makePurse); 25 | var escrowPurseP = makeEscrowPurseP ! (); 26 | 27 | Q(decisionP).then( // setup phase 2 28 | _ => { dstPurseP ! deposit(amount, escrowPurseP); }, 29 | _ => { srcPurseP ! deposit(amount, escrowPurseP); }); 30 | 31 | return escrowPurseP ! deposit(amount, srcPurseP); // phase 1 32 | }; 33 | 34 | var failOnly = cancellationP => Q(cancellationP).then( 35 | cancellation => { throw cancellation; }); 36 | 37 | decide(Q.race([Q.all([ 38 | transfer(a.moneySrcP, b.moneyDstP, b.moneyNeeded), 39 | transfer(b.stockSrcP, a.stockDstP, a.stockNeeded) 40 | ]), 41 | failOnly(a.cancellationP), 42 | failOnly(b.cancellationP)])); 43 | return decisionP; 44 | }; 45 | -------------------------------------------------------------------------------- /SecureableES5.md: -------------------------------------------------------------------------------- 1 | # What is "Secureable EcmaScript 5"? # 2 | 3 | Informally, it is an ES5 implementation in which [initSES.js](http://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/) succeeds, and in which that success results in an object-capability safe environment for untrusted code imported through the resulting `eval` or `Function`. 4 | 5 | Beyond being simply a conforming ES5 implementation, the additional constraints: 6 | * All properties on accessible primordial objects (primordial objects other than the global object) must be deleteable. The `initSES.js` script will delete all properties not on its whitelist, where its whitelist (at the time of this writing) includes exactly the global names and path names specified in ES5. 7 | * Of the objects that survive this step, i.e., those named by that whitelist and those created at runtime, any additional behaviors they may have beyond that specified in ES5 must not imply they provide authority exceeding what their specified behavior by itself would provide. 8 | * For example, the [global-state behavior](http://code.google.com/p/google-caja/issues/detail?id=528) of `RegExp.prototype.exec` on some browsers, while not violating the ES5 spec, if unconstrained, would cause such an ES5 system to not be classified as a _Secureable ES5 system_. For Secureable ES5, the issue in this case is solvable compatibly with existing practice. These de-facto static properties on the RegExp constructor should be deletable. If these are deleted and then the RegExp constructor is frozen, then RegExp matches should still succeed but without leaking any static mutable state. 9 | * **What else???** 10 | 11 | The result of running this success is a JavaScript environment supporting [draft SES (Secure EcmaScript)](SecureEcmaScript.md). -------------------------------------------------------------------------------- /src/traits/evolution-problem.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010, Vrije Universiteit Brussel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This example demonstrates how traits deal with the "evolution problem" 16 | // where previously composed traits are modified later, such that a 17 | // previously successful composition could become broken in a later 18 | // version of the code 19 | // 20 | // @author Tom Van Cutsem 21 | 22 | load('traits.js'); // provides Trait 23 | 24 | // original code: 25 | (function() { 26 | var T1 = Trait({ 27 | x: 1, 28 | y: 2 29 | }); 30 | 31 | var T2 = Trait({ 32 | z: 3 33 | }); 34 | 35 | var obj = Trait.create(Object.prototype, 36 | Trait.compose(T1,T2)); 37 | 38 | print([obj.x, obj.y, obj.z].join(' ')); // prints 1 2 3 39 | })(); 40 | 41 | // now someone comes along and adds an x property to T2, what happens? 42 | (function() { 43 | var T1 = Trait({ 44 | x: 1, 45 | y: 2 46 | }); 47 | 48 | var T2 = Trait({ 49 | z: 3, 50 | x: 4 51 | }); 52 | 53 | var obj = Trait.create(Object.prototype, 54 | Trait.compose(T1,T2)); 55 | // Error: remaining conflicting property: x 56 | 57 | print([obj.x, obj.y, obj.z].join(' ')); 58 | })(); -------------------------------------------------------------------------------- /tests/parser/unit.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // @author tomvc 16 | 17 | // minimal unit testing framework with same API as FireUnit 18 | 19 | // if verbose set to true, print both passed and failed tests 20 | // if verbose set to false, print only failed tests 21 | this.makeUnitTest = function(name, verbose) { 22 | var passed = 0; 23 | var total = 0; 24 | 25 | function test(bool, message, failmsg) { 26 | total++; 27 | var msg = ((bool) ? (passed++, "pass: ") : "fail: ") + message 28 | + (failmsg ? " ("+failmsg+")" : ""); 29 | if (verbose || !bool) { print(msg) }; 30 | }; 31 | 32 | return { 33 | ok : function(bool, message) { 34 | test(bool, message); 35 | }, 36 | compare: function(expected, actual, message) { 37 | test(expected === actual, message, "expected: "+expected+", got: "+actual); 38 | }, 39 | reCompare: function(regexp, actual, message) { 40 | test(typeof actual === "string" && actual.match(regexp)!==undefined, 41 | message, 42 | "string "+actual+" did not match "+regexp); 43 | }, 44 | testDone : function() { 45 | print("["+name+" done. Passed: "+passed+" Failed: "+(total-passed) 46 | +" Total: "+total+"]"); 47 | } 48 | }; 49 | }; -------------------------------------------------------------------------------- /tests/unit.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // @author tomvc 16 | 17 | // minimal unit testing framework with same API as FireUnit 18 | 19 | // if verbose set to true, print both passed and failed tests 20 | // if verbose set to false, print only failed tests 21 | this.makeUnitTest = function(name, verbose) { 22 | var passed = 0; 23 | var total = 0; 24 | 25 | function test(bool, message, failmsg) { 26 | total++; 27 | var msg = ((bool) ? (passed++, "pass: ") : "fail: ") + message 28 | + (failmsg ? " ("+failmsg+")" : ""); 29 | if (verbose || !bool) { print(msg) }; 30 | return bool; 31 | }; 32 | 33 | return { 34 | ok : function(bool, message) { 35 | return test(bool, message); 36 | }, 37 | compare: function(expected, actual, message) { 38 | return test(expected === actual, message, "expected: "+expected+", got: "+actual); 39 | }, 40 | reCompare: function(regexp, actual, message) { 41 | return test(typeof actual === "string" && actual.match(regexp)!==undefined, 42 | message, 43 | "string "+actual+" did not match "+regexp); 44 | }, 45 | testDone : function() { 46 | print("["+name+" done. Passed: "+passed+" Failed: "+(total-passed) 47 | +" Total: "+total+"]"); 48 | } 49 | }; 50 | }; -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/util.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | function proxyExpecting(expectedOp, expectedArgs, legalReturnvalueForOp) { 22 | var handler = {}; 23 | handler[expectedOp] = function() { 24 | var args = Array.prototype.slice.call(arguments); 25 | assert(expectedOp+' args', sameStructure(expectedArgs, args)); 26 | return legalReturnvalueForOp; 27 | }; 28 | return Proxy.create(handler); 29 | } -------------------------------------------------------------------------------- /src/ses/contract/escrowExchange.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | define('contract/escrowExchange', ['Q'], function(Q) { 16 | "use strict"; 17 | 18 | var escrowExchange = function(a, b) { // a from Alice, b from Bob 19 | var decide; 20 | var decisionP = Q.promise(function(resolve) { decide = resolve; }); 21 | 22 | var transfer = function(srcPurseP, dstPurseP, amount) { 23 | var makeEscrowPurseP = Q.join(Q(srcPurseP).get('makePurse'), 24 | Q(dstPurseP).get('makePurse')); 25 | var escrowPurseP = Q(makeEscrowPurseP).fcall(); 26 | 27 | Q(decisionP).then( // setup phase 2 28 | function(_) { Q(dstPurseP).send('deposit', amount, escrowPurseP); }, 29 | function(_) { Q(srcPurseP).send('deposit', amount, escrowPurseP); }); 30 | 31 | return Q(escrowPurseP).send('deposit', amount, srcPurseP); // phase 1 32 | }; 33 | 34 | var failOnly = function(cancellationP) { return Q(cancellationP).then( 35 | function(cancellation) { throw cancellation; }); }; 36 | 37 | decide(Q.race([Q.all([ 38 | transfer(a.moneySrcP, b.moneyDstP, b.moneyNeeded), 39 | transfer(b.stockSrcP, a.stockDstP, a.stockNeeded) 40 | ]), 41 | failOnly(a.cancellationP), 42 | failOnly(b.cancellationP)])); 43 | return decisionP; 44 | }; 45 | 46 | return escrowExchange; 47 | }); 48 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/fix.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-fix", 23 | path: "TestCases/trap-arguments/fix.js", 24 | 25 | description: 'fix trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | return true === Proxy.fix(proxyExpecting('fix',[],{})); 29 | }, 30 | 31 | precondition: function precond() { 32 | return typeof Proxy !== "undefined"; 33 | } 34 | }); 35 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/fix.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-fix", 23 | path: "TestCases/doublelifting/fix.js", 24 | 25 | description: 'double lifting of fix trap', 26 | 27 | test: function testcase() { 28 | return true === Proxy.fix(genericProxyExpecting('fix',[],{})); 29 | }, 30 | 31 | precondition: function precond() { 32 | return typeof Proxy !== "undefined"; 33 | } 34 | }); 35 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/has.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-has", 23 | path: "TestCases/doublelifting/has.js", 24 | 25 | description: 'double lifting of has trap', 26 | 27 | test: function testcase() { 28 | return true === 'foo' in genericProxyExpecting('has', ['foo'], true); 29 | }, 30 | 31 | precondition: function precond() { 32 | return typeof Proxy !== "undefined"; 33 | } 34 | }); 35 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/has.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-has", 23 | path: "TestCases/trap-arguments/has.js", 24 | 25 | description: 'has trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | return true === 'foo' in proxyExpecting('has', ['foo'], true); 29 | }, 30 | 31 | precondition: function precond() { 32 | return typeof Proxy !== "undefined"; 33 | } 34 | }); 35 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/defaultProto.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "defaultProto", 23 | path: "TestCases/defaultProto.js", 24 | 25 | description: 'test default prototype of object proxy', 26 | 27 | test: function testcase() { 28 | var proxy = Proxy.create({}); 29 | return (Object.getPrototypeOf(proxy) === null); 30 | }, 31 | 32 | precondition: function precond() { 33 | return typeof Proxy !== "undefined"; 34 | } 35 | }); 36 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/delete.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-delete", 23 | path: "TestCases/trap-arguments/delete.js", 24 | 25 | description: 'delete trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | return true === delete proxyExpecting('delete', ['foo'], true).foo; 29 | }, 30 | 31 | precondition: function precond() { 32 | return typeof Proxy !== "undefined"; 33 | } 34 | }); 35 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/delete.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-delete", 23 | path: "TestCases/doublelifting/delete.js", 24 | 25 | description: 'double lifting of delete trap', 26 | 27 | test: function testcase() { 28 | return true === delete genericProxyExpecting('delete', ['foo'], true).foo; 29 | }, 30 | 31 | precondition: function precond() { 32 | return typeof Proxy !== "undefined"; 33 | } 34 | }); 35 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/get.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-get", 23 | path: "TestCases/trap-throws/get.js", 24 | 25 | description: 'get trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('get', function(throwingProxy) { 29 | throwingProxy.foo; 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/fix.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-fix", 23 | path: "TestCases/trap-throws/fix.js", 24 | 25 | description: 'fix trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('fix', function(throwingProxy) { 29 | Proxy.fix(throwingProxy); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/has.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-has", 23 | path: "TestCases/trap-throws/has.js", 24 | 25 | description: 'has trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('has', function(throwingProxy) { 29 | 'foo' in throwingProxy; 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/set.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-set", 23 | path: "TestCases/trap-throws/set.js", 24 | 25 | description: 'set trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('set', function(throwingProxy) { 29 | throwingProxy.foo = 0; 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/hasOwn.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-hasOwn", 23 | path: "TestCases/trap-arguments/hasOwn.js", 24 | 25 | description: 'hasOwn trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | return true === ({}).hasOwnProperty.call( 29 | proxyExpecting('hasOwn', ['foo'], true), 30 | 'foo'); 31 | }, 32 | 33 | precondition: function precond() { 34 | return typeof Proxy !== "undefined"; 35 | } 36 | }); 37 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/hasOwn.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-hasOwn", 23 | path: "TestCases/doublelifting/hasOwn.js", 24 | 25 | description: 'double lifting of hasOwn trap', 26 | 27 | test: function testcase() { 28 | return true === ({}).hasOwnProperty.call( 29 | genericProxyExpecting('hasOwn', ['foo'], true), 30 | 'foo'); 31 | }, 32 | 33 | precondition: function precond() { 34 | return typeof Proxy !== "undefined"; 35 | } 36 | }); 37 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/delete.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-delete", 23 | path: "TestCases/trap-throws/delete.js", 24 | 25 | description: 'delete trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('delete', function(throwingProxy) { 29 | delete throwingProxy.foo; 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /src/util/sets.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview 3 | * Set operations that operate on sorted homogenous arrays of either 4 | * numbers or strings, sorted according to <. NaN cannot be a member 5 | * of a set. 6 | * 7 | * Sets are immutable on ES5 and later. Mutating sets on earlier 8 | * versions can lead to unpredictable behavior. 9 | * 10 | * @author mikesamuel@gmail.com 11 | * @provides set_union, set_singleton, set_difference, EMPTY_SET 12 | * @overrides Object 13 | */ 14 | 15 | // This code will work on ES < 5 but sets will not be immutable. 16 | if (!Object.freeze) { Object.freeze = function (x) { return x; }; } 17 | 18 | var EMPTY_SET = Object.freeze([]); 19 | 20 | function set_union(a, b) { 21 | var m = a.length, n = b.length; 22 | if (!m) { return b; } 23 | if (!n) { return a; } 24 | var i = 0, j = 0, k = 0; 25 | var o = []; 26 | while (i < m && j < n) { 27 | var v = a[i], w = b[j]; 28 | if (v <= w) { 29 | o[k++] = v; 30 | ++i; 31 | if (v === w) { ++j; } 32 | } else { 33 | o[k++] = w; 34 | ++j; 35 | } 36 | } 37 | if (i < m) { 38 | if (k === i) { return a; } 39 | do { 40 | o[k++] = a[i++]; 41 | } while (i < m); 42 | } else { 43 | if (k === j) { return b; } 44 | while (j < n) { 45 | o[k++] = b[j++]; 46 | } 47 | if (k === i) { return a; } 48 | } 49 | return Object.freeze(o); 50 | } 51 | 52 | function set_difference(a, b) { 53 | var m = a.length, n = b.length; 54 | if (!n || !m) { return a; } 55 | var i = 0, j = 0, k = 0; 56 | var o = []; 57 | while (i < m && j < n) { 58 | var v = a[i], w = b[j]; 59 | if (v <= w) { 60 | ++i; 61 | if (v === w) { 62 | ++j; 63 | } else { 64 | o[k++] = v; 65 | } 66 | } else { 67 | ++j; 68 | } 69 | } 70 | if (k === i) { return a; } 71 | if (i < m) { 72 | do { 73 | o[k++] = a[i++]; 74 | } while (i < m); 75 | } 76 | return k == 0 ? EMPTY_SET : Object.freeze(o); 77 | } 78 | 79 | /** A set containing a single item. */ 80 | function set_singleton(item) { return Object.freeze([item]); } 81 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/invoke.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-invoke", 23 | path: "TestCases/trap-throws/invoke.js", 24 | 25 | description: 'Test whether invoke trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('invoke', function(throwingProxy) { 29 | throwingProxy.foo(1,2,3); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/enumerateOwn.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-enumerateOwn", 23 | path: "TestCases/doublelifting/enumerateOwn.js", 24 | 25 | description: 'double lifting of enumerateOwn trap', 26 | 27 | test: function testcase() { 28 | var result = Object.keys(genericProxyExpecting('enumerateOwn',[],['a'])); 29 | return sameStructure(['a'], result); 30 | }, 31 | 32 | precondition: function precond() { 33 | return typeof Proxy !== "undefined"; 34 | } 35 | }); 36 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/enumerateOwn.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-enumerateOwn", 23 | path: "TestCases/trap-arguments/enumerateOwn.js", 24 | 25 | description: 'enumerateOwn trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var result = Object.keys(proxyExpecting('enumerateOwn',[],['a'])); 29 | return sameStructure(['a'], result); 30 | }, 31 | 32 | precondition: function precond() { 33 | return typeof Proxy !== "undefined"; 34 | } 35 | }); 36 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/enumerate.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-enumerate", 23 | path: "TestCases/trap-throws/enumerate.js", 24 | 25 | description: 'enumerate trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('enumerate', function(throwingProxy) { 29 | for (var p in throwingProxy) { } 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/hasOwn.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-hasOwn", 23 | path: "TestCases/trap-throws/hasOwn.js", 24 | 25 | description: 'hasOwn trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('hasOwn', function(throwingProxy) { 29 | ({}).hasOwnProperty.call(throwingProxy, 'foo'); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/set.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-set", 23 | path: "TestCases/doublelifting/set.js", 24 | 25 | description: 'double lifting of set trap', 26 | 27 | test: function testcase() { 28 | var setArgs = [null, 'foo', 0]; 29 | var proxy = genericProxyExpecting('set', setArgs, true); 30 | setArgs[0] = proxy; 31 | return 0 === (proxy.foo = 0); 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/get.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-get", 23 | path: "TestCases/trap-arguments/get.js", 24 | 25 | description: 'get trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var getArgs = [null, 'foo']; 29 | var proxy = proxyExpecting('get', getArgs, 42); 30 | getArgs[0] = proxy; 31 | 32 | return 42 === proxy.foo; 33 | }, 34 | 35 | precondition: function precond() { 36 | return typeof Proxy !== "undefined"; 37 | } 38 | }); 39 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/set.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-set", 23 | path: "TestCases/trap-arguments/set.js", 24 | 25 | description: 'set trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var setArgs = [null, 'foo', 0]; 29 | var proxy = proxyExpecting('set', setArgs, true); 30 | setArgs[0] = proxy; 31 | return 0 === (proxy.foo = 0); 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/get.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-get", 23 | path: "TestCases/doublelifting/get.js", 24 | 25 | description: 'double lifting of get trap', 26 | 27 | test: function testcase() { 28 | var getArgs = [null, 'foo']; 29 | var proxy = genericProxyExpecting('get', getArgs, 42); 30 | getArgs[0] = proxy; 31 | 32 | return 42 === proxy.foo; 33 | }, 34 | 35 | precondition: function precond() { 36 | return typeof Proxy !== "undefined"; 37 | } 38 | }); 39 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/enumerateOwn.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-enumerateOwn", 23 | path: "TestCases/trap-throws/enumerateOwn.js", 24 | 25 | description: 'enumerateOwn trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('enumerateOwn', function(throwingProxy) { 29 | Object.keys(throwingProxy); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/invoke.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Mozilla Foundation 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Mozilla Foundation nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "invoke", 23 | path: "TestCases/invoke.js", 24 | 25 | description: 'Test invoke trap', 26 | 27 | test: function testcase() { 28 | 29 | var proxy = Proxy.create({ invoke: function(obj,name,args) { return name + uneval(args); } }); 30 | assertEq("invoke on proxy", proxy.foo(1,2,3), "foo[1, 2, 3]"); 31 | 32 | return true; 33 | }, 34 | 35 | precondition: function precond() { 36 | return typeof Proxy !== "undefined"; 37 | } 38 | }); 39 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/enumerate.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-enumerate", 23 | path: "TestCases/trap-arguments/enumerate.js", 24 | 25 | description: 'enumerate trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var result = []; 29 | for (var p in proxyExpecting('enumerate', [], ['a'])) { result.push(p); } 30 | return sameStructure(['a'], result); 31 | }, 32 | 33 | precondition: function precond() { 34 | return typeof Proxy !== "undefined"; 35 | } 36 | }); 37 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #Copyright (C) 2009 Google Inc. 2 | # 3 | #Licensed under the Apache License, Version 2.0 (the "License"); 4 | #you may not use this file except in compliance with the License. 5 | #You may obtain a copy of the License at 6 | # 7 | #http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | #Unless required by applicable law or agreed to in writing, software 10 | #distributed under the License is distributed on an "AS IS" BASIS, 11 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | #See the License for the specific language governing permissions and 13 | #limitations under the License. 14 | 15 | es5parser_in = src/parser/es5parser.ojs 16 | es5parser_out = $(es5parser_in:%.ojs=%.js) 17 | # beware: these dependencies are deleted upon make clean 18 | es5parser_deps = third_party/json2_mini.js \ 19 | third_party/ometa/lib_mini.js \ 20 | third_party/ometa/ometa-base_mini.js \ 21 | src/parser/unicode_mini.js \ 22 | src/parser/es5parser_mini.js 23 | bundle = site/esparser/bundle.js 24 | 25 | # the javascript shell to use 26 | js = v8 #rhino 27 | 28 | all: parser esparser 29 | 30 | parser: $(es5parser_out) 31 | 32 | # compiles an OMeta grammar (.ojs) into an executable javascript (.js) parser 33 | %.js : %.ojs 34 | $(js) load-ometa.js -e "OMetaLib.compile('$<')" > $@ 35 | 36 | # runs the parser unit tests 37 | parsertests : $(es5parser_out) 38 | time $(js) run-parser-tests.js 39 | 40 | # builds the JS minifier 41 | jsmin : 42 | cc -o jsmin third_party/jsmin.c 43 | 44 | # minifies a Javascript source file 45 | %_mini.js: %.js jsmin 46 | @./jsmin < $< > $@ 47 | 48 | $(bundle): $(es5parser_deps) 49 | @mkdir -p "$$(dirname $@)" 50 | @(for file in $^; do echo // $$file; cat "$${file}"; echo; echo; done) > $@ 51 | 52 | # builds the parser playground website 53 | esparser: $(bundle) 54 | @for file in $^; do mv -f $${file} site/$@/`basename $${file}` ; done ; 55 | @cp -f site/parser.html site/$@/index.html 56 | @echo 'generated site/$@' 57 | 58 | # delete all generated files except site/esparser 59 | clean: 60 | rm -rf $(es5parser_out) jsmin $(es5parser_deps) 61 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/enumerate.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-enumerate", 23 | path: "TestCases/doublelifting/enumerate.js", 24 | 25 | description: 'double lifting of enumerate trap', 26 | 27 | test: function testcase() { 28 | var result = []; 29 | for (var p in genericProxyExpecting('enumerate', [], ['a'])) { result.push(p); } 30 | return sameStructure(['a'], result); 31 | }, 32 | 33 | precondition: function precond() { 34 | return typeof Proxy !== "undefined"; 35 | } 36 | }); 37 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/invoke.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-invoke", 23 | path: "TestCases/doublelifting/invoke.js", 24 | 25 | description: 'double lifting of invoke trap', 26 | 27 | test: function testcase() { 28 | var invokeargs = [null, 'foo', [1,2,3]]; 29 | var p = genericProxyExpecting('invoke',invokeargs, 42); 30 | invokeargs[0] = p; 31 | 32 | return 42 === p.foo(1,2,3); 33 | }, 34 | 35 | precondition: function precond() { 36 | return typeof Proxy !== "undefined"; 37 | } 38 | }); 39 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/defineProperty.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-defineProperty", 23 | path: "TestCases/trap-throws/defineProperty.js", 24 | 25 | description: 'defineProperty trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('defineProperty', function(throwingProxy) { 29 | Object.defineProperty(throwingProxy, 'foo', { }); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/getOwnPropertyNames.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-getOwnPropertyNames", 23 | path: "TestCases/trap-arguments/getOwnPropertyNames.js", 24 | 25 | description: 'getOwnPropertyNames trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var result = Object.getOwnPropertyNames( 29 | proxyExpecting('getOwnPropertyNames',[],['a'])); 30 | return sameStructure(['a'], result); 31 | }, 32 | 33 | precondition: function precond() { 34 | return typeof Proxy !== "undefined"; 35 | } 36 | }); 37 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/getOwnPropertyNames.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-getOwnPropertyNames", 23 | path: "TestCases/doublelifting/getOwnPropertyNames.js", 24 | 25 | description: 'double lifting of getOwnPropertyNames trap', 26 | 27 | test: function testcase() { 28 | var result = Object.getOwnPropertyNames( 29 | genericProxyExpecting('getOwnPropertyNames',[],['a'])); 30 | return sameStructure(['a'], result); 31 | }, 32 | 33 | precondition: function precond() { 34 | return typeof Proxy !== "undefined"; 35 | } 36 | }); 37 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/getOwnPropertyNames.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-getOwnPropertyNames", 23 | path: "TestCases/trap-throws/getOwnPropertyNames.js", 24 | 25 | description: 'getOwnPropertyNames trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('getOwnPropertyNames', function(throwingProxy) { 29 | Object.getOwnPropertyNames(throwingProxy); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/util.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | // assert whether the trap corresponding to trapName 22 | // passes exceptions thrown within the handler unmodified to the caller 23 | // 'operation' is expected to be a function(proxy) { /*trigger trapName trap*/ } 24 | function assertProxyThrows(trapName, operation) { 25 | function Exc() {}; // dummy exception type 26 | 27 | var handler = {}; 28 | handler[trapName] = function() { 29 | throw new Exc(); 30 | }; 31 | var proxy = Proxy.create(handler); 32 | assertThrows(trapName + ' throws', Exc, function() { return operation(proxy); }); 33 | } -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/defineProperty.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-defineProperty", 23 | path: "TestCases/doublelifting/defineProperty.js", 24 | 25 | description: 'double lifting of defineProperty trap', 26 | 27 | test: function testcase() { 28 | var pd = {}; 29 | var result = {}; 30 | return result === Object.defineProperty( 31 | genericProxyExpecting('defineProperty', ['foo',pd], result), 32 | 'foo', 33 | pd); 34 | }, 35 | 36 | precondition: function precond() { 37 | return typeof Proxy !== "undefined"; 38 | } 39 | }); 40 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/defineProperty.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-defineProperty", 23 | path: "TestCases/trap-arguments/defineProperty.js", 24 | 25 | description: 'defineProperty trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var pd = {}; 29 | var result = {}; 30 | return result === Object.defineProperty( 31 | proxyExpecting('defineProperty', ['foo',pd], result), 32 | 'foo', 33 | pd); 34 | }, 35 | 36 | precondition: function precond() { 37 | return typeof Proxy !== "undefined"; 38 | } 39 | }); 40 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/getOwnPropertyDescriptor.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-getOwnPropertyDescriptor", 23 | path: "TestCases/trap-arguments/getOwnPropertyDescriptor.js", 24 | 25 | description: 'getOwnPropertyDescriptor trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var pd = {}; 29 | return pd === Object.getOwnPropertyDescriptor( 30 | proxyExpecting('getOwnPropertyDescriptor', ['a'], pd), 31 | 'a'); 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/getOwnPropertyDescriptor.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-getOwnPropertyDescriptor", 23 | path: "TestCases/doublelifting/getOwnPropertyDescriptor.js", 24 | 25 | description: 'double lifting of getOwnPropertyDescriptor trap', 26 | 27 | test: function testcase() { 28 | var pd = {}; 29 | return pd === Object.getOwnPropertyDescriptor( 30 | genericProxyExpecting('getOwnPropertyDescriptor', ['a'], pd), 31 | 'a'); 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/getPropertyDescriptor.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "doublelifting-getProperty", 23 | path: "TestCases/doublelifting/getPropertyDescriptor.js", 24 | 25 | description: 'double lifting of getPropertyDescriptor trap', 26 | 27 | test: function testcase() { 28 | var pd = {}; 29 | return pd === Object.getPropertyDescriptor( 30 | genericProxyExpecting('getPropertyDescriptor', ['a'], pd), 31 | 'a'); 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined" && !!Object.getPropertyDescriptor; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/getPropertyDescriptor.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-getProperty", 23 | path: "TestCases/trap-arguments/getPropertyDescriptor.js", 24 | 25 | description: 'getPropertyDescriptor trap called with correct arguments', 26 | 27 | test: function testcase() { 28 | var pd = {}; 29 | return pd === Object.getPropertyDescriptor( 30 | proxyExpecting('getPropertyDescriptor', ['a'], pd), 31 | 'a'); 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined" && !!Object.getPropertyDescriptor; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/getOwnPropertyDescriptor.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-getOwnPropertyDescriptor", 23 | path: "TestCases/trap-throws/getOwnPropertyDescriptor.js", 24 | 25 | description: 'getOwnPropertyDescriptor trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('getOwnPropertyDescriptor', function(throwingProxy) { 29 | Object.getOwnPropertyDescriptor(throwingProxy, 'foo'); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined"; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-throws/getPropertyDescriptor.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "throws-getProperty", 23 | path: "TestCases/trap-throws/getPropertyDescriptor.js", 24 | 25 | description: 'getPropertyDescriptor trap passes exceptions through', 26 | 27 | test: function testcase() { 28 | assertProxyThrows('getPropertyDescriptor', function(throwingProxy) { 29 | Object.getPropertyDescriptor(throwingProxy); 30 | }); 31 | return true; 32 | }, 33 | 34 | precondition: function precond() { 35 | return typeof Proxy !== "undefined" && !!Object.getPropertyDescriptor; 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /tests/harmony/license.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | License 8 | 9 |

    ECMAScript-Harmony Conformance Suite License

    10 | Unless otherwise specified, the individual files of this project are licensed by their owners under terms of the New BSD licenses: 11 |

    New BSD License

    12 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    13 |
    • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    14 | 15 |
    • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    16 | 17 |
    • Neither the name of <<copyright owner>> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


    19 | 20 | 21 | 22 |
    23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/trap-arguments/invoke.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "args-invoke", 23 | path: "TestCases/trap-arguments/invoke.js", 24 | 25 | description: 'Test whether invoke is called with correct arguments', 26 | 27 | test: function testcase() { 28 | var invokeargs = [null, 'foo', [1,2,3]]; 29 | var p = proxyExpecting('invoke',invokeargs, 42); 30 | invokeargs[0] = p; 31 | 32 | // FIXME: test fails because invokeargs[0] !== p in the 'invoke' trap 33 | 34 | return 42 === p.foo(1,2,3); 35 | }, 36 | 37 | precondition: function precond() { 38 | return typeof Proxy !== "undefined"; 39 | } 40 | }); 41 | -------------------------------------------------------------------------------- /tests/harmony/example.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "id", //put a unique test id here 23 | path: "TestCases/example.js", //the directory path of this test starting at TestCases 24 | 25 | description: 'Test description', 26 | 27 | test: function testcase() { 28 | //Add test code here, return true if test passes 29 | return true; 30 | }, 31 | 32 | precondition: function precond() { 33 | //Add code to test any preconditions that must be establish in order to run this test. 34 | //Return true if it is ok to run the test. 35 | //This property may be completely omitted in which case the test will always be run. 36 | return true; 37 | } 38 | }); 39 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/denyfix.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | // When handler.fix() returns undefined, the corresponding call to 22 | // Object.freeze, Object.seal, or Object.preventExtensions will throw a TypeError. 23 | // Source: http://wiki.ecmascript.org/doku.php?id=harmony:proxies (rev 2/25/10) 24 | ES5Harness.registerTest( { 25 | id: "denyFix", 26 | path: "TestCases/denyFix.js", 27 | 28 | description: 'test whether a proxy can deny being fixed', 29 | 30 | test: function testcase() { 31 | var proxy = Proxy.create({ 32 | fix: function() { return undefined; } // deny fix by returning undefined 33 | }); 34 | return false === Proxy.fix(proxy); 35 | }, 36 | 37 | precondition: function precond() { 38 | return typeof Proxy !== "undefined"; 39 | } 40 | }); 41 | -------------------------------------------------------------------------------- /src/ses/StringMap.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Implements StringMap - a map api for strings. 17 | * 18 | * @author Mark S. Miller 19 | * @author Jasvir Nagra 20 | * @requires ses 21 | * @overrides StringMap 22 | */ 23 | 24 | var StringMap; 25 | 26 | (function() { 27 | 'use strict'; 28 | 29 | var create = Object.create; 30 | var freeze = Object.freeze; 31 | function constFunc(func) { 32 | func.prototype = null; 33 | return freeze(func); 34 | } 35 | 36 | function assertString(x) { 37 | if ('string' !== typeof(x)) { 38 | throw new TypeError('Not a string: ' + x); 39 | } 40 | return x; 41 | } 42 | 43 | var createNull; 44 | 45 | if (typeof ses === 'undefined' || 46 | !ses.ok() || 47 | ses.es5ProblemReports.FREEZING_BREAKS_PROTOTYPES.beforeFailure) { 48 | 49 | // Object.create(null) may be broken; fall back to ES3-style implementation 50 | // (safe because we suffix keys anyway). 51 | createNull = function() { return {}; }; 52 | } else { 53 | createNull = function() { return Object.create(null); }; 54 | } 55 | 56 | StringMap = function StringMap() { 57 | 58 | var objAsMap = createNull(); 59 | 60 | return freeze({ 61 | get: constFunc(function(key) { 62 | return objAsMap[assertString(key) + '$']; 63 | }), 64 | set: constFunc(function(key, value) { 65 | objAsMap[assertString(key) + '$'] = value; 66 | }), 67 | has: constFunc(function(key) { 68 | return (assertString(key) + '$') in objAsMap; 69 | }), 70 | 'delete': constFunc(function(key) { 71 | return delete objAsMap[assertString(key) + '$']; 72 | }) 73 | }); 74 | }; 75 | 76 | })(); 77 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/fixidentity.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "fixidentity", 23 | path: "TestCases/fixidentity.js", 24 | 25 | description: 'fixing proxies does not change their identity', 26 | 27 | test: function testcase() { 28 | 29 | var objProxy = Proxy.create({fix: function() { return {}; }}); 30 | assert('fixed object proxy has same identity', objProxy === Object.freeze(objProxy)); 31 | 32 | var funProxy = Proxy.createFunction({fix: function() { return {}; } }, function(){}); 33 | assert('fixed function proxy has same identity', funProxy === Object.freeze(funProxy)); 34 | 35 | return true; 36 | }, 37 | 38 | precondition: function precond() { 39 | return typeof Proxy !== "undefined" && !!Object.freeze; 40 | } 41 | }); 42 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/PhuPhung/enfPolicyWorks.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 3 | var enforcePolicy = function(pointcut, Policy) { 4 | var source = (typeof (pointcut.target.__proto__) != 'undefined') ? pointcut.target.__proto__ : pointcut.target; 5 | 6 | var method = pointcut.method 7 | var original = source1[method]; 8 | original.apply = Function.prototype.apply; 9 | Policy.apply = Function.prototype.apply; 10 | var aspect = function() { 11 | var invocation = { object: this, args: arguments }; 12 | var args = arguments; 13 | return Policy.apply(invocation.object, 14 | [{ arguments: invocation.args, 15 | method: method, 16 | proceed: function(){ return original.apply(invocation.object, invocation.args);} 17 | } 18 | 19 | ]); 20 | } 21 | source[$A$AdsafeRejectNot(method)] = aspect; 22 | return aspect; 23 | }; 24 | 25 | function policyLog(){}; 26 | 27 | 28 | 29 | var policylog = function(s) { 30 | if (_debug) { 31 | document.writeln(s+"
    "); 32 | } 33 | }; 34 | 35 | 36 | 37 | var HTMLBodyElement = {} 38 | HTMLBodyElement.appendChild = function precious1(){}; 39 | attacker = enforcePolicy({target : HTMLBodyElement , method: 'appendChild'}, 40 | function(invocation){ 41 | document.writeln('
    document.body.appendChild is wrapped
    '); 42 | var node = invocation.arguments[0]; 43 | 44 | newnode = invocation.proceed(); 45 | //newnode.src ='http://chalmers.se'; 46 | 47 | enforceWindow(newnode.contentWindow); 48 | return newnode; 49 | } 50 | ); 51 | 52 | document = {}; 53 | document.createElement = function precious2(){} 54 | attacker = enforcePolicy({target : document , method: 'createElement' }, 55 | function(invocation){ 56 | var tagName = invocation.arguments[0]; 57 | if(tagName=="iframe"){ 58 | policylog("creating a dynamic iframe is wrapped"); 59 | } 60 | ifrm = invocation.proceed(); 61 | ifrmWindow = ifrm.contentWindow; 62 | policylog("ifrmWindow ="+ifrmWindow); 63 | 64 | return ifrm; 65 | } 66 | ); 67 | 68 | 69 | 70 | })() 71 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/invokeDelegator.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "invokeDelegator", 23 | path: "TestCases/invokeDelegator.js", 24 | 25 | description: 'Test invoke on object that delegates to a proxy', 26 | 27 | test: function testcase() { 28 | 29 | var delegator; 30 | var proxy = Proxy.create({ 31 | get: function(receiver, name) { 32 | assertEq('get trap called for delegator', delegator, receiver); 33 | return function(argarray) { 34 | return 42; 35 | } 36 | }, 37 | invoke: function(receiver, name, argarray) { return 42; } 38 | }); 39 | 40 | delegator = Object.create(proxy); 41 | return (delegator.foo() === 42); 42 | }, 43 | 44 | precondition: function precond() { 45 | return typeof Proxy !== "undefined"; 46 | } 47 | }); 48 | -------------------------------------------------------------------------------- /tests/harmony/TestCases/doublelifting/util.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Google Inc. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Google Inc. nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | // helper function to test double lifting (using proxies as handlers) 22 | function genericProxyExpecting(expectedOp, expectedArgs, legalReturnvalueForOp) { 23 | // note: handlerProxy is both a handler for other proxies and a proxy itself 24 | var handlerProxy = Proxy.create({ 25 | get: function(rcvr, name) { 26 | assertEq(expectedOp, expectedOp, name); 27 | return function() { 28 | var args = Array.prototype.slice.call(arguments); 29 | assert(expectedOp+' args', sameStructure(expectedArgs, args)); 30 | return legalReturnvalueForOp; 31 | }; 32 | }, 33 | invoke: function(rcvr, name, args) { 34 | assertEq(expectedOp, expectedOp, name); 35 | assert(expectedOp+' args', sameStructure(expectedArgs, args)); 36 | return legalReturnvalueForOp; 37 | } 38 | }); 39 | 40 | return Proxy.create(handlerProxy); 41 | } -------------------------------------------------------------------------------- /tests/harmony/TestCases/constructor.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Mozilla Foundation. 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Mozilla Foundation nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "constructor", 23 | path: "TestCases/constructor.js", 24 | 25 | description: 'Test Function Proxies as constructors', 26 | 27 | test: function testcase() { 28 | 29 | var proxy = Proxy.createFunction({ 30 | get: function(obj, name) { return Function.prototype[name]; }, 31 | fix: function() { return ({}); } 32 | }, 33 | function() { var x = {}; x.origin = "call"; return x; }, 34 | function() { var x = {}; x.origin = "new"; return x; }) 35 | 36 | assert("call function proxy", proxy().origin == "call"); 37 | assert("new function proxy", (new proxy()).origin == "new"); 38 | assert("fix(Proxy)", Proxy.fix(proxy), true); 39 | assert("call fixed function proxy", proxy().origin == "call"); 40 | assert("new fixed function proxy", (new proxy()).origin == "new"); 41 | 42 | return true; 43 | }, 44 | 45 | precondition: function precond() { 46 | return typeof Proxy !== "undefined"; 47 | } 48 | }); 49 | -------------------------------------------------------------------------------- /tests/parser/parsertests.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 41 | ES5 Interpreter Parser Tests 42 | 43 |

    Instructions

    44 | This file runs the unit tests for the 45 | ES5 parser. 46 | It is meant to be run with the FireUnit extension to Firebug in Firefox. 47 | The unit tests assume that the OMeta grammar has been generated and is 48 | available in compiled form in the file 49 | es5parser.js. 50 |

    This page also serves as a convenient playground in combination with 51 | the FireBug command-line. The parsed can be invoked using parse(string,rule), the lexer using lex(string,rule)

    52 |

    To spot syntax errors in the OMeta grammar itself, 53 | it may be more convenient to debug in the 54 | OMeta workspace, where 55 | parse errors in the grammar itself are highlighted. Note that the workspace 56 | evaluates OMeta/JS code, not actual Javascript code. The unit tests for 57 | the parser are written in Javascript, not OMeta/JS. 58 | 59 | -------------------------------------------------------------------------------- /SecureEcmaScript.md: -------------------------------------------------------------------------------- 1 | # How does draft SES (Secure EcmaScript) differ from ES5? # 2 | 3 | In a frame of a [secureable ES5](SecureableES5.md) in which [initSES.js](http://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/) has been run, either prior to other scripts or in cooperation with other scripts, the resulting "language" as seen by that frame's new `eval` and `Function` bindings differs from full ES5 in the following ways: 4 | 1. All properties of accessible primordials not defined by the ES5 spec are absent, even if the browser originally provided them. 5 | 1. All accessible primordials (all primordials other than the global object) are frozen. 6 | 1. The ES5-defined properties of the global object are frozen, though the global object is not frozen as a whole and its other properties are not perturbed. The global variables defined by the ES5 spec are thus effectively `const`. 7 | 1. All calls to `eval` are calls to the SES _indirect eval function_. SES does not have a _direct eval operator_. 8 | 1. All code is only in the strict subset of ES5, whether it so declares or not. 9 | 1. The top level binding of `this` in an evaled Program is not the global object, but rather a frozen root object containing just the globals defined in the ES5 spec. 10 | 1. Only the global variables defined by the ES5 spec are addressable as free variables. 11 | 1. Any top level `var` or `function` declarations in an evaled Program are visible throughout that one Program, but not to other Programs nor to the global object. 12 | 13 | By analogy with Operating systems, let's call code imported through `eval` or `Function` _user code_, and code run directly in the frame, not through `eval` or `Function`, _privileged code_. The first four restrictions above apply to privileged code in that frame as well. However, since privileged code is able to address the real global object and its host-defined properties, it still has access to the authority the browser provides to JavaScript executing in that frame. It is therefore in a position to subdivide this authority, and hand out the resulting attenuated authority to imported user code, on a least authority basis, by providing objects (such as DOM wrappers) whose behavior represents this attenuated authority. 14 | 15 | As driven by the realization that it was possible to achieve the above restrictions on upcoming ES5 implementations (assuming they are [secureable](SecureableES5.md)), and with the goal of defining an SES that is minimally different from ES5, these seem like a good candidate list for the defining differences between SES and ES5. However, this currently has only the status of a strawman to be proposed to the EcmaScript committee. -------------------------------------------------------------------------------- /tests/harmony/TestCases/functionproxies.js: -------------------------------------------------------------------------------- 1 | /// Copyright (c) 2010 Mozilla Foundation 2 | /// 3 | /// Redistribution and use in source and binary forms, with or without modification, are permitted provided 4 | /// that the following conditions are met: 5 | /// * Redistributions of source code must retain the above copyright notice, this list of conditions and 6 | /// the following disclaimer. 7 | /// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 8 | /// the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | /// * Neither the name of Mozilla Foundation nor the names of its contributors may be used to 10 | /// endorse or promote products derived from this software without specific prior written permission. 11 | /// 12 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 13 | /// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 | /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 15 | /// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 | /// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 18 | /// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 19 | /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | ES5Harness.registerTest( { 22 | id: "functionproxies", 23 | path: "TestCases/functionproxies.js", 24 | 25 | description: 'Function Proxies', 26 | 27 | test: function testcase() { 28 | 29 | var proxy = Proxy.createFunction({ 30 | get: function(obj,name) { return Function.prototype[name]; }, 31 | fix: function() { 32 | return ({}); 33 | } 34 | }, function() { return "call"; }); 35 | 36 | assertEq("invoke function proxy", proxy(), "call"); 37 | assertEq("typeof trapping function proxy", typeof proxy, "function"); 38 | assertEq("isTrapping(Proxy) before fix", Proxy.isTrapping(proxy), true); 39 | assertEq("fix(Proxy)", Proxy.fix(proxy), true); 40 | assertEq("isTrapping(Proxy) after fix", Proxy.isTrapping(proxy), false); 41 | assertEq("typeof fixed function proxy", typeof proxy, "function"); 42 | assertEq("invoke function proxy", proxy(), "call"); 43 | 44 | return true; 45 | }, 46 | 47 | precondition: function precond() { 48 | return typeof Proxy !== "undefined"; 49 | } 50 | }); 51 | -------------------------------------------------------------------------------- /src/ses/contractTest.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @fileoverview Test simple contract code 17 | * @requires define 18 | */ 19 | 20 | define('contractTest', [ 21 | 'Q', 22 | 'contract/makeContractHost', 23 | 'contract/makeMint', 24 | 'contract/escrowExchange', 25 | 'contract/makeAlice', 26 | 'contract/makeBob'], 27 | function(Q, 28 | makeContractHost, 29 | makeMint, 30 | escrowExchange, 31 | makeAlice, 32 | makeBob) { 33 | "use strict"; 34 | 35 | var contractHostP = Q(makeContractHost).fcall(); 36 | 37 | function trivContract(whiteP, blackP) { 38 | return 8; 39 | } 40 | var contractSrc = '' + trivContract; 41 | 42 | var tokensP = Q(contractHostP).send('setup', contractSrc); 43 | 44 | var whiteTokenP = Q(tokensP).get(0); 45 | Q(contractHostP).send('play', whiteTokenP, contractSrc, 0, {}); 46 | 47 | var blackTokenP = Q(tokensP).get(1); 48 | var eightP = Q(contractHostP).send('play', blackTokenP, contractSrc, 1, {}); 49 | // check that eightP fulfills with 8. 50 | // (At the time of this writing, did the right thing under debugger) 51 | 52 | 53 | 54 | 55 | var moneyMintP = Q(makeMint).fcall(); 56 | var aliceMoneyPurseP = Q(moneyMintP).fcall(1000); 57 | var bobMoneyPurseP = Q(moneyMintP).fcall(1001); 58 | 59 | var stockMintP = Q(makeMint).fcall(); 60 | var aliceStockPurseP = Q(stockMintP).fcall(2002); 61 | var bobStockPurseP = Q(stockMintP).fcall(2003); 62 | 63 | var aliceP = Q(makeAlice).fcall(aliceMoneyPurseP, aliceStockPurseP, 64 | contractHostP); 65 | var bobP = Q(makeBob).fcall(bobMoneyPurseP, bobStockPurseP, 66 | contractHostP); 67 | 68 | var ifItFitsP = Q(aliceP).send('payBobWell', bobP); 69 | // check that ifItFitsP fulfills correctly, and that 70 | // payBobBadly1 and payBobBadly2 reject correctly. 71 | // (At the time of this writing, did the right thing under debugger) 72 | 73 | 74 | return Q(bobP).send('tradeWell', aliceP); 75 | // return Q(aliceP).send('tradeWell', bobP); 76 | }); 77 | -------------------------------------------------------------------------------- /src/util/EncapsulationAnalysis/NewVersion/Tests/PhuPhung/enfPolicy.js: -------------------------------------------------------------------------------- 1 | 2 | var enforcePolicy = function(pointcut, Policy) { 3 | //var source = (typeof (pointcut.target.prototype) != 'undefined') ? pointcut.target.prototype : pointcut.target; 4 | var source = (typeof (pointcut.target.__proto__) != 'undefined') ? pointcut.target.__proto__ : pointcut.target; 5 | var method = pointcut.method 6 | var original = source[method]; 7 | original.apply = Function.prototype.apply; 8 | Policy.apply = Function.prototype.apply; 9 | detach(pointcut.types); 10 | var aspect = function() { 11 | var types = pointcut.types; 12 | var typedargs = arguments; 13 | var overlayedargs = arguments; 14 | if (types != null) { 15 | policylog("
    typing"); 16 | typedargs = checkTypes(types, arguments); 17 | }else { 18 | policylog("
    No type"); 19 | } 20 | var invocation = { object: this, args: typedargs }; 21 | var args = arguments; 22 | return Policy.apply(invocation.object, 23 | [{ arguments: invocation.args, 24 | method: method, 25 | proceed: function() { 26 | return original.apply(invocation.object, overlay(invocation.args, args)); 27 | } 28 | } 29 | ]); 30 | }; 31 | source[method] = aspect; 32 | return aspect; 33 | }; 34 | 35 | var detach = function(object) { 36 | if (object != undefined) 37 | object.__proto__ = null; 38 | for (var x in object) 39 | if (typeof object[x] === 'object' && object[x] != null) 40 | detach(object[x]); 41 | } 42 | 43 | var o = {p: function precious(){}} 44 | 45 | enforcePolicy({target : document , method: 'createElement', types: ['string']/* , types: [{src:'string', tagName:'string'}]*/ }, 46 | function(invocation){ 47 | var tagName = invocation.arguments[0]; 48 | if(tagName=="iframe"){ 49 | policylog("creating a dynamic iframe is wrapped"); 50 | } 51 | //createElementPolicy(invocation); 52 | ifrm = invocation.proceed(); 53 | ifrmWindow = ifrm.contentWindow; 54 | policylog("ifrmWindow ="+ifrmWindow); 55 | //enforcePolicy({target : ifrmWindow , method: 'alert'}, 56 | //function(invocation){ 57 | // alertPolicy(invocation);} 58 | //); 59 | return ifrm; 60 | } 61 | ); 62 | //oldWrapper({target : document , method: 'createElement'}, 63 | // function(invocation){ 64 | // createElementPolicy(invocation);} 65 | //); 66 | 67 | -------------------------------------------------------------------------------- /SafeMashups.md: -------------------------------------------------------------------------------- 1 | # Safe Mashups # 2 | 3 | Currently, to mashup with library code provided by `https://example.org/badCode.js`, one might say `