OLD | NEW |
---|---|
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/interface-descriptors.h" | 5 #include "src/interface-descriptors.h" |
6 #include "src/isolate.h" | 6 #include "src/isolate.h" |
7 #include "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 namespace compiler { | 11 namespace compiler { |
12 | 12 |
13 | 13 |
14 class CodeStubAssemblerTester : public CodeStubAssembler { | 14 class CodeStubAssemblerTester : public CodeStubAssembler { |
15 public: | 15 public: |
16 // Test generating code for a stub. | |
16 CodeStubAssemblerTester(Isolate* isolate, | 17 CodeStubAssemblerTester(Isolate* isolate, |
17 const CallInterfaceDescriptor& descriptor) | 18 const CallInterfaceDescriptor& descriptor) |
18 : CodeStubAssembler(isolate, isolate->runtime_zone(), descriptor, | 19 : CodeStubAssembler(isolate, isolate->runtime_zone(), descriptor, |
19 Code::ComputeFlags(Code::STUB), "test"), | 20 Code::ComputeFlags(Code::STUB), "test"), |
20 scope_(isolate) {} | 21 scope_(isolate) {} |
21 | 22 |
23 // Test generating code for a JS function (e.g. builtins). | |
24 CodeStubAssemblerTester(Isolate* isolate, int parameter_count) | |
25 : CodeStubAssembler(isolate, isolate->runtime_zone(), parameter_count, | |
26 Code::ComputeFlags(Code::FUNCTION), "test"), | |
27 scope_(isolate) {} | |
28 | |
22 private: | 29 private: |
23 HandleScope scope_; | 30 HandleScope scope_; |
24 LocalContext context_; | 31 LocalContext context_; |
25 }; | 32 }; |
26 | 33 |
27 | 34 |
28 TEST(SimpleSmiReturn) { | 35 TEST(SimpleSmiReturn) { |
29 Isolate* isolate(CcTest::InitIsolateOnce()); | 36 Isolate* isolate(CcTest::InitIsolateOnce()); |
30 VoidDescriptor descriptor(isolate); | 37 VoidDescriptor descriptor(isolate); |
31 CodeStubAssemblerTester m(isolate, descriptor); | 38 CodeStubAssemblerTester m(isolate, descriptor); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); | 247 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); |
241 array->set(4, Smi::FromInt(733)); | 248 array->set(4, Smi::FromInt(733)); |
242 m.Return(m.LoadFixedArrayElementSmiIndex(m.HeapConstant(array), | 249 m.Return(m.LoadFixedArrayElementSmiIndex(m.HeapConstant(array), |
243 m.SmiTag(m.Int32Constant(4)))); | 250 m.SmiTag(m.Int32Constant(4)))); |
244 Handle<Code> code = m.GenerateCode(); | 251 Handle<Code> code = m.GenerateCode(); |
245 FunctionTester ft(descriptor, code); | 252 FunctionTester ft(descriptor, code); |
246 MaybeHandle<Object> result = ft.Call(); | 253 MaybeHandle<Object> result = ft.Call(); |
247 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value()); | 254 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
248 } | 255 } |
249 | 256 |
257 TEST(JSFunction) { | |
258 const int kNumParams = 3; // Receiver, left, right. | |
259 Isolate* isolate(CcTest::InitIsolateOnce()); | |
260 CodeStubAssemblerTester m(isolate, kNumParams); | |
261 m.Return(m.SmiTag( | |
262 m.Int32Add(m.SmiUntag(m.Parameter(1)), m.SmiUntag(m.Parameter(2))))); | |
263 Handle<Code> code = m.GenerateCode(); | |
264 FunctionTester ft(kNumParams - 1, code); // Implicit undefined receiver. | |
Jarin
2016/02/18 09:04:38
Apparently, there is a bug in FunctionTester::Buil
binji
2016/02/18 19:35:16
Acknowledged.
| |
265 Handle<Object> left = Handle<Smi>(Smi::FromInt(23), isolate); | |
266 Handle<Object> right = Handle<Smi>(Smi::FromInt(34), isolate); | |
267 MaybeHandle<Object> result = ft.Call(left, right); | |
268 CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value()); | |
269 } | |
Jarin
2016/02/18 12:32:15
Actually, FunctionTester as a whole seems to be a
binji
2016/02/18 19:35:17
Done.
| |
270 | |
250 } // namespace compiler | 271 } // namespace compiler |
251 } // namespace internal | 272 } // namespace internal |
252 } // namespace v8 | 273 } // namespace v8 |
OLD | NEW |