mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-11-04 07:10:57 +00:00 
			
		
		
		
	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.
		
			
				
	
	
		
			30 lines
		
	
	
	
		
			426 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
	
		
			426 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
load("test-common.js");
 | 
						|
 | 
						|
try {
 | 
						|
    assert(isStrictMode());
 | 
						|
 | 
						|
    (function() {
 | 
						|
       assert(isStrictMode());
 | 
						|
    })();
 | 
						|
 | 
						|
    (function() {
 | 
						|
        "use strict";
 | 
						|
         assert(isStrictMode());
 | 
						|
    })();
 | 
						|
 | 
						|
 | 
						|
    (() => {
 | 
						|
        assert(isStrictMode());
 | 
						|
    })();
 | 
						|
 | 
						|
    (() => {
 | 
						|
        "use strict";
 | 
						|
        assert(isStrictMode());
 | 
						|
    })();
 | 
						|
 | 
						|
    console.log("PASS");
 | 
						|
} catch (e) {
 | 
						|
    console.log("FAIL: " + e);
 | 
						|
}
 |