michael@0: load(libdir + "asserts.js"); michael@0: michael@0: var valid_strict_funs = [ michael@0: // directive ends on next line michael@0: function () { michael@0: "use strict" michael@0: ; michael@0: }, michael@0: function () { michael@0: "use strict" michael@0: }, michael@0: // directive ends on same line michael@0: function () { "use strict"; }, michael@0: function () { "use strict" }, michael@0: ]; michael@0: michael@0: for (var f of valid_strict_funs) { michael@0: assertThrowsInstanceOf(function() { f.caller }, TypeError); michael@0: } michael@0: michael@0: michael@0: var binary_ops = [ michael@0: "||", "&&", michael@0: "|", "^", "&", michael@0: "==", "!=", "===", "!==", michael@0: "<", "<=", ">", ">=", "in", "instanceof", michael@0: "<<", ">>", ">>>", michael@0: "+", "-", michael@0: "*", "/", "%", michael@0: ]; michael@0: michael@0: var invalid_strict_funs = [ michael@0: function () { michael@0: "use strict" michael@0: , "not"; michael@0: }, michael@0: function () { michael@0: "use strict" michael@0: ? 1 : 0; michael@0: }, michael@0: function () { michael@0: "use strict" michael@0: .length; michael@0: }, michael@0: function () { michael@0: "use strict" michael@0: [0]; michael@0: }, michael@0: function () { michael@0: "use strict" michael@0: (); michael@0: }, michael@0: ...([]), michael@0: ...[Function("'use strict'\n " + op + " 'not'") for (op of binary_ops)], michael@0: ]; michael@0: michael@0: for (var f of invalid_strict_funs) { michael@0: f.caller; michael@0: } michael@0: michael@0: michael@0: var assignment_ops = [ michael@0: "=", "+=", "-=", michael@0: "|=", "^=", "&=", michael@0: "<<=", ">>=", ">>>=", michael@0: "*=", "/=", "%=", michael@0: ]; michael@0: michael@0: var invalid_strict_funs_referror = [ michael@0: ...[("'use strict'\n " + op + " 'not'") for (op of assignment_ops)], michael@0: ]; michael@0: michael@0: // assignment with string literal as LHS is an early error, therefore we michael@0: // can only test for ReferenceError michael@0: for (var f of invalid_strict_funs_referror) { michael@0: assertThrowsInstanceOf(function() { Function(f) }, ReferenceError); michael@0: }