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

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

Issue 2498073002: [refactoring] Split CodeAssemblerState out of CodeAssembler (Closed)
Patch Set: one more attempt Created 4 years, 1 month 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
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"
11 #include "test/cctest/compiler/code-assembler-tester.h" 11 #include "test/cctest/compiler/code-assembler-tester.h"
12 #include "test/cctest/compiler/function-tester.h" 12 #include "test/cctest/compiler/function-tester.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 using compiler::CodeAssemblerTester;
17 using compiler::FunctionTester; 18 using compiler::FunctionTester;
18 using compiler::Node; 19 using compiler::Node;
19 20
20 typedef compiler::CodeAssemblerTesterImpl<CodeStubAssembler>
21 CodeStubAssemblerTester;
22
23 TEST(FixedArrayAccessSmiIndex) { 21 TEST(FixedArrayAccessSmiIndex) {
24 Isolate* isolate(CcTest::InitIsolateOnce()); 22 Isolate* isolate(CcTest::InitIsolateOnce());
25 VoidDescriptor descriptor(isolate); 23 CodeAssemblerTester data(isolate);
26 CodeStubAssemblerTester m(isolate, descriptor); 24 CodeStubAssembler m(data.state());
27 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); 25 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5);
28 array->set(4, Smi::FromInt(733)); 26 array->set(4, Smi::FromInt(733));
29 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array), 27 m.Return(m.LoadFixedArrayElement(m.HeapConstant(array),
30 m.SmiTag(m.Int32Constant(4)), 0, 28 m.SmiTag(m.Int32Constant(4)), 0,
31 CodeStubAssembler::SMI_PARAMETERS)); 29 CodeStubAssembler::SMI_PARAMETERS));
32 Handle<Code> code = m.GenerateCode(); 30 Handle<Code> code = data.GenerateCode();
33 FunctionTester ft(descriptor, code); 31 FunctionTester ft(code);
34 MaybeHandle<Object> result = ft.Call(); 32 MaybeHandle<Object> result = ft.Call();
35 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value()); 33 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value());
36 } 34 }
37 35
38 TEST(LoadHeapNumberValue) { 36 TEST(LoadHeapNumberValue) {
39 Isolate* isolate(CcTest::InitIsolateOnce()); 37 Isolate* isolate(CcTest::InitIsolateOnce());
40 VoidDescriptor descriptor(isolate); 38 CodeAssemblerTester data(isolate);
41 CodeStubAssemblerTester m(isolate, descriptor); 39 CodeStubAssembler m(data.state());
42 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234); 40 Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234);
43 m.Return(m.SmiTag( 41 m.Return(m.SmiTag(
44 m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number))))); 42 m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number)))));
45 Handle<Code> code = m.GenerateCode(); 43 Handle<Code> code = data.GenerateCode();
46 FunctionTester ft(descriptor, code); 44 FunctionTester ft(code);
47 MaybeHandle<Object> result = ft.Call(); 45 MaybeHandle<Object> result = ft.Call();
48 CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value()); 46 CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value());
49 } 47 }
50 48
51 TEST(LoadInstanceType) { 49 TEST(LoadInstanceType) {
52 Isolate* isolate(CcTest::InitIsolateOnce()); 50 Isolate* isolate(CcTest::InitIsolateOnce());
53 VoidDescriptor descriptor(isolate); 51 CodeAssemblerTester data(isolate);
54 CodeStubAssemblerTester m(isolate, descriptor); 52 CodeStubAssembler m(data.state());
55 Handle<HeapObject> undefined = isolate->factory()->undefined_value(); 53 Handle<HeapObject> undefined = isolate->factory()->undefined_value();
56 m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined)))); 54 m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined))));
57 Handle<Code> code = m.GenerateCode(); 55 Handle<Code> code = data.GenerateCode();
58 FunctionTester ft(descriptor, code); 56 FunctionTester ft(code);
59 MaybeHandle<Object> result = ft.Call(); 57 MaybeHandle<Object> result = ft.Call();
60 CHECK_EQ(InstanceType::ODDBALL_TYPE, 58 CHECK_EQ(InstanceType::ODDBALL_TYPE,
61 Handle<Smi>::cast(result.ToHandleChecked())->value()); 59 Handle<Smi>::cast(result.ToHandleChecked())->value());
62 } 60 }
63 61
64 TEST(DecodeWordFromWord32) { 62 TEST(DecodeWordFromWord32) {
65 Isolate* isolate(CcTest::InitIsolateOnce()); 63 Isolate* isolate(CcTest::InitIsolateOnce());
66 VoidDescriptor descriptor(isolate); 64 CodeAssemblerTester data(isolate);
67 CodeStubAssemblerTester m(isolate, descriptor); 65 CodeStubAssembler m(data.state());
68 66
69 class TestBitField : public BitField<unsigned, 3, 3> {}; 67 class TestBitField : public BitField<unsigned, 3, 3> {};
70 m.Return( 68 m.Return(
71 m.SmiTag(m.DecodeWordFromWord32<TestBitField>(m.Int32Constant(0x2f)))); 69 m.SmiTag(m.DecodeWordFromWord32<TestBitField>(m.Int32Constant(0x2f))));
72 Handle<Code> code = m.GenerateCode(); 70 Handle<Code> code = data.GenerateCode();
73 FunctionTester ft(descriptor, code); 71 FunctionTester ft(code);
74 MaybeHandle<Object> result = ft.Call(); 72 MaybeHandle<Object> result = ft.Call();
75 // value = 00101111 73 // value = 00101111
76 // mask = 00111000 74 // mask = 00111000
77 // result = 101 75 // result = 101
78 CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value()); 76 CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value());
79 } 77 }
80 78
81 TEST(JSFunction) { 79 TEST(JSFunction) {
82 const int kNumParams = 3; // Receiver, left, right. 80 const int kNumParams = 3; // Receiver, left, right.
83 Isolate* isolate(CcTest::InitIsolateOnce()); 81 Isolate* isolate(CcTest::InitIsolateOnce());
84 CodeStubAssemblerTester m(isolate, kNumParams); 82 CodeAssemblerTester data(isolate, kNumParams);
83 CodeStubAssembler m(data.state());
85 m.Return(m.SmiFromWord32(m.Int32Add(m.SmiToWord32(m.Parameter(1)), 84 m.Return(m.SmiFromWord32(m.Int32Add(m.SmiToWord32(m.Parameter(1)),
86 m.SmiToWord32(m.Parameter(2))))); 85 m.SmiToWord32(m.Parameter(2)))));
87 86
88 Handle<Code> code = m.GenerateCode(); 87 Handle<Code> code = data.GenerateCode();
89 FunctionTester ft(code, kNumParams); 88 FunctionTester ft(code, kNumParams);
90 89
91 MaybeHandle<Object> result = ft.Call(isolate->factory()->undefined_value(), 90 MaybeHandle<Object> result = ft.Call(isolate->factory()->undefined_value(),
92 handle(Smi::FromInt(23), isolate), 91 handle(Smi::FromInt(23), isolate),
93 handle(Smi::FromInt(34), isolate)); 92 handle(Smi::FromInt(34), isolate));
94 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value()); 93 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
95 } 94 }
96 95
97 TEST(ComputeIntegerHash) { 96 TEST(ComputeIntegerHash) {
98 Isolate* isolate(CcTest::InitIsolateOnce()); 97 Isolate* isolate(CcTest::InitIsolateOnce());
99 const int kNumParams = 2; 98 const int kNumParams = 2;
100 CodeStubAssemblerTester m(isolate, kNumParams); 99 CodeAssemblerTester data(isolate, kNumParams);
100 CodeStubAssembler m(data.state());
101 m.Return(m.SmiFromWord32(m.ComputeIntegerHash( 101 m.Return(m.SmiFromWord32(m.ComputeIntegerHash(
102 m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1))))); 102 m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1)))));
103 103
104 Handle<Code> code = m.GenerateCode(); 104 Handle<Code> code = data.GenerateCode();
105 FunctionTester ft(code, kNumParams); 105 FunctionTester ft(code, kNumParams);
106 106
107 Handle<Smi> hash_seed = isolate->factory()->hash_seed(); 107 Handle<Smi> hash_seed = isolate->factory()->hash_seed();
108 108
109 base::RandomNumberGenerator rand_gen(FLAG_random_seed); 109 base::RandomNumberGenerator rand_gen(FLAG_random_seed);
110 110
111 for (int i = 0; i < 1024; i++) { 111 for (int i = 0; i < 1024; i++) {
112 int k = rand_gen.NextInt(Smi::kMaxValue); 112 int k = rand_gen.NextInt(Smi::kMaxValue);
113 113
114 Handle<Smi> key(Smi::FromInt(k), isolate); 114 Handle<Smi> key(Smi::FromInt(k), isolate);
115 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked(); 115 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked();
116 116
117 uint32_t hash = ComputeIntegerHash(k, hash_seed->value()); 117 uint32_t hash = ComputeIntegerHash(k, hash_seed->value());
118 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue); 118 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue);
119 CHECK_EQ(expected, Smi::cast(*result)); 119 CHECK_EQ(expected, Smi::cast(*result));
120 } 120 }
121 } 121 }
122 122
123 TEST(ToString) { 123 TEST(ToString) {
124 Isolate* isolate(CcTest::InitIsolateOnce()); 124 Isolate* isolate(CcTest::InitIsolateOnce());
125 const int kNumParams = 1; 125 const int kNumParams = 1;
126 CodeStubAssemblerTester m(isolate, kNumParams); 126 CodeAssemblerTester data(isolate, kNumParams);
127 CodeStubAssembler m(data.state());
127 m.Return(m.ToString(m.Parameter(kNumParams + 2), m.Parameter(0))); 128 m.Return(m.ToString(m.Parameter(kNumParams + 2), m.Parameter(0)));
128 129
129 Handle<Code> code = m.GenerateCode(); 130 Handle<Code> code = data.GenerateCode();
130 FunctionTester ft(code, kNumParams); 131 FunctionTester ft(code, kNumParams);
131 132
132 Handle<FixedArray> test_cases = isolate->factory()->NewFixedArray(5); 133 Handle<FixedArray> test_cases = isolate->factory()->NewFixedArray(5);
133 Handle<FixedArray> smi_test = isolate->factory()->NewFixedArray(2); 134 Handle<FixedArray> smi_test = isolate->factory()->NewFixedArray(2);
134 smi_test->set(0, Smi::FromInt(42)); 135 smi_test->set(0, Smi::FromInt(42));
135 Handle<String> str(isolate->factory()->InternalizeUtf8String("42")); 136 Handle<String> str(isolate->factory()->InternalizeUtf8String("42"));
136 smi_test->set(1, *str); 137 smi_test->set(1, *str);
137 test_cases->set(0, *smi_test); 138 test_cases->set(0, *smi_test);
138 139
139 Handle<FixedArray> number_test = isolate->factory()->NewFixedArray(2); 140 Handle<FixedArray> number_test = isolate->factory()->NewFixedArray(2);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 Handle<String> expected = handle(String::cast(test->get(1))); 173 Handle<String> expected = handle(String::cast(test->get(1)));
173 Handle<Object> result = ft.Call(obj).ToHandleChecked(); 174 Handle<Object> result = ft.Call(obj).ToHandleChecked();
174 CHECK(result->IsString()); 175 CHECK(result->IsString());
175 CHECK(String::Equals(Handle<String>::cast(result), expected)); 176 CHECK(String::Equals(Handle<String>::cast(result), expected));
176 } 177 }
177 } 178 }
178 179
179 TEST(FlattenString) { 180 TEST(FlattenString) {
180 Isolate* isolate(CcTest::InitIsolateOnce()); 181 Isolate* isolate(CcTest::InitIsolateOnce());
181 const int kNumParams = 1; 182 const int kNumParams = 1;
182 CodeStubAssemblerTester m(isolate, kNumParams); 183 CodeAssemblerTester data(isolate, kNumParams);
184 CodeStubAssembler m(data.state());
183 m.Return(m.FlattenString(m.Parameter(0))); 185 m.Return(m.FlattenString(m.Parameter(0)));
184 186
185 Handle<Code> code = m.GenerateCode(); 187 Handle<Code> code = data.GenerateCode();
186 FunctionTester ft(code, kNumParams); 188 FunctionTester ft(code, kNumParams);
187 189
188 Handle<FixedArray> test_cases(isolate->factory()->NewFixedArray(4)); 190 Handle<FixedArray> test_cases(isolate->factory()->NewFixedArray(4));
189 Handle<String> expected( 191 Handle<String> expected(
190 isolate->factory()->InternalizeUtf8String("hello, world!")); 192 isolate->factory()->InternalizeUtf8String("hello, world!"));
191 test_cases->set(0, *expected); 193 test_cases->set(0, *expected);
192 194
193 Handle<String> string( 195 Handle<String> string(
194 isolate->factory()->InternalizeUtf8String("filler hello, world! filler")); 196 isolate->factory()->InternalizeUtf8String("filler hello, world! filler"));
195 Handle<String> sub_string( 197 Handle<String> sub_string(
(...skipping 19 matching lines...) Expand all
215 CHECK(String::Equals(Handle<String>::cast(result), expected)); 217 CHECK(String::Equals(Handle<String>::cast(result), expected));
216 } 218 }
217 } 219 }
218 220
219 TEST(TryToName) { 221 TEST(TryToName) {
220 typedef CodeStubAssembler::Label Label; 222 typedef CodeStubAssembler::Label Label;
221 typedef CodeStubAssembler::Variable Variable; 223 typedef CodeStubAssembler::Variable Variable;
222 Isolate* isolate(CcTest::InitIsolateOnce()); 224 Isolate* isolate(CcTest::InitIsolateOnce());
223 225
224 const int kNumParams = 3; 226 const int kNumParams = 3;
225 CodeStubAssemblerTester m(isolate, kNumParams); 227 CodeAssemblerTester data(isolate, kNumParams);
228 CodeStubAssembler m(data.state());
226 229
227 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; 230 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
228 { 231 {
229 Node* key = m.Parameter(0); 232 Node* key = m.Parameter(0);
230 Node* expected_result = m.Parameter(1); 233 Node* expected_result = m.Parameter(1);
231 Node* expected_arg = m.Parameter(2); 234 Node* expected_arg = m.Parameter(2);
232 235
233 Label passed(&m), failed(&m); 236 Label passed(&m), failed(&m);
234 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); 237 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m);
235 Variable var_index(&m, MachineType::PointerRepresentation()); 238 Variable var_index(&m, MachineType::PointerRepresentation());
(...skipping 18 matching lines...) Expand all
254 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 257 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
255 &passed, &failed); 258 &passed, &failed);
256 259
257 m.Bind(&passed); 260 m.Bind(&passed);
258 m.Return(m.BooleanConstant(true)); 261 m.Return(m.BooleanConstant(true));
259 262
260 m.Bind(&failed); 263 m.Bind(&failed);
261 m.Return(m.BooleanConstant(false)); 264 m.Return(m.BooleanConstant(false));
262 } 265 }
263 266
264 Handle<Code> code = m.GenerateCode(); 267 Handle<Code> code = data.GenerateCode();
265 FunctionTester ft(code, kNumParams); 268 FunctionTester ft(code, kNumParams);
266 269
267 Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate); 270 Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate);
268 Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate); 271 Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate);
269 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); 272 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate);
270 273
271 { 274 {
272 // TryToName(<zero smi>) => if_keyisindex: smi value. 275 // TryToName(<zero smi>) => if_keyisindex: smi value.
273 Handle<Object> key(Smi::kZero, isolate); 276 Handle<Object> key(Smi::kZero, isolate);
274 ft.CheckTrue(key, expect_index, key); 277 ft.CheckTrue(key, expect_index, key);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 348 }
346 } 349 }
347 350
348 namespace { 351 namespace {
349 352
350 template <typename Dictionary> 353 template <typename Dictionary>
351 void TestEntryToIndex() { 354 void TestEntryToIndex() {
352 Isolate* isolate(CcTest::InitIsolateOnce()); 355 Isolate* isolate(CcTest::InitIsolateOnce());
353 356
354 const int kNumParams = 1; 357 const int kNumParams = 1;
355 CodeStubAssemblerTester m(isolate, kNumParams); 358 CodeAssemblerTester data(isolate, kNumParams);
359 CodeStubAssembler m(data.state());
356 { 360 {
357 Node* entry = m.SmiUntag(m.Parameter(0)); 361 Node* entry = m.SmiUntag(m.Parameter(0));
358 Node* result = m.EntryToIndex<Dictionary>(entry); 362 Node* result = m.EntryToIndex<Dictionary>(entry);
359 m.Return(m.SmiTag(result)); 363 m.Return(m.SmiTag(result));
360 } 364 }
361 365
362 Handle<Code> code = m.GenerateCode(); 366 Handle<Code> code = data.GenerateCode();
363 FunctionTester ft(code, kNumParams); 367 FunctionTester ft(code, kNumParams);
364 368
365 // Test a wide range of entries but staying linear in the first 100 entries. 369 // Test a wide range of entries but staying linear in the first 100 entries.
366 for (int entry = 0; entry < Dictionary::kMaxCapacity; 370 for (int entry = 0; entry < Dictionary::kMaxCapacity;
367 entry = entry * 1.01 + 1) { 371 entry = entry * 1.01 + 1) {
368 Handle<Object> result = 372 Handle<Object> result =
369 ft.Call(handle(Smi::FromInt(entry), isolate)).ToHandleChecked(); 373 ft.Call(handle(Smi::FromInt(entry), isolate)).ToHandleChecked();
370 CHECK_EQ(Dictionary::EntryToIndex(entry), Smi::cast(*result)->value()); 374 CHECK_EQ(Dictionary::EntryToIndex(entry), Smi::cast(*result)->value());
371 } 375 }
372 } 376 }
373 377
374 TEST(NameDictionaryEntryToIndex) { TestEntryToIndex<NameDictionary>(); } 378 TEST(NameDictionaryEntryToIndex) { TestEntryToIndex<NameDictionary>(); }
375 TEST(GlobalDictionaryEntryToIndex) { TestEntryToIndex<GlobalDictionary>(); } 379 TEST(GlobalDictionaryEntryToIndex) { TestEntryToIndex<GlobalDictionary>(); }
376 380
377 } // namespace 381 } // namespace
378 382
379 namespace { 383 namespace {
380 384
381 template <typename Dictionary> 385 template <typename Dictionary>
382 void TestNameDictionaryLookup() { 386 void TestNameDictionaryLookup() {
383 typedef CodeStubAssembler::Label Label; 387 typedef CodeStubAssembler::Label Label;
384 typedef CodeStubAssembler::Variable Variable; 388 typedef CodeStubAssembler::Variable Variable;
385 Isolate* isolate(CcTest::InitIsolateOnce()); 389 Isolate* isolate(CcTest::InitIsolateOnce());
386 390
387 const int kNumParams = 4; 391 const int kNumParams = 4;
388 CodeStubAssemblerTester m(isolate, kNumParams); 392 CodeAssemblerTester data(isolate, kNumParams);
393 CodeStubAssembler m(data.state());
389 394
390 enum Result { kFound, kNotFound }; 395 enum Result { kFound, kNotFound };
391 { 396 {
392 Node* dictionary = m.Parameter(0); 397 Node* dictionary = m.Parameter(0);
393 Node* unique_name = m.Parameter(1); 398 Node* unique_name = m.Parameter(1);
394 Node* expected_result = m.Parameter(2); 399 Node* expected_result = m.Parameter(2);
395 Node* expected_arg = m.Parameter(3); 400 Node* expected_arg = m.Parameter(3);
396 401
397 Label passed(&m), failed(&m); 402 Label passed(&m), failed(&m);
398 Label if_found(&m), if_not_found(&m); 403 Label if_found(&m), if_not_found(&m);
(...skipping 13 matching lines...) Expand all
412 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))), 417 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
413 &passed, &failed); 418 &passed, &failed);
414 419
415 m.Bind(&passed); 420 m.Bind(&passed);
416 m.Return(m.BooleanConstant(true)); 421 m.Return(m.BooleanConstant(true));
417 422
418 m.Bind(&failed); 423 m.Bind(&failed);
419 m.Return(m.BooleanConstant(false)); 424 m.Return(m.BooleanConstant(false));
420 } 425 }
421 426
422 Handle<Code> code = m.GenerateCode(); 427 Handle<Code> code = data.GenerateCode();
423 FunctionTester ft(code, kNumParams); 428 FunctionTester ft(code, kNumParams);
424 429
425 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 430 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
426 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); 431 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
427 432
428 Handle<Dictionary> dictionary = Dictionary::New(isolate, 40); 433 Handle<Dictionary> dictionary = Dictionary::New(isolate, 40);
429 PropertyDetails fake_details = PropertyDetails::Empty(); 434 PropertyDetails fake_details = PropertyDetails::Empty();
430 435
431 Factory* factory = isolate->factory(); 436 Factory* factory = isolate->factory();
432 Handle<Name> keys[] = { 437 Handle<Name> keys[] = {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 489
485 namespace { 490 namespace {
486 491
487 template <typename Dictionary> 492 template <typename Dictionary>
488 void TestNumberDictionaryLookup() { 493 void TestNumberDictionaryLookup() {
489 typedef CodeStubAssembler::Label Label; 494 typedef CodeStubAssembler::Label Label;
490 typedef CodeStubAssembler::Variable Variable; 495 typedef CodeStubAssembler::Variable Variable;
491 Isolate* isolate(CcTest::InitIsolateOnce()); 496 Isolate* isolate(CcTest::InitIsolateOnce());
492 497
493 const int kNumParams = 4; 498 const int kNumParams = 4;
494 CodeStubAssemblerTester m(isolate, kNumParams); 499 CodeAssemblerTester data(isolate, kNumParams);
500 CodeStubAssembler m(data.state());
495 501
496 enum Result { kFound, kNotFound }; 502 enum Result { kFound, kNotFound };
497 { 503 {
498 Node* dictionary = m.Parameter(0); 504 Node* dictionary = m.Parameter(0);
499 Node* key = m.SmiToWord32(m.Parameter(1)); 505 Node* key = m.SmiToWord32(m.Parameter(1));
500 Node* expected_result = m.Parameter(2); 506 Node* expected_result = m.Parameter(2);
501 Node* expected_arg = m.Parameter(3); 507 Node* expected_arg = m.Parameter(3);
502 508
503 Label passed(&m), failed(&m); 509 Label passed(&m), failed(&m);
504 Label if_found(&m), if_not_found(&m); 510 Label if_found(&m), if_not_found(&m);
(...skipping 13 matching lines...) Expand all
518 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))), 524 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
519 &passed, &failed); 525 &passed, &failed);
520 526
521 m.Bind(&passed); 527 m.Bind(&passed);
522 m.Return(m.BooleanConstant(true)); 528 m.Return(m.BooleanConstant(true));
523 529
524 m.Bind(&failed); 530 m.Bind(&failed);
525 m.Return(m.BooleanConstant(false)); 531 m.Return(m.BooleanConstant(false));
526 } 532 }
527 533
528 Handle<Code> code = m.GenerateCode(); 534 Handle<Code> code = data.GenerateCode();
529 FunctionTester ft(code, kNumParams); 535 FunctionTester ft(code, kNumParams);
530 536
531 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 537 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
532 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); 538 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
533 539
534 const int kKeysCount = 1000; 540 const int kKeysCount = 1000;
535 Handle<Dictionary> dictionary = Dictionary::New(isolate, kKeysCount); 541 Handle<Dictionary> dictionary = Dictionary::New(isolate, kKeysCount);
536 uint32_t keys[kKeysCount]; 542 uint32_t keys[kKeysCount];
537 543
538 Handle<Object> fake_value(Smi::FromInt(42), isolate); 544 Handle<Object> fake_value(Smi::FromInt(42), isolate);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 627 }
622 } 628 }
623 629
624 } // namespace 630 } // namespace
625 631
626 TEST(TryHasOwnProperty) { 632 TEST(TryHasOwnProperty) {
627 typedef CodeStubAssembler::Label Label; 633 typedef CodeStubAssembler::Label Label;
628 Isolate* isolate(CcTest::InitIsolateOnce()); 634 Isolate* isolate(CcTest::InitIsolateOnce());
629 635
630 const int kNumParams = 4; 636 const int kNumParams = 4;
631 CodeStubAssemblerTester m(isolate, kNumParams); 637 CodeAssemblerTester data(isolate, kNumParams);
638 CodeStubAssembler m(data.state());
632 639
633 enum Result { kFound, kNotFound, kBailout }; 640 enum Result { kFound, kNotFound, kBailout };
634 { 641 {
635 Node* object = m.Parameter(0); 642 Node* object = m.Parameter(0);
636 Node* unique_name = m.Parameter(1); 643 Node* unique_name = m.Parameter(1);
637 Node* expected_result = m.Parameter(2); 644 Node* expected_result = m.Parameter(2);
638 645
639 Label passed(&m), failed(&m); 646 Label passed(&m), failed(&m);
640 Label if_found(&m), if_not_found(&m), if_bailout(&m); 647 Label if_found(&m), if_not_found(&m), if_bailout(&m);
641 648
(...skipping 17 matching lines...) Expand all
659 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 666 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
660 &passed, &failed); 667 &passed, &failed);
661 668
662 m.Bind(&passed); 669 m.Bind(&passed);
663 m.Return(m.BooleanConstant(true)); 670 m.Return(m.BooleanConstant(true));
664 671
665 m.Bind(&failed); 672 m.Bind(&failed);
666 m.Return(m.BooleanConstant(false)); 673 m.Return(m.BooleanConstant(false));
667 } 674 }
668 675
669 Handle<Code> code = m.GenerateCode(); 676 Handle<Code> code = data.GenerateCode();
670 FunctionTester ft(code, kNumParams); 677 FunctionTester ft(code, kNumParams);
671 678
672 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 679 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
673 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate); 680 Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
674 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate); 681 Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate);
675 682
676 Factory* factory = isolate->factory(); 683 Factory* factory = isolate->factory();
677 684
678 Handle<Name> deleted_property_name = 685 Handle<Name> deleted_property_name =
679 factory->InternalizeUtf8String("deleted"); 686 factory->InternalizeUtf8String("deleted");
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 } 814 }
808 } 815 }
809 816
810 TEST(TryGetOwnProperty) { 817 TEST(TryGetOwnProperty) {
811 typedef CodeStubAssembler::Label Label; 818 typedef CodeStubAssembler::Label Label;
812 typedef CodeStubAssembler::Variable Variable; 819 typedef CodeStubAssembler::Variable Variable;
813 Isolate* isolate(CcTest::InitIsolateOnce()); 820 Isolate* isolate(CcTest::InitIsolateOnce());
814 Factory* factory = isolate->factory(); 821 Factory* factory = isolate->factory();
815 822
816 const int kNumParams = 2; 823 const int kNumParams = 2;
817 CodeStubAssemblerTester m(isolate, kNumParams); 824 CodeAssemblerTester data(isolate, kNumParams);
825 CodeStubAssembler m(data.state());
818 826
819 Handle<Symbol> not_found_symbol = factory->NewSymbol(); 827 Handle<Symbol> not_found_symbol = factory->NewSymbol();
820 Handle<Symbol> bailout_symbol = factory->NewSymbol(); 828 Handle<Symbol> bailout_symbol = factory->NewSymbol();
821 { 829 {
822 Node* object = m.Parameter(0); 830 Node* object = m.Parameter(0);
823 Node* unique_name = m.Parameter(1); 831 Node* unique_name = m.Parameter(1);
824 Node* context = m.Parameter(kNumParams + 2); 832 Node* context = m.Parameter(kNumParams + 2);
825 833
826 Variable var_value(&m, MachineRepresentation::kTagged); 834 Variable var_value(&m, MachineRepresentation::kTagged);
827 Label if_found(&m), if_not_found(&m), if_bailout(&m); 835 Label if_found(&m), if_not_found(&m), if_bailout(&m);
828 836
829 Node* map = m.LoadMap(object); 837 Node* map = m.LoadMap(object);
830 Node* instance_type = m.LoadMapInstanceType(map); 838 Node* instance_type = m.LoadMapInstanceType(map);
831 839
832 m.TryGetOwnProperty(context, object, object, map, instance_type, 840 m.TryGetOwnProperty(context, object, object, map, instance_type,
833 unique_name, &if_found, &var_value, &if_not_found, 841 unique_name, &if_found, &var_value, &if_not_found,
834 &if_bailout); 842 &if_bailout);
835 843
836 m.Bind(&if_found); 844 m.Bind(&if_found);
837 m.Return(var_value.value()); 845 m.Return(var_value.value());
838 846
839 m.Bind(&if_not_found); 847 m.Bind(&if_not_found);
840 m.Return(m.HeapConstant(not_found_symbol)); 848 m.Return(m.HeapConstant(not_found_symbol));
841 849
842 m.Bind(&if_bailout); 850 m.Bind(&if_bailout);
843 m.Return(m.HeapConstant(bailout_symbol)); 851 m.Return(m.HeapConstant(bailout_symbol));
844 } 852 }
845 853
846 Handle<Code> code = m.GenerateCode(); 854 Handle<Code> code = data.GenerateCode();
847 FunctionTester ft(code, kNumParams); 855 FunctionTester ft(code, kNumParams);
848 856
849 Handle<Name> deleted_property_name = 857 Handle<Name> deleted_property_name =
850 factory->InternalizeUtf8String("deleted"); 858 factory->InternalizeUtf8String("deleted");
851 859
852 Handle<Name> names[] = { 860 Handle<Name> names[] = {
853 factory->InternalizeUtf8String("bb"), 861 factory->InternalizeUtf8String("bb"),
854 factory->NewSymbol(), 862 factory->NewSymbol(),
855 factory->InternalizeUtf8String("a"), 863 factory->InternalizeUtf8String("a"),
856 factory->InternalizeUtf8String("ccc"), 864 factory->InternalizeUtf8String("ccc"),
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked(); 1031 JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked();
1024 } 1032 }
1025 1033
1026 } // namespace 1034 } // namespace
1027 1035
1028 TEST(TryLookupElement) { 1036 TEST(TryLookupElement) {
1029 typedef CodeStubAssembler::Label Label; 1037 typedef CodeStubAssembler::Label Label;
1030 Isolate* isolate(CcTest::InitIsolateOnce()); 1038 Isolate* isolate(CcTest::InitIsolateOnce());
1031 1039
1032 const int kNumParams = 3; 1040 const int kNumParams = 3;
1033 CodeStubAssemblerTester m(isolate, kNumParams); 1041 CodeAssemblerTester data(isolate, kNumParams);
1042 CodeStubAssembler m(data.state());
1034 1043
1035 enum Result { kFound, kNotFound, kBailout }; 1044 enum Result { kFound, kNotFound, kBailout };
1036 { 1045 {
1037 Node* object = m.Parameter(0); 1046 Node* object = m.Parameter(0);
1038 Node* index = m.SmiToWord32(m.Parameter(1)); 1047 Node* index = m.SmiToWord32(m.Parameter(1));
1039 Node* expected_result = m.Parameter(2); 1048 Node* expected_result = m.Parameter(2);
1040 1049
1041 Label passed(&m), failed(&m); 1050 Label passed(&m), failed(&m);
1042 Label if_found(&m), if_not_found(&m), if_bailout(&m); 1051 Label if_found(&m), if_not_found(&m), if_bailout(&m);
1043 1052
(...skipping 17 matching lines...) Expand all
1061 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 1070 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
1062 &passed, &failed); 1071 &passed, &failed);
1063 1072
1064 m.Bind(&passed); 1073 m.Bind(&passed);
1065 m.Return(m.BooleanConstant(true)); 1074 m.Return(m.BooleanConstant(true));
1066 1075
1067 m.Bind(&failed); 1076 m.Bind(&failed);
1068 m.Return(m.BooleanConstant(false)); 1077 m.Return(m.BooleanConstant(false));
1069 } 1078 }
1070 1079
1071 Handle<Code> code = m.GenerateCode(); 1080 Handle<Code> code = data.GenerateCode();
1072 FunctionTester ft(code, kNumParams); 1081 FunctionTester ft(code, kNumParams);
1073 1082
1074 Factory* factory = isolate->factory(); 1083 Factory* factory = isolate->factory();
1075 Handle<Object> smi0(Smi::kZero, isolate); 1084 Handle<Object> smi0(Smi::kZero, isolate);
1076 Handle<Object> smi1(Smi::FromInt(1), isolate); 1085 Handle<Object> smi1(Smi::FromInt(1), isolate);
1077 Handle<Object> smi7(Smi::FromInt(7), isolate); 1086 Handle<Object> smi7(Smi::FromInt(7), isolate);
1078 Handle<Object> smi13(Smi::FromInt(13), isolate); 1087 Handle<Object> smi13(Smi::FromInt(13), isolate);
1079 Handle<Object> smi42(Smi::FromInt(42), isolate); 1088 Handle<Object> smi42(Smi::FromInt(42), isolate);
1080 1089
1081 Handle<Object> expect_found(Smi::FromInt(kFound), isolate); 1090 Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type()); 1218 CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type());
1210 ft.CheckTrue(object, smi0, expect_bailout); 1219 ft.CheckTrue(object, smi0, expect_bailout);
1211 } 1220 }
1212 } 1221 }
1213 1222
1214 TEST(DeferredCodePhiHints) { 1223 TEST(DeferredCodePhiHints) {
1215 typedef compiler::Node Node; 1224 typedef compiler::Node Node;
1216 typedef CodeStubAssembler::Label Label; 1225 typedef CodeStubAssembler::Label Label;
1217 typedef CodeStubAssembler::Variable Variable; 1226 typedef CodeStubAssembler::Variable Variable;
1218 Isolate* isolate(CcTest::InitIsolateOnce()); 1227 Isolate* isolate(CcTest::InitIsolateOnce());
1219 VoidDescriptor descriptor(isolate); 1228 CodeAssemblerTester data(isolate);
1220 CodeStubAssemblerTester m(isolate, descriptor); 1229 CodeStubAssembler m(data.state());
1221 Label block1(&m, Label::kDeferred); 1230 Label block1(&m, Label::kDeferred);
1222 m.Goto(&block1); 1231 m.Goto(&block1);
1223 m.Bind(&block1); 1232 m.Bind(&block1);
1224 { 1233 {
1225 Variable var_object(&m, MachineRepresentation::kTagged); 1234 Variable var_object(&m, MachineRepresentation::kTagged);
1226 Label loop(&m, &var_object); 1235 Label loop(&m, &var_object);
1227 var_object.Bind(m.IntPtrConstant(0)); 1236 var_object.Bind(m.IntPtrConstant(0));
1228 m.Goto(&loop); 1237 m.Goto(&loop);
1229 m.Bind(&loop); 1238 m.Bind(&loop);
1230 { 1239 {
1231 Node* map = m.LoadMap(var_object.value()); 1240 Node* map = m.LoadMap(var_object.value());
1232 var_object.Bind(map); 1241 var_object.Bind(map);
1233 m.Goto(&loop); 1242 m.Goto(&loop);
1234 } 1243 }
1235 } 1244 }
1236 CHECK(!m.GenerateCode().is_null()); 1245 CHECK(!data.GenerateCode().is_null());
1237 } 1246 }
1238 1247
1239 TEST(TestOutOfScopeVariable) { 1248 TEST(TestOutOfScopeVariable) {
1240 typedef CodeStubAssembler::Label Label; 1249 typedef CodeStubAssembler::Label Label;
1241 typedef CodeStubAssembler::Variable Variable; 1250 typedef CodeStubAssembler::Variable Variable;
1242 Isolate* isolate(CcTest::InitIsolateOnce()); 1251 Isolate* isolate(CcTest::InitIsolateOnce());
1243 VoidDescriptor descriptor(isolate); 1252 CodeAssemblerTester data(isolate);
1244 CodeStubAssemblerTester m(isolate, descriptor); 1253 CodeStubAssembler m(data.state());
1245 Label block1(&m); 1254 Label block1(&m);
1246 Label block2(&m); 1255 Label block2(&m);
1247 Label block3(&m); 1256 Label block3(&m);
1248 Label block4(&m); 1257 Label block4(&m);
1249 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block1, &block4); 1258 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block1, &block4);
1250 m.Bind(&block4); 1259 m.Bind(&block4);
1251 { 1260 {
1252 Variable var_object(&m, MachineRepresentation::kTagged); 1261 Variable var_object(&m, MachineRepresentation::kTagged);
1253 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block2, 1262 m.Branch(m.WordEqual(m.Parameter(0), m.IntPtrConstant(0)), &block2,
1254 &block3); 1263 &block3);
1255 1264
1256 m.Bind(&block2); 1265 m.Bind(&block2);
1257 var_object.Bind(m.IntPtrConstant(55)); 1266 var_object.Bind(m.IntPtrConstant(55));
1258 m.Goto(&block1); 1267 m.Goto(&block1);
1259 1268
1260 m.Bind(&block3); 1269 m.Bind(&block3);
1261 var_object.Bind(m.IntPtrConstant(66)); 1270 var_object.Bind(m.IntPtrConstant(66));
1262 m.Goto(&block1); 1271 m.Goto(&block1);
1263 } 1272 }
1264 m.Bind(&block1); 1273 m.Bind(&block1);
1265 CHECK(!m.GenerateCode().is_null()); 1274 CHECK(!data.GenerateCode().is_null());
1266 } 1275 }
1267 1276
1268 namespace { 1277 namespace {
1269 1278
1270 void TestStubCacheOffsetCalculation(StubCache::Table table) { 1279 void TestStubCacheOffsetCalculation(StubCache::Table table) {
1271 Isolate* isolate(CcTest::InitIsolateOnce()); 1280 Isolate* isolate(CcTest::InitIsolateOnce());
1272 const int kNumParams = 2; 1281 const int kNumParams = 2;
1273 CodeStubAssemblerTester m(isolate, kNumParams); 1282 CodeAssemblerTester data(isolate, kNumParams);
1283 CodeStubAssembler m(data.state());
1274 1284
1275 { 1285 {
1276 Node* name = m.Parameter(0); 1286 Node* name = m.Parameter(0);
1277 Node* map = m.Parameter(1); 1287 Node* map = m.Parameter(1);
1278 Node* primary_offset = m.StubCachePrimaryOffset(name, map); 1288 Node* primary_offset = m.StubCachePrimaryOffset(name, map);
1279 Node* result; 1289 Node* result;
1280 if (table == StubCache::kPrimary) { 1290 if (table == StubCache::kPrimary) {
1281 result = primary_offset; 1291 result = primary_offset;
1282 } else { 1292 } else {
1283 CHECK_EQ(StubCache::kSecondary, table); 1293 CHECK_EQ(StubCache::kSecondary, table);
1284 result = m.StubCacheSecondaryOffset(name, primary_offset); 1294 result = m.StubCacheSecondaryOffset(name, primary_offset);
1285 } 1295 }
1286 m.Return(m.SmiFromWord32(result)); 1296 m.Return(m.SmiFromWord32(result));
1287 } 1297 }
1288 1298
1289 Handle<Code> code = m.GenerateCode(); 1299 Handle<Code> code = data.GenerateCode();
1290 FunctionTester ft(code, kNumParams); 1300 FunctionTester ft(code, kNumParams);
1291 1301
1292 Factory* factory = isolate->factory(); 1302 Factory* factory = isolate->factory();
1293 Handle<Name> names[] = { 1303 Handle<Name> names[] = {
1294 factory->NewSymbol(), 1304 factory->NewSymbol(),
1295 factory->InternalizeUtf8String("a"), 1305 factory->InternalizeUtf8String("a"),
1296 factory->InternalizeUtf8String("bb"), 1306 factory->InternalizeUtf8String("bb"),
1297 factory->InternalizeUtf8String("ccc"), 1307 factory->InternalizeUtf8String("ccc"),
1298 factory->NewPrivateSymbol(), 1308 factory->NewPrivateSymbol(),
1299 factory->InternalizeUtf8String("dddd"), 1309 factory->InternalizeUtf8String("dddd"),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 } 1357 }
1348 1358
1349 TEST(StubCacheSecondaryOffset) { 1359 TEST(StubCacheSecondaryOffset) {
1350 TestStubCacheOffsetCalculation(StubCache::kSecondary); 1360 TestStubCacheOffsetCalculation(StubCache::kSecondary);
1351 } 1361 }
1352 1362
1353 namespace { 1363 namespace {
1354 1364
1355 Handle<Code> CreateCodeWithFlags(Code::Flags flags) { 1365 Handle<Code> CreateCodeWithFlags(Code::Flags flags) {
1356 Isolate* isolate(CcTest::InitIsolateOnce()); 1366 Isolate* isolate(CcTest::InitIsolateOnce());
1357 CodeStubAssemblerTester m(isolate, flags); 1367 CodeAssemblerTester data(isolate, flags);
1368 CodeStubAssembler m(data.state());
1358 m.Return(m.UndefinedConstant()); 1369 m.Return(m.UndefinedConstant());
1359 return m.GenerateCodeCloseAndEscape(); 1370 return data.GenerateCodeCloseAndEscape();
1360 } 1371 }
1361 1372
1362 } // namespace 1373 } // namespace
1363 1374
1364 TEST(TryProbeStubCache) { 1375 TEST(TryProbeStubCache) {
1365 typedef CodeStubAssembler::Label Label; 1376 typedef CodeStubAssembler::Label Label;
1366 typedef CodeStubAssembler::Variable Variable; 1377 typedef CodeStubAssembler::Variable Variable;
1367 Isolate* isolate(CcTest::InitIsolateOnce()); 1378 Isolate* isolate(CcTest::InitIsolateOnce());
1368 const int kNumParams = 3; 1379 const int kNumParams = 3;
1369 CodeStubAssemblerTester m(isolate, kNumParams); 1380 CodeAssemblerTester data(isolate, kNumParams);
1381 CodeStubAssembler m(data.state());
1370 1382
1371 Code::Kind ic_kind = Code::LOAD_IC; 1383 Code::Kind ic_kind = Code::LOAD_IC;
1372 StubCache stub_cache(isolate, ic_kind); 1384 StubCache stub_cache(isolate, ic_kind);
1373 stub_cache.Clear(); 1385 stub_cache.Clear();
1374 1386
1375 { 1387 {
1376 Node* receiver = m.Parameter(0); 1388 Node* receiver = m.Parameter(0);
1377 Node* name = m.Parameter(1); 1389 Node* name = m.Parameter(1);
1378 Node* expected_handler = m.Parameter(2); 1390 Node* expected_handler = m.Parameter(2);
1379 1391
(...skipping 12 matching lines...) Expand all
1392 m.Branch(m.WordEqual(expected_handler, m.IntPtrConstant(0)), &passed, 1404 m.Branch(m.WordEqual(expected_handler, m.IntPtrConstant(0)), &passed,
1393 &failed); 1405 &failed);
1394 1406
1395 m.Bind(&passed); 1407 m.Bind(&passed);
1396 m.Return(m.BooleanConstant(true)); 1408 m.Return(m.BooleanConstant(true));
1397 1409
1398 m.Bind(&failed); 1410 m.Bind(&failed);
1399 m.Return(m.BooleanConstant(false)); 1411 m.Return(m.BooleanConstant(false));
1400 } 1412 }
1401 1413
1402 Handle<Code> code = m.GenerateCode(); 1414 Handle<Code> code = data.GenerateCode();
1403 FunctionTester ft(code, kNumParams); 1415 FunctionTester ft(code, kNumParams);
1404 1416
1405 std::vector<Handle<Name>> names; 1417 std::vector<Handle<Name>> names;
1406 std::vector<Handle<JSObject>> receivers; 1418 std::vector<Handle<JSObject>> receivers;
1407 std::vector<Handle<Code>> handlers; 1419 std::vector<Handle<Code>> handlers;
1408 1420
1409 base::RandomNumberGenerator rand_gen(FLAG_random_seed); 1421 base::RandomNumberGenerator rand_gen(FLAG_random_seed);
1410 1422
1411 Factory* factory = isolate->factory(); 1423 Factory* factory = isolate->factory();
1412 1424
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 // Ensure we performed both kind of queries. 1515 // Ensure we performed both kind of queries.
1504 CHECK(queried_existing && queried_non_existing); 1516 CHECK(queried_existing && queried_non_existing);
1505 } 1517 }
1506 1518
1507 TEST(GotoIfException) { 1519 TEST(GotoIfException) {
1508 typedef CodeStubAssembler::Label Label; 1520 typedef CodeStubAssembler::Label Label;
1509 typedef CodeStubAssembler::Variable Variable; 1521 typedef CodeStubAssembler::Variable Variable;
1510 Isolate* isolate(CcTest::InitIsolateOnce()); 1522 Isolate* isolate(CcTest::InitIsolateOnce());
1511 1523
1512 const int kNumParams = 1; 1524 const int kNumParams = 1;
1513 // Emulate TFJ builtin 1525 CodeAssemblerTester data(isolate, kNumParams);
1514 CodeStubAssemblerTester m(isolate, kNumParams, Code::BUILTIN); 1526 CodeStubAssembler m(data.state());
1515 1527
1516 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); 1528 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
1517 Node* to_string_tag = 1529 Node* to_string_tag =
1518 m.HeapConstant(isolate->factory()->to_string_tag_symbol()); 1530 m.HeapConstant(isolate->factory()->to_string_tag_symbol());
1519 Variable exception(&m, MachineRepresentation::kTagged); 1531 Variable exception(&m, MachineRepresentation::kTagged);
1520 1532
1521 Label exception_handler(&m); 1533 Label exception_handler(&m);
1522 Callable to_string = CodeFactory::ToString(isolate); 1534 Callable to_string = CodeFactory::ToString(isolate);
1523 Node* string = m.CallStub(to_string, context, to_string_tag); 1535 Node* string = m.CallStub(to_string, context, to_string_tag);
1524 m.GotoIfException(string, &exception_handler, &exception); 1536 m.GotoIfException(string, &exception_handler, &exception);
1525 m.Return(string); 1537 m.Return(string);
1526 1538
1527 m.Bind(&exception_handler); 1539 m.Bind(&exception_handler);
1528 m.Return(exception.value()); 1540 m.Return(exception.value());
1529 1541
1530 Handle<Code> code = m.GenerateCode(); 1542 Handle<Code> code = data.GenerateCode();
1531 CHECK(!code.is_null()); 1543 CHECK(!code.is_null());
1532 1544
1533 FunctionTester ft(code, kNumParams); 1545 FunctionTester ft(code, kNumParams);
1534 Handle<Object> result = ft.Call().ToHandleChecked(); 1546 Handle<Object> result = ft.Call().ToHandleChecked();
1535 1547
1536 // Should be a TypeError 1548 // Should be a TypeError.
1537 CHECK(result->IsJSObject()); 1549 CHECK(result->IsJSObject());
1538 1550
1539 Handle<Object> constructor = 1551 Handle<Object> constructor =
1540 Object::GetPropertyOrElement(result, 1552 Object::GetPropertyOrElement(result,
1541 isolate->factory()->constructor_string()) 1553 isolate->factory()->constructor_string())
1542 .ToHandleChecked(); 1554 .ToHandleChecked();
1543 CHECK(constructor->SameValue(*isolate->type_error_function())); 1555 CHECK(constructor->SameValue(*isolate->type_error_function()));
1544 } 1556 }
1545 1557
1546 TEST(GotoIfExceptionMultiple) { 1558 TEST(GotoIfExceptionMultiple) {
1547 typedef CodeStubAssembler::Label Label; 1559 typedef CodeStubAssembler::Label Label;
1548 typedef CodeStubAssembler::Variable Variable; 1560 typedef CodeStubAssembler::Variable Variable;
1549 Isolate* isolate(CcTest::InitIsolateOnce()); 1561 Isolate* isolate(CcTest::InitIsolateOnce());
1550 1562
1551 const int kNumParams = 4; // receiver, first, second, third 1563 const int kNumParams = 4; // receiver, first, second, third
1552 // Emulate TFJ builtin 1564 CodeAssemblerTester data(isolate, kNumParams);
1553 CodeStubAssemblerTester m(isolate, kNumParams, Code::BUILTIN); 1565 CodeStubAssembler m(data.state());
1554 1566
1555 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); 1567 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
1556 Node* first_value = m.Parameter(0); 1568 Node* first_value = m.Parameter(0);
1557 Node* second_value = m.Parameter(1); 1569 Node* second_value = m.Parameter(1);
1558 Node* third_value = m.Parameter(2); 1570 Node* third_value = m.Parameter(2);
1559 1571
1560 Label exception_handler1(&m); 1572 Label exception_handler1(&m);
1561 Label exception_handler2(&m); 1573 Label exception_handler2(&m);
1562 Label exception_handler3(&m); 1574 Label exception_handler3(&m);
1563 Variable return_value(&m, MachineRepresentation::kWord32); 1575 Variable return_value(&m, MachineRepresentation::kWord32);
(...skipping 21 matching lines...) Expand all
1585 error.Bind(m.UndefinedConstant()); 1597 error.Bind(m.UndefinedConstant());
1586 string = m.CallStub(to_string, context, third_value); 1598 string = m.CallStub(to_string, context, third_value);
1587 m.GotoIfException(string, &exception_handler3, &error); 1599 m.GotoIfException(string, &exception_handler3, &error);
1588 m.Return(m.SmiFromWord32( 1600 m.Return(m.SmiFromWord32(
1589 m.Word32And(return_value.value(), 1601 m.Word32And(return_value.value(),
1590 m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1))))); 1602 m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1)))));
1591 1603
1592 m.Bind(&exception_handler3); 1604 m.Bind(&exception_handler3);
1593 m.Return(error.value()); 1605 m.Return(error.value());
1594 1606
1595 Handle<Code> code = m.GenerateCode(); 1607 Handle<Code> code = data.GenerateCode();
1596 CHECK(!code.is_null()); 1608 CHECK(!code.is_null());
1597 1609
1598 FunctionTester ft(code, kNumParams); 1610 FunctionTester ft(code, kNumParams);
1599 1611
1600 Handle<Object> result; 1612 Handle<Object> result;
1601 // First handler does not throw, returns result of first value 1613 // First handler does not throw, returns result of first value.
1602 result = ft.Call(isolate->factory()->undefined_value(), 1614 result = ft.Call(isolate->factory()->undefined_value(),
1603 isolate->factory()->to_string_tag_symbol()) 1615 isolate->factory()->to_string_tag_symbol())
1604 .ToHandleChecked(); 1616 .ToHandleChecked();
1605 CHECK(String::cast(*result)->IsOneByteEqualTo(OneByteVector("undefined"))); 1617 CHECK(String::cast(*result)->IsOneByteEqualTo(OneByteVector("undefined")));
1606 1618
1607 // First handler returns a number 1619 // First handler returns a number.
1608 result = ft.Call(isolate->factory()->to_string_tag_symbol(), 1620 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1609 isolate->factory()->undefined_value()) 1621 isolate->factory()->undefined_value())
1610 .ToHandleChecked(); 1622 .ToHandleChecked();
1611 CHECK_EQ(7, Smi::cast(*result)->value()); 1623 CHECK_EQ(7, Smi::cast(*result)->value());
1612 1624
1613 // First handler throws, second handler returns a number 1625 // First handler throws, second handler returns a number.
1614 result = ft.Call(isolate->factory()->to_string_tag_symbol(), 1626 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1615 isolate->factory()->to_primitive_symbol()) 1627 isolate->factory()->to_primitive_symbol())
1616 .ToHandleChecked(); 1628 .ToHandleChecked();
1617 CHECK_EQ(7 & ~2, Smi::cast(*result)->value()); 1629 CHECK_EQ(7 & ~2, Smi::cast(*result)->value());
1618 1630
1619 // First handler throws, second handler throws, third handler returns thrown 1631 // First handler throws, second handler throws, third handler returns thrown
1620 // value. 1632 // value.
1621 result = ft.Call(isolate->factory()->to_string_tag_symbol(), 1633 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1622 isolate->factory()->to_primitive_symbol(), 1634 isolate->factory()->to_primitive_symbol(),
1623 isolate->factory()->unscopables_symbol()) 1635 isolate->factory()->unscopables_symbol())
1624 .ToHandleChecked(); 1636 .ToHandleChecked();
1625 1637
1626 // Should be a TypeError 1638 // Should be a TypeError.
1627 CHECK(result->IsJSObject()); 1639 CHECK(result->IsJSObject());
1628 1640
1629 Handle<Object> constructor = 1641 Handle<Object> constructor =
1630 Object::GetPropertyOrElement(result, 1642 Object::GetPropertyOrElement(result,
1631 isolate->factory()->constructor_string()) 1643 isolate->factory()->constructor_string())
1632 .ToHandleChecked(); 1644 .ToHandleChecked();
1633 CHECK(constructor->SameValue(*isolate->type_error_function())); 1645 CHECK(constructor->SameValue(*isolate->type_error_function()));
1634 } 1646 }
1635 1647
1636 TEST(AllocateJSObjectFromMap) { 1648 TEST(AllocateJSObjectFromMap) {
1637 Isolate* isolate(CcTest::InitIsolateOnce()); 1649 Isolate* isolate(CcTest::InitIsolateOnce());
1638 Factory* factory = isolate->factory(); 1650 Factory* factory = isolate->factory();
1639 1651
1640 const int kNumParams = 3; 1652 const int kNumParams = 3;
1641 CodeStubAssemblerTester m(isolate, kNumParams); 1653 CodeAssemblerTester data(isolate, kNumParams);
1654 CodeStubAssembler m(data.state());
1642 1655
1643 { 1656 {
1644 Node* map = m.Parameter(0); 1657 Node* map = m.Parameter(0);
1645 Node* properties = m.Parameter(1); 1658 Node* properties = m.Parameter(1);
1646 Node* elements = m.Parameter(2); 1659 Node* elements = m.Parameter(2);
1647 1660
1648 Node* result = m.AllocateJSObjectFromMap(map, properties, elements); 1661 Node* result = m.AllocateJSObjectFromMap(map, properties, elements);
1649 1662
1650 m.Return(result); 1663 m.Return(result);
1651 } 1664 }
1652 1665
1653 Handle<Code> code = m.GenerateCode(); 1666 Handle<Code> code = data.GenerateCode();
1654 FunctionTester ft(code, kNumParams); 1667 FunctionTester ft(code, kNumParams);
1655 1668
1656 Handle<Map> maps[] = { 1669 Handle<Map> maps[] = {
1657 handle(isolate->object_function()->initial_map(), isolate), 1670 handle(isolate->object_function()->initial_map(), isolate),
1658 handle(isolate->array_function()->initial_map(), isolate), 1671 handle(isolate->array_function()->initial_map(), isolate),
1659 }; 1672 };
1660 1673
1661 #define VERIFY(result, map_value, properties_value, elements_value) \ 1674 #define VERIFY(result, map_value, properties_value, elements_value) \
1662 CHECK_EQ(result->map(), map_value); \ 1675 CHECK_EQ(result->map(), map_value); \
1663 CHECK_EQ(result->properties(), properties_value); \ 1676 CHECK_EQ(result->properties(), properties_value); \
(...skipping 30 matching lines...) Expand all
1694 isolate->heap()->Verify(); 1707 isolate->heap()->Verify();
1695 #endif 1708 #endif
1696 } 1709 }
1697 #undef VERIFY 1710 #undef VERIFY
1698 } 1711 }
1699 1712
1700 TEST(AllocateNameDictionary) { 1713 TEST(AllocateNameDictionary) {
1701 Isolate* isolate(CcTest::InitIsolateOnce()); 1714 Isolate* isolate(CcTest::InitIsolateOnce());
1702 1715
1703 const int kNumParams = 1; 1716 const int kNumParams = 1;
1704 CodeStubAssemblerTester m(isolate, kNumParams); 1717 CodeAssemblerTester data(isolate, kNumParams);
1718 CodeStubAssembler m(data.state());
1705 1719
1706 { 1720 {
1707 Node* capacity = m.Parameter(0); 1721 Node* capacity = m.Parameter(0);
1708 Node* result = m.AllocateNameDictionary(m.SmiUntag(capacity)); 1722 Node* result = m.AllocateNameDictionary(m.SmiUntag(capacity));
1709 m.Return(result); 1723 m.Return(result);
1710 } 1724 }
1711 1725
1712 Handle<Code> code = m.GenerateCode(); 1726 Handle<Code> code = data.GenerateCode();
1713 FunctionTester ft(code, kNumParams); 1727 FunctionTester ft(code, kNumParams);
1714 1728
1715 { 1729 {
1716 for (int i = 0; i < 256; i = i * 1.1 + 1) { 1730 for (int i = 0; i < 256; i = i * 1.1 + 1) {
1717 Handle<Object> result = 1731 Handle<Object> result =
1718 ft.Call(handle(Smi::FromInt(i), isolate)).ToHandleChecked(); 1732 ft.Call(handle(Smi::FromInt(i), isolate)).ToHandleChecked();
1719 Handle<NameDictionary> dict = NameDictionary::New(isolate, i); 1733 Handle<NameDictionary> dict = NameDictionary::New(isolate, i);
1720 // Both dictionaries should be memory equal. 1734 // Both dictionaries should be memory equal.
1721 int size = 1735 int size =
1722 FixedArrayBase::kHeaderSize + (dict->length() - 1) * kPointerSize; 1736 FixedArrayBase::kHeaderSize + (dict->length() - 1) * kPointerSize;
1723 CHECK_EQ(0, memcmp(*dict, *result, size)); 1737 CHECK_EQ(0, memcmp(*dict, *result, size));
1724 } 1738 }
1725 } 1739 }
1726 } 1740 }
1727 1741
1728 TEST(PopAndReturnConstant) { 1742 TEST(PopAndReturnConstant) {
1729 Isolate* isolate(CcTest::InitIsolateOnce()); 1743 Isolate* isolate(CcTest::InitIsolateOnce());
1730 1744
1731 const int kNumParams = 4; 1745 const int kNumParams = 4;
1732 const int kNumProgramaticParams = 2; 1746 const int kNumProgrammaticParams = 2;
1733 CodeStubAssemblerTester m(isolate, kNumParams - kNumProgramaticParams); 1747 CodeAssemblerTester data(isolate, kNumParams - kNumProgrammaticParams);
1748 CodeStubAssembler m(data.state());
1734 1749
1735 // Call a function that return |kNumProgramaticParams| parameters in addition 1750 // Call a function that return |kNumProgramaticParams| parameters in addition
1736 // to those specified by the static descriptor. |kNumProgramaticParams| is 1751 // to those specified by the static descriptor. |kNumProgramaticParams| is
1737 // specified as a constant. 1752 // specified as a constant.
1738 m.PopAndReturn(m.Int32Constant(kNumProgramaticParams), 1753 m.PopAndReturn(m.Int32Constant(kNumProgrammaticParams),
1739 m.SmiConstant(Smi::FromInt(1234))); 1754 m.SmiConstant(Smi::FromInt(1234)));
1740 1755
1741 Handle<Code> code = m.GenerateCode(); 1756 Handle<Code> code = data.GenerateCode();
1742 CHECK(!code.is_null()); 1757 CHECK(!code.is_null());
1743 1758
1744 FunctionTester ft(code, kNumParams); 1759 FunctionTester ft(code, kNumParams);
1745 Handle<Object> result; 1760 Handle<Object> result;
1746 for (int test_count = 0; test_count < 100; ++test_count) { 1761 for (int test_count = 0; test_count < 100; ++test_count) {
1747 result = ft.Call(isolate->factory()->undefined_value(), 1762 result = ft.Call(isolate->factory()->undefined_value(),
1748 Handle<Smi>(Smi::FromInt(1234), isolate), 1763 Handle<Smi>(Smi::FromInt(1234), isolate),
1749 isolate->factory()->undefined_value(), 1764 isolate->factory()->undefined_value(),
1750 isolate->factory()->undefined_value()) 1765 isolate->factory()->undefined_value())
1751 .ToHandleChecked(); 1766 .ToHandleChecked();
1752 CHECK_EQ(1234, Handle<Smi>::cast(result)->value()); 1767 CHECK_EQ(1234, Handle<Smi>::cast(result)->value());
1753 } 1768 }
1754 } 1769 }
1755 1770
1756 TEST(PopAndReturnVariable) { 1771 TEST(PopAndReturnVariable) {
1757 Isolate* isolate(CcTest::InitIsolateOnce()); 1772 Isolate* isolate(CcTest::InitIsolateOnce());
1758 1773
1759 const int kNumParams = 4; 1774 const int kNumParams = 4;
1760 const int kNumProgramaticParams = 2; 1775 const int kNumProgrammaticParams = 2;
1761 CodeStubAssemblerTester m(isolate, kNumParams - kNumProgramaticParams); 1776 CodeAssemblerTester data(isolate, kNumParams - kNumProgrammaticParams);
1777 CodeStubAssembler m(data.state());
1762 1778
1763 // Call a function that return |kNumProgramaticParams| parameters in addition 1779 // Call a function that return |kNumProgramaticParams| parameters in addition
1764 // to those specified by the static descriptor. |kNumProgramaticParams| is 1780 // to those specified by the static descriptor. |kNumProgramaticParams| is
1765 // passed in as a parameter to the function so that it can't be recongized as 1781 // passed in as a parameter to the function so that it can't be recongized as
1766 // a constant. 1782 // a constant.
1767 m.PopAndReturn(m.SmiUntag(m.Parameter(1)), m.SmiConstant(Smi::FromInt(1234))); 1783 m.PopAndReturn(m.SmiUntag(m.Parameter(1)), m.SmiConstant(Smi::FromInt(1234)));
1768 1784
1769 Handle<Code> code = m.GenerateCode(); 1785 Handle<Code> code = data.GenerateCode();
1770 CHECK(!code.is_null()); 1786 CHECK(!code.is_null());
1771 1787
1772 FunctionTester ft(code, kNumParams); 1788 FunctionTester ft(code, kNumParams);
1773 Handle<Object> result; 1789 Handle<Object> result;
1774 for (int test_count = 0; test_count < 100; ++test_count) { 1790 for (int test_count = 0; test_count < 100; ++test_count) {
1775 result = ft.Call(isolate->factory()->undefined_value(), 1791 result = ft.Call(isolate->factory()->undefined_value(),
1776 Handle<Smi>(Smi::FromInt(1234), isolate), 1792 Handle<Smi>(Smi::FromInt(1234), isolate),
1777 isolate->factory()->undefined_value(), 1793 isolate->factory()->undefined_value(),
1778 Handle<Smi>(Smi::FromInt(kNumProgramaticParams), isolate)) 1794 Handle<Smi>(Smi::FromInt(kNumProgrammaticParams), isolate))
1779 .ToHandleChecked(); 1795 .ToHandleChecked();
1780 CHECK_EQ(1234, Handle<Smi>::cast(result)->value()); 1796 CHECK_EQ(1234, Handle<Smi>::cast(result)->value());
1781 } 1797 }
1782 } 1798 }
1783 1799
1784 TEST(OneToTwoByteStringCopy) { 1800 TEST(OneToTwoByteStringCopy) {
1785 Isolate* isolate(CcTest::InitIsolateOnce()); 1801 Isolate* isolate(CcTest::InitIsolateOnce());
1786 1802
1787 CodeStubAssemblerTester m(isolate, 2); 1803 const int kNumParams = 2;
1804 CodeAssemblerTester data(isolate, kNumParams);
1805 CodeStubAssembler m(data.state());
1788 1806
1789 m.CopyStringCharacters( 1807 m.CopyStringCharacters(
1790 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1808 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1791 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)), 1809 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
1792 String::ONE_BYTE_ENCODING, String::TWO_BYTE_ENCODING, 1810 String::ONE_BYTE_ENCODING, String::TWO_BYTE_ENCODING,
1793 CodeStubAssembler::SMI_PARAMETERS); 1811 CodeStubAssembler::SMI_PARAMETERS);
1794 m.Return(m.SmiConstant(Smi::FromInt(0))); 1812 m.Return(m.SmiConstant(Smi::FromInt(0)));
1795 1813
1796 Handle<Code> code = m.GenerateCode(); 1814 Handle<Code> code = data.GenerateCode();
1797 CHECK(!code.is_null()); 1815 CHECK(!code.is_null());
1798 1816
1799 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde"); 1817 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
1800 uc16 array[] = {1000, 1001, 1002, 1003, 1004}; 1818 uc16 array[] = {1000, 1001, 1002, 1003, 1004};
1801 Vector<const uc16> str(array); 1819 Vector<const uc16> str(array);
1802 Handle<String> string2 = 1820 Handle<String> string2 =
1803 isolate->factory()->NewStringFromTwoByte(str).ToHandleChecked(); 1821 isolate->factory()->NewStringFromTwoByte(str).ToHandleChecked();
1804 FunctionTester ft(code, 2); 1822 FunctionTester ft(code, 2);
1805 ft.Call(string1, string2); 1823 ft.Call(string1, string2);
1806 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0], 1824 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
1807 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]); 1825 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
1808 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1], 1826 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
1809 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]); 1827 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
1810 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2], 1828 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
1811 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]); 1829 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
1812 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3], 1830 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
1813 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]); 1831 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
1814 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4], 1832 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
1815 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]); 1833 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
1816 } 1834 }
1817 1835
1818 TEST(OneToOneByteStringCopy) { 1836 TEST(OneToOneByteStringCopy) {
1819 Isolate* isolate(CcTest::InitIsolateOnce()); 1837 Isolate* isolate(CcTest::InitIsolateOnce());
1820 1838
1821 CodeStubAssemblerTester m(isolate, 2); 1839 const int kNumParams = 2;
1840 CodeAssemblerTester data(isolate, kNumParams);
1841 CodeStubAssembler m(data.state());
1822 1842
1823 m.CopyStringCharacters( 1843 m.CopyStringCharacters(
1824 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1844 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1825 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)), 1845 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
1826 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING, 1846 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING,
1827 CodeStubAssembler::SMI_PARAMETERS); 1847 CodeStubAssembler::SMI_PARAMETERS);
1828 m.Return(m.SmiConstant(Smi::FromInt(0))); 1848 m.Return(m.SmiConstant(Smi::FromInt(0)));
1829 1849
1830 Handle<Code> code = m.GenerateCode(); 1850 Handle<Code> code = data.GenerateCode();
1831 CHECK(!code.is_null()); 1851 CHECK(!code.is_null());
1832 1852
1833 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde"); 1853 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
1834 uint8_t array[] = {100, 101, 102, 103, 104}; 1854 uint8_t array[] = {100, 101, 102, 103, 104};
1835 Vector<const uint8_t> str(array); 1855 Vector<const uint8_t> str(array);
1836 Handle<String> string2 = 1856 Handle<String> string2 =
1837 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked(); 1857 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked();
1838 FunctionTester ft(code, 2); 1858 FunctionTester ft(code, 2);
1839 ft.Call(string1, string2); 1859 ft.Call(string1, string2);
1840 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0], 1860 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
1841 Handle<SeqOneByteString>::cast(string2)->GetChars()[0]); 1861 Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
1842 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1], 1862 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
1843 Handle<SeqOneByteString>::cast(string2)->GetChars()[1]); 1863 Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
1844 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2], 1864 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
1845 Handle<SeqOneByteString>::cast(string2)->GetChars()[2]); 1865 Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
1846 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3], 1866 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
1847 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]); 1867 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
1848 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4], 1868 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
1849 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]); 1869 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
1850 } 1870 }
1851 1871
1852 TEST(OneToOneByteStringCopyNonZeroStart) { 1872 TEST(OneToOneByteStringCopyNonZeroStart) {
1853 Isolate* isolate(CcTest::InitIsolateOnce()); 1873 Isolate* isolate(CcTest::InitIsolateOnce());
1854 1874
1855 CodeStubAssemblerTester m(isolate, 2); 1875 const int kNumParams = 2;
1876 CodeAssemblerTester data(isolate, kNumParams);
1877 CodeStubAssembler m(data.state());
1856 1878
1857 m.CopyStringCharacters( 1879 m.CopyStringCharacters(
1858 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1880 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1859 m.SmiConstant(Smi::FromInt(3)), m.SmiConstant(Smi::FromInt(2)), 1881 m.SmiConstant(Smi::FromInt(3)), m.SmiConstant(Smi::FromInt(2)),
1860 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING, 1882 String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING,
1861 CodeStubAssembler::SMI_PARAMETERS); 1883 CodeStubAssembler::SMI_PARAMETERS);
1862 m.Return(m.SmiConstant(Smi::FromInt(0))); 1884 m.Return(m.SmiConstant(Smi::FromInt(0)));
1863 1885
1864 Handle<Code> code = m.GenerateCode(); 1886 Handle<Code> code = data.GenerateCode();
1865 CHECK(!code.is_null()); 1887 CHECK(!code.is_null());
1866 1888
1867 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde"); 1889 Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
1868 uint8_t array[] = {100, 101, 102, 103, 104}; 1890 uint8_t array[] = {100, 101, 102, 103, 104};
1869 Vector<const uint8_t> str(array); 1891 Vector<const uint8_t> str(array);
1870 Handle<String> string2 = 1892 Handle<String> string2 =
1871 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked(); 1893 isolate->factory()->NewStringFromOneByte(str).ToHandleChecked();
1872 FunctionTester ft(code, 2); 1894 FunctionTester ft(code, 2);
1873 ft.Call(string1, string2); 1895 ft.Call(string1, string2);
1874 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0], 1896 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
1875 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]); 1897 Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
1876 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1], 1898 CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
1877 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]); 1899 Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
1878 CHECK_EQ(100, Handle<SeqOneByteString>::cast(string2)->GetChars()[0]); 1900 CHECK_EQ(100, Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
1879 CHECK_EQ(101, Handle<SeqOneByteString>::cast(string2)->GetChars()[1]); 1901 CHECK_EQ(101, Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
1880 CHECK_EQ(102, Handle<SeqOneByteString>::cast(string2)->GetChars()[2]); 1902 CHECK_EQ(102, Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
1881 } 1903 }
1882 1904
1883 TEST(TwoToTwoByteStringCopy) { 1905 TEST(TwoToTwoByteStringCopy) {
1884 Isolate* isolate(CcTest::InitIsolateOnce()); 1906 Isolate* isolate(CcTest::InitIsolateOnce());
1885 1907
1886 CodeStubAssemblerTester m(isolate, 2); 1908 const int kNumParams = 2;
1909 CodeAssemblerTester data(isolate, kNumParams);
1910 CodeStubAssembler m(data.state());
1887 1911
1888 m.CopyStringCharacters( 1912 m.CopyStringCharacters(
1889 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)), 1913 m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
1890 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)), 1914 m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
1891 String::TWO_BYTE_ENCODING, String::TWO_BYTE_ENCODING, 1915 String::TWO_BYTE_ENCODING, String::TWO_BYTE_ENCODING,
1892 CodeStubAssembler::SMI_PARAMETERS); 1916 CodeStubAssembler::SMI_PARAMETERS);
1893 m.Return(m.SmiConstant(Smi::FromInt(0))); 1917 m.Return(m.SmiConstant(Smi::FromInt(0)));
1894 1918
1895 Handle<Code> code = m.GenerateCode(); 1919 Handle<Code> code = data.GenerateCode();
1896 CHECK(!code.is_null()); 1920 CHECK(!code.is_null());
1897 1921
1898 uc16 array1[] = {2000, 2001, 2002, 2003, 2004}; 1922 uc16 array1[] = {2000, 2001, 2002, 2003, 2004};
1899 Vector<const uc16> str1(array1); 1923 Vector<const uc16> str1(array1);
1900 Handle<String> string1 = 1924 Handle<String> string1 =
1901 isolate->factory()->NewStringFromTwoByte(str1).ToHandleChecked(); 1925 isolate->factory()->NewStringFromTwoByte(str1).ToHandleChecked();
1902 uc16 array2[] = {1000, 1001, 1002, 1003, 1004}; 1926 uc16 array2[] = {1000, 1001, 1002, 1003, 1004};
1903 Vector<const uc16> str2(array2); 1927 Vector<const uc16> str2(array2);
1904 Handle<String> string2 = 1928 Handle<String> string2 =
1905 isolate->factory()->NewStringFromTwoByte(str2).ToHandleChecked(); 1929 isolate->factory()->NewStringFromTwoByte(str2).ToHandleChecked();
1906 FunctionTester ft(code, 2); 1930 FunctionTester ft(code, 2);
1907 ft.Call(string1, string2); 1931 ft.Call(string1, string2);
1908 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[0], 1932 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[0],
1909 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]); 1933 Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
1910 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1], 1934 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1],
1911 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]); 1935 Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
1912 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2], 1936 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2],
1913 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]); 1937 Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
1914 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3], 1938 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3],
1915 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]); 1939 Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
1916 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4], 1940 CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4],
1917 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]); 1941 Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
1918 } 1942 }
1919 1943
1920 TEST(Arguments) { 1944 TEST(Arguments) {
1921 Isolate* isolate(CcTest::InitIsolateOnce()); 1945 Isolate* isolate(CcTest::InitIsolateOnce());
1922 1946
1923 const int kNumParams = 4; 1947 const int kNumParams = 4;
1924 CodeStubAssemblerTester m(isolate, kNumParams); 1948 CodeAssemblerTester data(isolate, kNumParams);
1949 CodeStubAssembler m(data.state());
1925 1950
1926 CodeStubArguments arguments(&m, m.IntPtrConstant(3)); 1951 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1927 1952
1928 CSA_ASSERT( 1953 CSA_ASSERT(
1929 &m, m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12)))); 1954 &m, m.WordEqual(arguments.AtIndex(0), m.SmiConstant(Smi::FromInt(12))));
1930 CSA_ASSERT( 1955 CSA_ASSERT(
1931 &m, m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13)))); 1956 &m, m.WordEqual(arguments.AtIndex(1), m.SmiConstant(Smi::FromInt(13))));
1932 CSA_ASSERT( 1957 CSA_ASSERT(
1933 &m, m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14)))); 1958 &m, m.WordEqual(arguments.AtIndex(2), m.SmiConstant(Smi::FromInt(14))));
1934 1959
1935 m.Return(arguments.GetReceiver()); 1960 m.Return(arguments.GetReceiver());
1936 1961
1937 Handle<Code> code = m.GenerateCode(); 1962 Handle<Code> code = data.GenerateCode();
1938 CHECK(!code.is_null()); 1963 CHECK(!code.is_null());
1939 1964
1940 FunctionTester ft(code, kNumParams); 1965 FunctionTester ft(code, kNumParams);
1941 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), 1966 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1942 Handle<Smi>(Smi::FromInt(12), isolate), 1967 Handle<Smi>(Smi::FromInt(12), isolate),
1943 Handle<Smi>(Smi::FromInt(13), isolate), 1968 Handle<Smi>(Smi::FromInt(13), isolate),
1944 Handle<Smi>(Smi::FromInt(14), isolate)) 1969 Handle<Smi>(Smi::FromInt(14), isolate))
1945 .ToHandleChecked(); 1970 .ToHandleChecked();
1946 CHECK_EQ(*isolate->factory()->undefined_value(), *result); 1971 CHECK_EQ(*isolate->factory()->undefined_value(), *result);
1947 } 1972 }
1948 1973
1949 TEST(ArgumentsForEach) { 1974 TEST(ArgumentsForEach) {
1950 Isolate* isolate(CcTest::InitIsolateOnce()); 1975 Isolate* isolate(CcTest::InitIsolateOnce());
1951 1976
1952 const int kNumParams = 4; 1977 const int kNumParams = 4;
1953 CodeStubAssemblerTester m(isolate, kNumParams); 1978 CodeAssemblerTester data(isolate, kNumParams);
1979 CodeStubAssembler m(data.state());
1954 1980
1955 CodeStubArguments arguments(&m, m.IntPtrConstant(3)); 1981 CodeStubArguments arguments(&m, m.IntPtrConstant(3));
1956 1982
1957 CodeStubAssemblerTester::Variable sum(&m, 1983 CodeStubAssembler::Variable sum(&m, MachineType::PointerRepresentation());
1958 MachineType::PointerRepresentation()); 1984 CodeStubAssembler::VariableList list({&sum}, m.zone());
1959 CodeStubAssemblerTester::VariableList list({&sum}, m.zone());
1960 1985
1961 sum.Bind(m.IntPtrConstant(0)); 1986 sum.Bind(m.IntPtrConstant(0));
1962 1987
1963 arguments.ForEach(list, [&m, &sum](CodeStubAssembler* assembler, Node* arg) { 1988 arguments.ForEach(list, [&m, &sum](CodeStubAssembler* assembler, Node* arg) {
1964 sum.Bind(assembler->IntPtrAdd(sum.value(), arg)); 1989 sum.Bind(assembler->IntPtrAdd(sum.value(), arg));
1965 }); 1990 });
1966 1991
1967 m.Return(sum.value()); 1992 m.Return(sum.value());
1968 1993
1969 Handle<Code> code = m.GenerateCode(); 1994 Handle<Code> code = data.GenerateCode();
1970 CHECK(!code.is_null()); 1995 CHECK(!code.is_null());
1971 1996
1972 FunctionTester ft(code, kNumParams); 1997 FunctionTester ft(code, kNumParams);
1973 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(), 1998 Handle<Object> result = ft.Call(isolate->factory()->undefined_value(),
1974 Handle<Smi>(Smi::FromInt(12), isolate), 1999 Handle<Smi>(Smi::FromInt(12), isolate),
1975 Handle<Smi>(Smi::FromInt(13), isolate), 2000 Handle<Smi>(Smi::FromInt(13), isolate),
1976 Handle<Smi>(Smi::FromInt(14), isolate)) 2001 Handle<Smi>(Smi::FromInt(14), isolate))
1977 .ToHandleChecked(); 2002 .ToHandleChecked();
1978 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result); 2003 CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result);
1979 } 2004 }
1980 2005
1981 } // namespace internal 2006 } // namespace internal
1982 } // namespace v8 2007 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-code-assembler.cc ('k') | test/unittests/interpreter/interpreter-assembler-unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698