ladybird/Libraries/LibJS/Tests/function-strict-mode.js
Matthew Olsson 786722149b LibJS: Add strict mode
Adds the ability for a scope (either a function or the entire program)
to be in strict mode. Scopes default to non-strict mode.

There are two ways to determine the strict-ness of the JS engine:

1. In the parser, this can be accessed with the parser_state variable
   m_is_strict_mode boolean. If true, the Parser is currently parsing in
   strict mode. This is done so that the Parser can generate syntax
   errors at parse time, which is required in some cases.

2. With Interpreter.is_strict_mode(). This allows strict mode checking
   at runtime as opposed to compile time.

Additionally, in order to test this, a global isStrictMode() function
has been added to the JS ReplObject under the test-mode flag.
2020-05-28 17:18:42 +02:00

52 lines
900 B
JavaScript

load("test-common.js");
try {
(function() {
assert(!isStrictMode());
})();
(function() {
'use strict';
assert(isStrictMode());
})();
(function() {
"use strict";
assert(isStrictMode());
})();
(function() {
`use strict`;
assert(!isStrictMode());
})();
(function() {
;'use strict';
assert(!isStrictMode());
})();
(function() {
;"use strict";
assert(!isStrictMode());
})();
(function() {
"use strict";
(function() {
assert(isStrictMode());
})();
})();
(function() {
assert(!isStrictMode());
(function(){
"use strict";
assert(isStrictMode());
})();
assert(!isStrictMode());
})();
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}