Line data Source code
1 : // Copyright 2014 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/objects/string.h"
6 : #include "src/optimized-compilation-info.h"
7 : #include "test/cctest/compiler/function-tester.h"
8 :
9 : namespace v8 {
10 : namespace internal {
11 : namespace compiler {
12 :
13 : uint32_t flags = OptimizedCompilationInfo::kInliningEnabled;
14 :
15 26660 : TEST(Call) {
16 4 : FunctionTester T("(function(a,b) { return %_Call(b, a, 1, 2, 3); })", flags);
17 : CompileRun("function f(a,b,c) { return a + b + c + this.d; }");
18 :
19 12 : T.CheckCall(T.Val(129), T.NewObject("({d:123})"), T.NewObject("f"));
20 16 : T.CheckCall(T.Val("6x"), T.NewObject("({d:'x'})"), T.NewObject("f"));
21 4 : }
22 :
23 26660 : TEST(IsArray) {
24 4 : FunctionTester T("(function(a) { return %_IsArray(a); })", flags);
25 :
26 8 : T.CheckFalse(T.NewObject("new Date()"));
27 8 : T.CheckFalse(T.NewObject("(function() {})"));
28 8 : T.CheckTrue(T.NewObject("([1])"));
29 8 : T.CheckFalse(T.NewObject("({})"));
30 8 : T.CheckFalse(T.NewObject("(/x/)"));
31 4 : T.CheckFalse(T.undefined());
32 4 : T.CheckFalse(T.null());
33 8 : T.CheckFalse(T.Val("x"));
34 4 : T.CheckFalse(T.Val(1));
35 4 : }
36 :
37 :
38 26660 : TEST(IsSmi) {
39 4 : FunctionTester T("(function(a) { return %_IsSmi(a); })", flags);
40 :
41 8 : T.CheckFalse(T.NewObject("new Date()"));
42 8 : T.CheckFalse(T.NewObject("(function() {})"));
43 8 : T.CheckFalse(T.NewObject("([1])"));
44 8 : T.CheckFalse(T.NewObject("({})"));
45 8 : T.CheckFalse(T.NewObject("(/x/)"));
46 4 : T.CheckFalse(T.undefined());
47 4 : T.CheckTrue(T.Val(1));
48 4 : T.CheckFalse(T.Val(1.1));
49 4 : T.CheckFalse(T.Val(-0.0));
50 4 : T.CheckTrue(T.Val(-2));
51 4 : T.CheckFalse(T.Val(-2.3));
52 4 : }
53 :
54 : } // namespace compiler
55 : } // namespace internal
56 79968 : } // namespace v8
|