mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
LibJS: Add tests for strict mode and strict mode propagation
This commit is contained in:
parent
f8a869f2fc
commit
295192bf15
2 changed files with 69 additions and 0 deletions
61
Userland/Libraries/LibJS/Tests/program-non-strict.js
Normal file
61
Userland/Libraries/LibJS/Tests/program-non-strict.js
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
"do not use strict";
|
||||||
|
"no really";
|
||||||
|
// /\ Valid directives which should not trigger strict mode
|
||||||
|
|
||||||
|
test("basic functionality", () => {
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
})();
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
})();
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
})();
|
||||||
|
|
||||||
|
function a() {
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
a();
|
||||||
|
|
||||||
|
eval("expect(isStrictMode()).toBeFalse()");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("functions with strict mode", () => {
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
|
||||||
|
function a() {
|
||||||
|
"this is allowed trust me";
|
||||||
|
"use strict";
|
||||||
|
expect(isStrictMode()).toBeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
a();
|
||||||
|
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
"use strict";
|
||||||
|
expect(isStrictMode()).toBeTrue();
|
||||||
|
})();
|
||||||
|
|
||||||
|
function b() {
|
||||||
|
eval("expect(isStrictMode()).toBeFalse()");
|
||||||
|
|
||||||
|
function nested() {
|
||||||
|
"use strict";
|
||||||
|
eval("expect(isStrictMode()).toBeTrue()");
|
||||||
|
}
|
||||||
|
|
||||||
|
nested();
|
||||||
|
|
||||||
|
eval("expect(isStrictMode()).toBeFalse()");
|
||||||
|
}
|
||||||
|
|
||||||
|
b();
|
||||||
|
});
|
|
@ -15,4 +15,12 @@ test("basic functionality", () => {
|
||||||
"use strict";
|
"use strict";
|
||||||
expect(isStrictMode()).toBeTrue();
|
expect(isStrictMode()).toBeTrue();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
function a() {
|
||||||
|
expect(isStrictMode()).toBeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
a();
|
||||||
|
|
||||||
|
eval("expect(isStrictMode()).toBeTrue()");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue