Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: test/mjsunit/harmony/block-sloppy-function.js

Issue 1376623002: Extend Annex B 3.3 sloppy-mode block-scoped hoisting to scripts, eval (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tests, many of which fail Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/block-sloppy-function.js
diff --git a/test/mjsunit/harmony/block-sloppy-function.js b/test/mjsunit/harmony/block-sloppy-function.js
index a17a4c0799c7d9bced58941597f0b150f532ee7b..9f34a45dd6ec1f3dfc3e15b8f2237629f96493eb 100644
--- a/test/mjsunit/harmony/block-sloppy-function.js
+++ b/test/mjsunit/harmony/block-sloppy-function.js
@@ -146,13 +146,6 @@
assertEquals(2, f());
})();
-// Test that hoisting from blocks doesn't happen in global scope
-function globalUnhoisted() { return 0; }
-{
- function globalUnhoisted() { return 1; }
-}
-assertEquals(0, globalUnhoisted());
-
// Test that shadowing arguments is fine
(function shadowArguments(x) {
assertArrayEquals([1], arguments);
@@ -201,3 +194,82 @@ assertThrows(function notInDefaultScope(x = y) {
assertEquals('function', typeof y);
assertEquals(x, undefined);
}, ReferenceError);
+
+// Test that hoisting from blocks does happen in global scope
+function globalHoisted() { return 0; }
+{
+ function globalHoisted() { return 1; }
+}
+assertEquals(1, globalHoisted());
+
+// Also happens when not previously defined
+assertEquals(undefined, globalUndefinedHoisted);
+{
+ function globalUndefinedHoisted() { return 1; }
+}
+assertEquals(1, globalUndefinedHoisted());
+var globalUndefinedHoistedDescriptor =
+ Object.getOwnPropertyDescriptor(this, "globalUndefinedHoisted");
+// Configurablility is not set properly BUG(v8:4451#1)
+// assertTrue(globalUndefinedHoistedDescriptor.configurable);
adamk 2015/09/30 18:24:26 Please leave this uncommented (with the current be
Dan Ehrenberg 2015/09/30 23:06:55 Done
+assertTrue(globalUndefinedHoistedDescriptor.writable);
+assertTrue(globalUndefinedHoistedDescriptor.enumerable);
+assertEquals(1, globalUndefinedHoistedDescriptor.value());
+
+// When a function property is hoisted, it should be
+// made enumerable.
+// BUG(v8:4451)
+Object.defineProperty(this, "globalNonEnumerable", {
+ value: false,
+ configurable: true,
+ writable: true,
+ enumerable: false
+});
+eval("{function globalNonEnumerable() { return 1; }}");
+var globalNonEnumerableDescriptor
+ = Object.getOwnPropertyDescriptor(this, "globalNonEnumerable");
+assertTrue(globalNonEnumerableDescriptor.configurable);
+assertTrue(globalNonEnumerableDescriptor.writable);
+// BUG(v8:4451)
+// assertTrue(globalNonEnumerableDescriptor.enumerable);
adamk 2015/09/30 18:24:26 Same here.
Dan Ehrenberg 2015/09/30 23:06:55 Done
+assertEquals(1, globalNonEnumerableDescriptor.value());
+
+// Test that hoisting from blocks does happen in an eval
+eval(`
+ function evalHoisted() { return 0; }
+ {
+ function evalHoisted() { return 1; }
+ }
+ assertEquals(1, evalHoisted());
+`);
+
+// Test that hoisting from blocks happens from eval in a function
+!function() {
+ eval(`
+ function evalInFunctionHoisted() { return 0; }
+ {
+ function evalInFunctionHoisted() { return 1; }
+ }
+ assertEquals(1, evalInFunctionHoisted());
+ `);
+}();
+
+// When the global object is frozen, silently don't hoist
+// Currently this actually throws BUG(v8:4452)
adamk 2015/09/30 18:24:26 Ah, this throws because it goes through the define
Dan Ehrenberg 2015/09/30 23:06:55 I guess it matches, but still, we eventually want
+// Object.freeze(this);
+// eval(`
+// {
+// function hoistWhenFrozen() {}
+// }
+// `);
+// assertFalse(this.hasOwnProperty("hoistWhenFrozen"));
+assertThrows(() => hoistWhenFrozen, ReferenceError);
+
+let dontHoistGlobal;
+{ function dontHoistGlobal() {} }
+assertEquals(undefined, dontHoistGlobal);
+
+let dontHoistEval;
+// OK, this really needs to be fixed...
adamk 2015/09/30 18:24:26 Yeah, this needs to be fixed before landing.
Dan Ehrenberg 2015/09/30 23:06:55 We talked about this off-line and it sounded like
+// eval("{ function dontHoistEval() {} }");
+// assertEquals(undefined, dontHoistEval);
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698