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

Side by Side Diff: test/mjsunit/const-eval-init.js

Issue 379893002: Clean up and update const / var (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 18 matching lines...) Expand all
29 29
30 // Test the handling of initialization of deleted const variables. 30 // Test the handling of initialization of deleted const variables.
31 // This only makes sense in local scopes since the declaration and 31 // This only makes sense in local scopes since the declaration and
32 // initialization of consts in the global scope happen at the same 32 // initialization of consts in the global scope happen at the same
33 // time. 33 // time.
34 34
35 function testIntroduceGlobal() { 35 function testIntroduceGlobal() {
36 var source = 36 var source =
37 // Deleting 'x' removes the local const property. 37 // Deleting 'x' removes the local const property.
38 "delete x;" + 38 "delete x;" +
39 // Initialization turns into assignment to global 'x'. 39 // Initialization turns into assignment to global 'x'.
rossberg 2014/07/11 12:54:49 Adjust comment (also below)
Toon Verwaest 2014/07/14 07:39:55 Done.
40 "const x = 3; assertEquals(3, x);" + 40 "const x = 3; assertEquals(3, x);" +
41 // No constness of the global 'x'. 41 // Test constness of the global 'x'.
42 "x = 4; assertEquals(4, x);"; 42 "x = 4; assertEquals(3, x);";
43 eval(source); 43 eval(source);
44 } 44 }
45 45
46 testIntroduceGlobal(); 46 testIntroduceGlobal();
47 assertEquals(4, x); 47 assertEquals("undefined", typeof x);
48 48
49 function testAssignExistingGlobal() { 49 function testAssignExistingGlobal() {
50 var source = 50 var source =
51 // Delete 'x' to remove the local const property. 51 // Delete 'x' to remove the local const property.
52 "delete x;" + 52 "delete x;" +
53 // Initialization turns into assignment to global 'x'. 53 // Initialization turns into assignment to global 'x'.
54 "const x = 5; assertEquals(5, x);" + 54 "const x = 5; assertEquals(5, x);" +
55 // No constness of the global 'x'. 55 // Test constness of the global 'x'.
56 "x = 6; assertEquals(6, x);"; 56 "x = 6; assertEquals(5, x);";
57 eval(source); 57 eval(source);
58 } 58 }
59 59
60 testAssignExistingGlobal(); 60 testAssignExistingGlobal();
61 assertEquals(6, x); 61 assertEquals("undefined", typeof x);
62 62
63 function testAssignmentArgument(x) { 63 function testAssignmentArgument(x) {
64 function local() { 64 function local() {
65 var source = "delete x; const x = 7; assertEquals(7, x)"; 65 var source = "delete x; const x = 7; assertEquals(7, x)";
66 eval(source); 66 eval(source);
67 } 67 }
68 local(); 68 local();
69 assertEquals(7, x); 69 assertEquals("undefined", typeof x);
70 } 70 }
71 71
72 for (var i = 0; i < 5; i++) { 72 for (var i = 0; i < 5; i++) {
73 testAssignmentArgument(); 73 testAssignmentArgument();
74 } 74 }
75 %OptimizeFunctionOnNextCall(testAssignmentArgument); 75 %OptimizeFunctionOnNextCall(testAssignmentArgument);
76 testAssignmentArgument(); 76 testAssignmentArgument();
77 assertEquals(6, x); 77 assertEquals("undefined", typeof x);
78 78
79 __defineSetter__('x', function() { throw 42; }); 79 __defineSetter__('x', function() { throw 42; });
80 var finished = false;
80 function testAssignGlobalThrows() { 81 function testAssignGlobalThrows() {
81 // Initialization turns into assignment to global 'x' which 82 // Initialization turns into assignment to global 'x' which
82 // throws an exception. 83 // throws an exception.
83 var source = "delete x; const x = 8"; 84 var source = "delete x; const x = 8; finished = true;";
84 eval(source); 85 eval(source);
85 } 86 }
86 87
87 assertThrows("testAssignGlobalThrows()"); 88 testAssignGlobalThrows();
89 assertTrue(finished);
88 90
89 function testInitFastCaseExtension() { 91 function testInitFastCaseExtension() {
90 var source = "const x = 9; assertEquals(9, x); x = 10; assertEquals(9, x)"; 92 var source = "const x = 9; assertEquals(9, x); x = 10; assertEquals(9, x)";
91 eval(source); 93 eval(source);
92 } 94 }
93 95
94 testInitFastCaseExtension(); 96 testInitFastCaseExtension();
95 97
96 function testInitSlowCaseExtension() { 98 function testInitSlowCaseExtension() {
97 var source = ""; 99 var source = "";
98 // Introduce 100 properties on the context extension object to force 100 // Introduce 100 properties on the context extension object to force
99 // it in slow case. 101 // it in slow case.
100 for (var i = 0; i < 100; i++) source += ("var a" + i + " = " + i + ";"); 102 for (var i = 0; i < 100; i++) source += ("var a" + i + " = " + i + ";");
101 source += "const x = 10; assertEquals(10, x); x = 11; assertEquals(10, x)"; 103 source += "const x = 10; assertEquals(10, x); x = 11; assertEquals(10, x)";
102 eval(source); 104 eval(source);
103 } 105 }
104 106
105 testInitSlowCaseExtension(); 107 testInitSlowCaseExtension();
106 108
107 function testAssignSurroundingContextSlot() { 109 function testAssignSurroundingContextSlot() {
108 var x = 12; 110 var x = 12;
109 function local() { 111 function local() {
110 var source = "delete x; const x = 13; assertEquals(13, x)"; 112 var source = "delete x; const x = 13; assertEquals(13, x)";
111 eval(source); 113 eval(source);
112 } 114 }
113 local(); 115 local();
114 assertEquals(13, x); 116 assertEquals(12, x);
115 } 117 }
116 118
117 testAssignSurroundingContextSlot(); 119 testAssignSurroundingContextSlot();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698