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

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

Issue 2438483002: Add tests for CodeStubAssembler::ToString (Closed)
Patch Set: updates Created 4 years, 2 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 | « no previous file | 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 Handle<Smi> key(Smi::FromInt(k), isolate); 113 Handle<Smi> key(Smi::FromInt(k), isolate);
114 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked(); 114 Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked();
115 115
116 uint32_t hash = ComputeIntegerHash(k, hash_seed->value()); 116 uint32_t hash = ComputeIntegerHash(k, hash_seed->value());
117 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue); 117 Smi* expected = Smi::FromInt(hash & Smi::kMaxValue);
118 CHECK_EQ(expected, Smi::cast(*result)); 118 CHECK_EQ(expected, Smi::cast(*result));
119 } 119 }
120 } 120 }
121 121
122 TEST(ToString) {
123 Isolate* isolate(CcTest::InitIsolateOnce());
124 const int kNumParams = 1;
125 CodeStubAssemblerTester m(isolate, kNumParams);
126 m.Return(m.ToString(m.Parameter(kNumParams + 2), m.Parameter(0)));
127
128 Handle<Code> code = m.GenerateCode();
129 FunctionTester ft(code, kNumParams);
130
131 Handle<FixedArray> test_cases = isolate->factory()->NewFixedArray(5);
132 Handle<FixedArray> smi_test = isolate->factory()->NewFixedArray(2);
133 smi_test->set(0, Smi::FromInt(42));
134 Handle<String> str(isolate->factory()->InternalizeUtf8String("42"));
135 smi_test->set(1, *str);
136 test_cases->set(0, *smi_test);
137
138 Handle<FixedArray> number_test = isolate->factory()->NewFixedArray(2);
139 Handle<HeapNumber> num(isolate->factory()->NewHeapNumber(3.14));
140 number_test->set(0, *num);
141 str = isolate->factory()->InternalizeUtf8String("3.14");
142 number_test->set(1, *str);
143 test_cases->set(1, *number_test);
144
145 Handle<FixedArray> string_test = isolate->factory()->NewFixedArray(2);
146 str = isolate->factory()->InternalizeUtf8String("test");
147 string_test->set(0, *str);
148 string_test->set(1, *str);
149 test_cases->set(2, *string_test);
150
151 Handle<FixedArray> oddball_test = isolate->factory()->NewFixedArray(2);
152 oddball_test->set(0, isolate->heap()->undefined_value());
153 str = isolate->factory()->InternalizeUtf8String("undefined");
154 oddball_test->set(1, *str);
155 test_cases->set(3, *oddball_test);
156
157 Handle<FixedArray> tostring_test = isolate->factory()->NewFixedArray(2);
158 Handle<FixedArray> js_array_storage = isolate->factory()->NewFixedArray(2);
159 js_array_storage->set(0, Smi::FromInt(1));
160 js_array_storage->set(1, Smi::FromInt(2));
161 Handle<JSArray> js_array = isolate->factory()->NewJSArray(2);
162 JSArray::SetContent(js_array, js_array_storage);
163 tostring_test->set(0, *js_array);
164 str = isolate->factory()->InternalizeUtf8String("1,2");
165 tostring_test->set(1, *str);
166 test_cases->set(4, *tostring_test);
167
168 for (int i = 0; i < 5; ++i) {
169 Handle<FixedArray> test = handle(FixedArray::cast(test_cases->get(i)));
170 Handle<Object> obj = handle(test->get(0), isolate);
171 Handle<String> expected = handle(String::cast(test->get(1)));
172 Handle<Object> result = ft.Call(obj).ToHandleChecked();
173 CHECK(result->IsString());
174 CHECK(String::Equals(Handle<String>::cast(result), expected));
175 }
176 }
177
122 TEST(TryToName) { 178 TEST(TryToName) {
123 typedef CodeStubAssembler::Label Label; 179 typedef CodeStubAssembler::Label Label;
124 typedef CodeStubAssembler::Variable Variable; 180 typedef CodeStubAssembler::Variable Variable;
125 Isolate* isolate(CcTest::InitIsolateOnce()); 181 Isolate* isolate(CcTest::InitIsolateOnce());
126 182
127 const int kNumParams = 3; 183 const int kNumParams = 3;
128 CodeStubAssemblerTester m(isolate, kNumParams); 184 CodeStubAssemblerTester m(isolate, kNumParams);
129 185
130 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; 186 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
131 { 187 {
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 1560
1505 Handle<Object> constructor = 1561 Handle<Object> constructor =
1506 Object::GetPropertyOrElement(result, 1562 Object::GetPropertyOrElement(result,
1507 isolate->factory()->constructor_string()) 1563 isolate->factory()->constructor_string())
1508 .ToHandleChecked(); 1564 .ToHandleChecked();
1509 CHECK(constructor->SameValue(*isolate->type_error_function())); 1565 CHECK(constructor->SameValue(*isolate->type_error_function()));
1510 } 1566 }
1511 1567
1512 } // namespace internal 1568 } // namespace internal
1513 } // namespace v8 1569 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698