diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-06 00:43:03 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-05 23:54:08 +0100 |
commit | 2a8f4f097c30fd15f8d421aa062dcab3f63cc13f (patch) | |
tree | 8bd56b53b4ad6e05e867bd017fb270331c323185 /Userland/Libraries/LibJS/Tests/non-writable-assignment.js | |
parent | 31534055e4e2ab17d3db6cb761e528568cd6e5f9 (diff) | |
download | serenity-2a8f4f097c30fd15f8d421aa062dcab3f63cc13f.zip |
LibJS: Throw TypeError on write to non-writable property in strict mode
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/non-writable-assignment.js')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/non-writable-assignment.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/non-writable-assignment.js b/Userland/Libraries/LibJS/Tests/non-writable-assignment.js new file mode 100644 index 0000000000..2674cf6221 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/non-writable-assignment.js @@ -0,0 +1,12 @@ +test("normal mode", () => { + expect(() => { + NaN = 5; // NaN is a non-writable global variable + }).not.toThrow(); +}); + +test("strict mode", () => { + expect(() => { + "use strict"; + NaN = 5; // NaN is a non-writable global variable + }).toThrowWithMessage(TypeError, "Cannot write to non-writable property 'NaN'"); +}); |