mirror of https://github.com/boa-dev/boa.git
Browse Source
* Add strict mode flag to `Context` * Add strict mode handling of `delete` * Add strict mode test * Handle non-strict functions in strict functions * Enable strict mode for functions defined in a strict contextpull/1568/head
raskad
3 years ago
committed by
GitHub
10 changed files with 265 additions and 34 deletions
@ -0,0 +1,118 @@
|
||||
use crate::exec; |
||||
|
||||
#[test] |
||||
fn strict_mode_global() { |
||||
let scenario = r#" |
||||
'use strict'; |
||||
let throws = false; |
||||
try { |
||||
delete Boolean.prototype; |
||||
} catch (e) { |
||||
throws = true; |
||||
} |
||||
throws |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "true"); |
||||
} |
||||
|
||||
#[test] |
||||
fn strict_mode_function() { |
||||
let scenario = r#" |
||||
let throws = false; |
||||
function t() { |
||||
'use strict'; |
||||
try { |
||||
delete Boolean.prototype; |
||||
} catch (e) { |
||||
throws = true; |
||||
} |
||||
} |
||||
t() |
||||
throws |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "true"); |
||||
} |
||||
|
||||
#[test] |
||||
fn strict_mode_function_after() { |
||||
let scenario = r#" |
||||
function t() { |
||||
'use strict'; |
||||
} |
||||
t() |
||||
let throws = false; |
||||
try { |
||||
delete Boolean.prototype; |
||||
} catch (e) { |
||||
throws = true; |
||||
} |
||||
throws |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "false"); |
||||
} |
||||
|
||||
#[test] |
||||
fn strict_mode_global_active_in_function() { |
||||
let scenario = r#" |
||||
'use strict' |
||||
let throws = false; |
||||
function a(){ |
||||
try { |
||||
delete Boolean.prototype; |
||||
} catch (e) { |
||||
throws = true; |
||||
} |
||||
} |
||||
a(); |
||||
throws |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "true"); |
||||
} |
||||
|
||||
#[test] |
||||
fn strict_mode_function_in_function() { |
||||
let scenario = r#" |
||||
let throws = false; |
||||
function a(){ |
||||
try { |
||||
delete Boolean.prototype; |
||||
} catch (e) { |
||||
throws = true; |
||||
} |
||||
} |
||||
function b(){ |
||||
'use strict'; |
||||
a(); |
||||
} |
||||
b(); |
||||
throws |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "false"); |
||||
} |
||||
|
||||
#[test] |
||||
fn strict_mode_function_return() { |
||||
let scenario = r#" |
||||
let throws = false; |
||||
function a() { |
||||
'use strict'; |
||||
|
||||
return function () { |
||||
try { |
||||
delete Boolean.prototype; |
||||
} catch (e) { |
||||
throws = true; |
||||
} |
||||
} |
||||
} |
||||
a()(); |
||||
throws |
||||
"#; |
||||
|
||||
assert_eq!(&exec(scenario), "true"); |
||||
} |
Loading…
Reference in new issue