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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/js/resources/const.js

Issue 1815833002: Rebaseline, fix, or remove various tests dealing with V8 behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
(Empty)
1 description(
2 "This test checks that const declarations in JavaScript work and are readonly."
3 );
4
5
6 shouldThrow("const redef='a'; const redef='a';");
7
8 const x = "RIGHT";
9 x = "WRONG";
10 shouldBe("x", '"RIGHT"');
11
12 const z = "RIGHT", y = "RIGHT";
13 y = "WRONG";
14 shouldBe("y", '"RIGHT"');
15
16 const one = 1;
17
18 var a;
19
20 // PostIncResolveNode
21 a = one++;
22 shouldBe("a", "1");
23 shouldBe("one", "1");
24
25 // PostDecResolveNode
26 a = one--;
27 shouldBe("a", "1");
28 shouldBe("one", "1");
29
30 // PreIncResolveNode
31 a = ++one;
32 shouldBe("a", "2");
33 shouldBe("one", "1");
34
35 // PreDecResolveNode
36 a = --one;
37 shouldBe("a", "0");
38 shouldBe("one", "1");
39
40 // ReadModifyConstNode
41 a = one += 2;
42 shouldBe("a", "3");
43 shouldBe("one", "1");
44
45 // AssignConstNode
46 a = one = 2;
47 shouldBe("a", "2");
48 shouldBe("one", "1");
49
50 // PostIncResolveNode
51 shouldBe("function f() { const one = 1; one++; return one; } f();", "1");
52 shouldBe("function f() { const oneString = '1'; return oneString++; } f();", "1" );
53 shouldBe("function f() { const one = 1; return one++; } f();", "1");
54
55 // PostDecResolveNode
56 shouldBe("function f() { const one = 1; one--; return one; } f();", "1");
57 shouldBe("function f() { const oneString = '1'; return oneString--; } f();", "1" );
58 shouldBe("function f() { const one = 1; return one--; } f();", "1");
59
60 // PreIncResolveNode
61 shouldBe("function f() { const one = 1; ++one; return one; } f();", "1");
62 shouldBe("function f() { const one = 1; return ++one; } f();", "2");
63
64 // PreDecResolveNode
65 shouldBe("function f() { const one = 1; --one; return one; } f();", "1");
66 shouldBe("function f() { const one = 1; return --one; } f();", "0");
67
68 // ReadModifyConstNode
69 shouldBe("function f() { const one = 1; one += 2; return one; } f();", "1");
70 shouldBe("function f() { const one = 1; return one += 2; } f();", "3");
71
72 // AssignConstNode
73 shouldBe("function f() { const one = 1; one = 2; return one; } f();", "1");
74 shouldBe("function f() { const one = 1; return one = 2; } f();", "2");
75
76 // PostIncResolveNode
77 shouldBe("one++", "1");
78 shouldBe("one", "1");
79
80 // PostDecResolveNode
81 shouldBe("one--", "1");
82 shouldBe("one", "1");
83
84 // PreIncResolveNode
85 shouldBe("++one", "2");
86 shouldBe("one", "1");
87
88 // PreDecResolveNode
89 shouldBe("--one", "0");
90 shouldBe("one", "1");
91
92 // ReadModifyConstNode
93 shouldBe("one += 1", "2");
94 shouldBe("one", "1");
95
96 // AssignConstNode
97 shouldBe("one = 2", "2");
98 shouldBe("one", "1");
99
100 var object = { inWith1: "RIGHT", inWith2: ""}
101 with (object) {
102 const inWith1 = "WRONG";
103 const inWith2 = "RIGHT";
104 inWith2 = "WRONG";
105 }
106 shouldBe("object.inWith1", "'RIGHT'");
107 shouldBe("inWith2", "'RIGHT'");
108
109 shouldBe("(function(){ one = 2; return one; })()", "1")
110 var f = function g() { g="FAIL"; return g; };
111 shouldBe("f()", "f");
112
113 shouldBe("const a;", "undefined");
114
115 // Make sure we don't override properties placed on the global object
116 var ranConstInitialiser = false;
117 const bodyId = (ranConstInitialiser = true, "Const initialiser overwrote existin g property");
118 shouldBe("bodyId", "document.getElementById('bodyId')");
119 shouldBeTrue("ranConstInitialiser");
120
121 // Make sure that dynamic scopes (catch, with) don't break const declarations
122 function tryCatch1() {
123 var bar;
124 eval("try {\
125 stuff();\
126 } catch (e) {\
127 const bar = 5;\
128 }");
129 return bar;
130 }
131
132 function tryCatch2() {
133 var bar;
134 try {
135 stuff();
136 } catch (e) {
137 const bar = 5;
138 }
139 return bar;
140 }
141
142 tryCatch1Result = tryCatch1();
143 shouldBe("tryCatch1Result", "5");
144 tryCatch2Result = tryCatch2();
145 shouldBe("tryCatch2Result", "5");
146
147 function with1() {
148 var bar;
149 eval("with({foo:42}) const bar = 5;");
150 return bar;
151 }
152
153 function with2() {
154 var bar;
155 with({foo:42}) const bar = 5;
156 return bar;
157 }
158
159 with1Result = with1();
160 shouldBe("with1Result", "5");
161 with2Result = with2();
162 shouldBe("with2Result", "5");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698