LibJS: Add tests for strict mode and strict mode propagation

This commit is contained in:
davidot 2021-07-12 01:39:03 +02:00 committed by Andreas Kling
parent f8a869f2fc
commit 295192bf15
2 changed files with 69 additions and 0 deletions

View 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();
});

View file

@ -15,4 +15,12 @@ test("basic functionality", () => {
"use strict";
expect(isStrictMode()).toBeTrue();
})();
function a() {
expect(isStrictMode()).toBeTrue();
}
a();
eval("expect(isStrictMode()).toBeTrue()");
});