File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ function detectStrictMode ( src ) {
2+ return ( / ^ \s * " u s e s t r i c t " ; / g) . test ( src ) ;
3+ }
4+
5+ module . exports = detectStrictMode ;
Original file line number Diff line number Diff line change 1+ var expect = require ( "expect.js" ) ,
2+ detectStrictMode = require ( "../lib/detectStrictMode.js" ) ;
3+
4+ describe ( "detectStrictMode" , function ( ) {
5+ it ( "should detect \"use strict\"; at the beginning of a string and ignore all whitespace before" , function ( ) {
6+ expect ( detectStrictMode ( '"use strict";' ) ) . to . be ( true ) ;
7+ expect ( detectStrictMode ( ' "use strict";' ) ) . to . be ( true ) ;
8+ expect ( detectStrictMode ( ' \n "use strict";' ) ) . to . be ( true ) ;
9+ } ) ;
10+ it ( "should not detect \"use strict\"; if it occurs in some nested function" , function ( ) {
11+ expect ( detectStrictMode ( 'function () {"use strict";}' ) ) . to . be ( false ) ;
12+ } ) ;
13+ } ) ;
Original file line number Diff line number Diff line change 1+ "use strict" ; // run code in ES5 strict mode
2+
3+ function doSomethingUnstrict ( ) {
4+ var caller = arguments . callee . caller ; // this should throw an error as a proof that strict mode is on
5+ }
6+
7+ exports . doSomethingUnstrict = doSomethingUnstrict ;
You can’t perform that action at this time.
0 commit comments