2014-07-30 13:54:45 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/optimized-compilation-info.h"
|
2017-06-12 11:08:30 +00:00
|
|
|
#include "src/objects/string.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/compiler/function-tester.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2020-06-10 10:07:25 +00:00
|
|
|
uint32_t flags = OptimizedCompilationInfo::kInlining;
|
2015-03-24 15:20:46 +00:00
|
|
|
|
2015-11-05 11:48:07 +00:00
|
|
|
TEST(Call) {
|
|
|
|
FunctionTester T("(function(a,b) { return %_Call(b, a, 1, 2, 3); })", flags);
|
2015-03-24 15:20:46 +00:00
|
|
|
CompileRun("function f(a,b,c) { return a + b + c + this.d; }");
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckCall(T.Val(129), T.NewObject("({d:123})"), T.NewObject("f"));
|
|
|
|
T.CheckCall(T.Val("6x"), T.NewObject("({d:'x'})"), T.NewObject("f"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(IsArray) {
|
|
|
|
FunctionTester T("(function(a) { return %_IsArray(a); })", flags);
|
|
|
|
|
2015-06-23 06:43:34 +00:00
|
|
|
T.CheckFalse(T.NewObject("new Date()"));
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckFalse(T.NewObject("(function() {})"));
|
|
|
|
T.CheckTrue(T.NewObject("([1])"));
|
|
|
|
T.CheckFalse(T.NewObject("({})"));
|
|
|
|
T.CheckFalse(T.NewObject("(/x/)"));
|
2014-07-30 13:54:45 +00:00
|
|
|
T.CheckFalse(T.undefined());
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckFalse(T.null());
|
|
|
|
T.CheckFalse(T.Val("x"));
|
|
|
|
T.CheckFalse(T.Val(1));
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
TEST(IsSmi) {
|
|
|
|
FunctionTester T("(function(a) { return %_IsSmi(a); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-06-24 09:15:19 +00:00
|
|
|
T.CheckFalse(T.NewObject("new Date()"));
|
|
|
|
T.CheckFalse(T.NewObject("(function() {})"));
|
|
|
|
T.CheckFalse(T.NewObject("([1])"));
|
|
|
|
T.CheckFalse(T.NewObject("({})"));
|
|
|
|
T.CheckFalse(T.NewObject("(/x/)"));
|
|
|
|
T.CheckFalse(T.undefined());
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckTrue(T.Val(1));
|
|
|
|
T.CheckFalse(T.Val(1.1));
|
|
|
|
T.CheckFalse(T.Val(-0.0));
|
|
|
|
T.CheckTrue(T.Val(-2));
|
|
|
|
T.CheckFalse(T.Val(-2.3));
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|