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

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2277363002: [stubs] Consolidate TryToName implementation (Closed)
Patch Set: reword comment 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 unified diff | Download patch
« no previous file with comments | « src/compiler/code-assembler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/utils/random-number-generator.h" 5 #include "src/base/utils/random-number-generator.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/code-stub-assembler.h" 7 #include "src/code-stub-assembler.h"
8 #include "src/compiler/node.h" 8 #include "src/compiler/node.h"
9 #include "src/ic/stub-cache.h" 9 #include "src/ic/stub-cache.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 CodeStubAssemblerTester m(isolate, kNumParams); 128 CodeStubAssemblerTester m(isolate, kNumParams);
129 129
130 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; 130 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
131 { 131 {
132 Node* key = m.Parameter(0); 132 Node* key = m.Parameter(0);
133 Node* expected_result = m.Parameter(1); 133 Node* expected_result = m.Parameter(1);
134 Node* expected_arg = m.Parameter(2); 134 Node* expected_arg = m.Parameter(2);
135 135
136 Label passed(&m), failed(&m); 136 Label passed(&m), failed(&m);
137 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); 137 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m);
138 Variable var_index(&m, MachineRepresentation::kWord32); 138 Variable var_index(&m, MachineType::PointerRepresentation());
139 139
140 m.TryToName(key, &if_keyisindex, &var_index, &if_keyisunique, &if_bailout); 140 m.TryToName(key, &if_keyisindex, &var_index, &if_keyisunique, &if_bailout);
141 141
142 m.Bind(&if_keyisindex); 142 m.Bind(&if_keyisindex);
143 m.GotoUnless( 143 m.GotoUnless(
144 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsIndex))), 144 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsIndex))),
145 &failed); 145 &failed);
146 m.Branch(m.Word32Equal(m.SmiToWord32(expected_arg), var_index.value()), 146 m.Branch(m.WordEqual(m.SmiUntag(expected_arg), var_index.value()), &passed,
147 &passed, &failed); 147 &failed);
148 148
149 m.Bind(&if_keyisunique); 149 m.Bind(&if_keyisunique);
150 m.GotoUnless( 150 m.GotoUnless(
151 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsUnique))), 151 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsUnique))),
152 &failed); 152 &failed);
153 m.Branch(m.WordEqual(expected_arg, key), &passed, &failed); 153 m.Branch(m.WordEqual(expected_arg, key), &passed, &failed);
154 154
155 m.Bind(&if_bailout); 155 m.Bind(&if_bailout);
156 m.Branch( 156 m.Branch(
157 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 157 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
(...skipping 19 matching lines...) Expand all
177 ft.CheckTrue(key, expect_index, key); 177 ft.CheckTrue(key, expect_index, key);
178 } 178 }
179 179
180 { 180 {
181 // TryToName(<positive smi>) => if_keyisindex: smi value. 181 // TryToName(<positive smi>) => if_keyisindex: smi value.
182 Handle<Object> key(Smi::FromInt(153), isolate); 182 Handle<Object> key(Smi::FromInt(153), isolate);
183 ft.CheckTrue(key, expect_index, key); 183 ft.CheckTrue(key, expect_index, key);
184 } 184 }
185 185
186 { 186 {
187 // TryToName(<negative smi>) => bailout. 187 // TryToName(<negative smi>) => if_keyisindex: smi value.
188 // A subsequent bounds check needs to take care of this case.
188 Handle<Object> key(Smi::FromInt(-1), isolate); 189 Handle<Object> key(Smi::FromInt(-1), isolate);
189 ft.CheckTrue(key, expect_bailout); 190 ft.CheckTrue(key, expect_index, key);
190 } 191 }
191 192
192 { 193 {
194 // TryToName(<heap number with int value>) => if_keyisindex: number.
195 Handle<Object> key(isolate->factory()->NewHeapNumber(153));
196 Handle<Object> index(Smi::FromInt(153), isolate);
197 ft.CheckTrue(key, expect_index, index);
198 }
199
200 {
193 // TryToName(<symbol>) => if_keyisunique: <symbol>. 201 // TryToName(<symbol>) => if_keyisunique: <symbol>.
194 Handle<Object> key = isolate->factory()->NewSymbol(); 202 Handle<Object> key = isolate->factory()->NewSymbol();
195 ft.CheckTrue(key, expect_unique, key); 203 ft.CheckTrue(key, expect_unique, key);
196 } 204 }
197 205
198 { 206 {
199 // TryToName(<internalized string>) => if_keyisunique: <internalized string> 207 // TryToName(<internalized string>) => if_keyisunique: <internalized string>
200 Handle<Object> key = isolate->factory()->InternalizeUtf8String("test"); 208 Handle<Object> key = isolate->factory()->InternalizeUtf8String("test");
201 ft.CheckTrue(key, expect_unique, key); 209 ft.CheckTrue(key, expect_unique, key);
202 } 210 }
203 211
204 { 212 {
205 // TryToName(<internalized number string>) => if_keyisindex: number. 213 // TryToName(<internalized number string>) => if_keyisindex: number.
206 Handle<Object> key = isolate->factory()->InternalizeUtf8String("153"); 214 Handle<Object> key = isolate->factory()->InternalizeUtf8String("153");
207 Handle<Object> index(Smi::FromInt(153), isolate); 215 Handle<Object> index(Smi::FromInt(153), isolate);
208 ft.CheckTrue(key, expect_index, index); 216 ft.CheckTrue(key, expect_index, index);
209 } 217 }
210 218
211 { 219 {
220 // TryToName(<internalized uncacheable number string>) => bailout
221 Handle<Object> key =
222 isolate->factory()->InternalizeUtf8String("4294967294");
223 ft.CheckTrue(key, expect_bailout);
224 }
225
226 {
227 // TryToName(<non-internalized number string>) => if_keyisindex: number.
228 Handle<String> key = isolate->factory()->NewStringFromAsciiChecked("153");
229 uint32_t dummy;
230 CHECK(key->AsArrayIndex(&dummy));
231 CHECK(key->HasHashCode());
232 CHECK(!key->IsInternalizedString());
233 Handle<Object> index(Smi::FromInt(153), isolate);
234 ft.CheckTrue(key, expect_index, index);
235 }
236
237 {
238 // TryToName(<number string without cached index>) => bailout.
239 Handle<String> key = isolate->factory()->NewStringFromAsciiChecked("153");
240 CHECK(!key->HasHashCode());
241 ft.CheckTrue(key, expect_bailout);
242 }
243
244 {
212 // TryToName(<non-internalized string>) => bailout. 245 // TryToName(<non-internalized string>) => bailout.
213 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test"); 246 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test");
214 ft.CheckTrue(key, expect_bailout); 247 ft.CheckTrue(key, expect_bailout);
215 } 248 }
216 } 249 }
217 250
218 namespace { 251 namespace {
219 252
220 template <typename Dictionary> 253 template <typename Dictionary>
221 void TestNameDictionaryLookup() { 254 void TestNameDictionaryLookup() {
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 1504
1472 Handle<Object> constructor = 1505 Handle<Object> constructor =
1473 Object::GetPropertyOrElement(result, 1506 Object::GetPropertyOrElement(result,
1474 isolate->factory()->constructor_string()) 1507 isolate->factory()->constructor_string())
1475 .ToHandleChecked(); 1508 .ToHandleChecked();
1476 CHECK(constructor->SameValue(*isolate->type_error_function())); 1509 CHECK(constructor->SameValue(*isolate->type_error_function()));
1477 } 1510 }
1478 1511
1479 } // namespace internal 1512 } // namespace internal
1480 } // namespace v8 1513 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/code-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698