haikuwebkit/LayoutTests/fast/dom/window-const-variable-shado...

69 lines
1.5 KiB
HTML
Raw Permalink Normal View History

`const location = "foo"` throws in a worker https://bugs.webkit.org/show_bug.cgi?id=169839 Reviewed by Mark Lam. JSTests: * ChakraCore/test/es6/letconst_global_shadow_builtins_nonconfigurable.baseline-jsc: Update expected jsc result now that we throw a SyntaxError when trying to shadow undefined with a let variable. We used not to throw because the value is undefined but this was not as per EcmaScript. Both Firefox and Chrome throw in this case. * stress/global-lexical-redeclare-variable.js: (catch): Update test that defines a non-configurable 'zoo' property on the global object and then expected shadowing it with a 'let zoo' variable to work because its value was undefined. This was not as per EcmaScript spec and both Firefox and Chrome throw in this case. Source/JavaScriptCore: Our HasRestrictedGlobalProperty check in JSC was slightly wrong, causing us to sometimes throw a Syntax exception when we shouldn't when declaring a const/let variable and sometimes not throw an exception when we should have. This aligns our behavior with ES6, Firefox and Chrome. * runtime/ProgramExecutable.cpp: (JSC::hasRestrictedGlobalProperty): (JSC::ProgramExecutable::initializeGlobalProperties): Rewrite hasRestrictedGlobalProperty logic as per the EcmaScript spec: - http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasproperty In particular, they were 2 issues: - We should throw a SyntaxError if hasProperty() returned true but getOwnProperty() would fail to return a descriptor. This would happen for properties that are not OWN properties, but defined somewhere in the prototype chain. The spec does not say to use hasProperty(), only getOwnProperty() and says we should return false if getOwnProperty() does not return a descriptor. This is what we do now. - We would fail to throw when declaring a let/const variable that shadows an own property whose value is undefined. This is because the previous code was explicitly checking for this case. I believe this was a misinterpretation of ES6 which says: """ Let desc be O.[[GetOwnProperty]](P). If desc is undefined, return false. """ We should check that desc is undefined, not desc.value. This is now fixed. LayoutTests: * fast/dom/window-const-variable-shadowing-expected.txt: Added. * fast/dom/window-const-variable-shadowing.html: Added. * fast/workers/const-location-variable-expected.txt: Added. * fast/workers/const-location-variable.html: Added. * fast/workers/resources/worker-const-location.js: Added. Add layout test coverage for behavior changes. Those tests pass in Firefox and Chrome. * js/dom/const-expected.txt: * js/dom/const.html: Update test which wrongly expected a let variable not to be able to shadow a window named property. This test was failing in Chrome and Firefox. The reason this does not throw is because window named properties are not on the window object, they are on the WindowProperties object in the Window prototype chain. Canonical link: https://commits.webkit.org/186805@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214145 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-19 17:45:39 +00:00
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test-pre.js"></script>
<script>
description("Tests various cases of const variable shadowing on Window.");
let sentinel = "good";
</script>
<script>
debug("Should throw because Window has a non-configurable location own property.");
</script>
<script>
const location = 3;
sentinel = "bad";
</script>
<script>
shouldBeEqualToString("sentinel", "good");
</script>
<script>
debug("");
debug("Should throw because window has an own property foo that is not configurable, even though its value is undefined.");
Object.defineProperty(window, 'foo', {value: undefined, configurable: false, writable: true});
</script>
<script>
const foo = 3;
sentinel = "bad";
</script>
<script>
shouldBeEqualToString("sentinel", "good");
</script>
<script>
debug("");
debug("Should work because Window's own bar property is configurable.");
Object.defineProperty(window, 'bar', {value: 2, configurable: true, writable: true});
sentinel = "bad";
</script>
<script>
const bar = 3;
sentinel = "good";
shouldBe("bar", "3");
</script>
<script>
shouldBeEqualToString("sentinel", "good");
</script>
<script>
debug("");
debug("Should work because dispatchEvent is not an own property, it comes from the prototype chain.");
sentinel = "bad"
</script>
<script>
const dispatchEvent = 3;
sentinel = "good";
shouldBe("dispatchEvent", "3");
</script>
<script>
shouldBeEqualToString("sentinel", "good");
</script>
<script>
successfullyParsed = true;
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>