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

Unified Diff: test/mjsunit/fixed-context-shapes-when-recompiling.js

Issue 2350683002: Add a missing test for ensuring that context shapes stay the same when recompiling. (Closed)
Patch Set: updated to use native syntax Created 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/fixed-context-shapes-when-recompiling.js
diff --git a/test/mjsunit/fixed-context-shapes-when-recompiling.js b/test/mjsunit/fixed-context-shapes-when-recompiling.js
new file mode 100644
index 0000000000000000000000000000000000000000..acfa22e51aa35008f8fa9838784c06b1a4e83222
--- /dev/null
+++ b/test/mjsunit/fixed-context-shapes-when-recompiling.js
@@ -0,0 +1,253 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --min-preparse-length 1 --allow-natives-syntax
+
+// Test that the information on which variables to allocate in context doesn't
+// change when recompiling.
+
+(function TestVarInInnerFunction() {
+ // Introduce variables which would potentially be context allocated, depending
+ // on whether an inner function refers to them or not.
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ var a; // This will make "a" actually not be context allocated.
+ a; b; c;
+ }
+ // Force recompilation.
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+
+// Other tests are the same, except that the shadowing variable "a" in inner
+// functions is declared differently.
+
+(function TestLetInInnerFunction() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ let a;
+ a; b; c;
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionParameter() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner(a) {
+ a; b; c;
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerInnerFunctionParameter() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ function innerinner(a) { a; b; c; }
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerArrowFunctionParameter() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ var f = a => a + b + c;
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionInnerFunction() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ function a() { }
+ a; b; c;
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionSloppyBlockFunction() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ if (true) { function a() { } }
+ a; b; c;
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionCatchVariable() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ try {
+ }
+ catch(a) {
+ a; b; c;
+ }
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionLoopVariable1() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ for (var a in {}) {
+ a; b; c;
+ }
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionLoopVariable2() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ for (let a in {}) {
+ a; b; c;
+ }
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionLoopVariable3() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ for (var a of []) {
+ a; b; c;
+ }
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionLoopVariable4() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ for (let a of []) {
+ a; b; c;
+ }
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
+
+(function TestInnerFunctionClass() {
+ var a = 1;
+ var b = 2;
+ var c = 3;
+ function inner() {
+ class a {}
+ a; b; c;
+ }
+ for (var i = 0; i < 3; ++i) {
+ if (i == 1) {
+ %OptimizeOsr();
+ }
+ assertEquals(1, a);
+ assertEquals(2, b);
+ assertEquals(3, c);
+ }
+})();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698