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.
|
|
|
|
|
2015-10-28 13:09:46 +00:00
|
|
|
// TODO(jochen): Remove this after the setting is turned on globally.
|
|
|
|
#define V8_IMMINENT_DEPRECATION_WARNINGS
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/compiler/function-tester.h"
|
|
|
|
|
|
|
|
using namespace v8::internal;
|
|
|
|
using namespace v8::internal::compiler;
|
2014-10-20 07:56:50 +00:00
|
|
|
uint32_t flags = CompilationInfo::kInliningEnabled;
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
|
|
|
|
TEST(CallFunction) {
|
|
|
|
FunctionTester T("(function(a,b) { return %_CallFunction(a, 1, 2, 3, b); })",
|
|
|
|
flags);
|
|
|
|
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(ClassOf) {
|
|
|
|
FunctionTester T("(function(a) { return %_ClassOf(a); })", flags);
|
|
|
|
|
|
|
|
T.CheckCall(T.Val("Function"), T.NewObject("(function() {})"));
|
|
|
|
T.CheckCall(T.Val("Array"), T.NewObject("([1])"));
|
|
|
|
T.CheckCall(T.Val("Object"), T.NewObject("({})"));
|
|
|
|
T.CheckCall(T.Val("RegExp"), T.NewObject("(/x/)"));
|
|
|
|
T.CheckCall(T.null(), T.undefined());
|
|
|
|
T.CheckCall(T.null(), T.null());
|
|
|
|
T.CheckCall(T.null(), T.Val("x"));
|
|
|
|
T.CheckCall(T.null(), T.Val(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(HeapObjectGetMap) {
|
|
|
|
FunctionTester T("(function(a) { return %_HeapObjectGetMap(a); })", flags);
|
|
|
|
|
|
|
|
Factory* factory = T.main_isolate()->factory();
|
|
|
|
T.CheckCall(factory->null_map(), T.null());
|
|
|
|
T.CheckCall(factory->undefined_map(), T.undefined());
|
|
|
|
T.CheckCall(factory->heap_number_map(), T.Val(3.1415));
|
|
|
|
T.CheckCall(factory->symbol_map(), factory->NewSymbol());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-27 10:06:43 +00:00
|
|
|
#define COUNTER_NAME "hurz"
|
|
|
|
|
|
|
|
static int* LookupCounter(const char* name) {
|
|
|
|
static int counter = 1234;
|
|
|
|
return strcmp(name, COUNTER_NAME) == 0 ? &counter : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(IncrementStatsCounter) {
|
|
|
|
FLAG_native_code_counters = true;
|
|
|
|
reinterpret_cast<v8::Isolate*>(CcTest::InitIsolateOnce())
|
|
|
|
->SetCounterFunction(LookupCounter);
|
|
|
|
FunctionTester T(
|
2015-03-30 06:28:35 +00:00
|
|
|
"(function() { %_IncrementStatsCounter('" COUNTER_NAME "'); })", flags);
|
2015-03-27 10:06:43 +00:00
|
|
|
StatsCounter counter(T.main_isolate(), COUNTER_NAME);
|
|
|
|
if (!counter.Enabled()) return;
|
|
|
|
|
|
|
|
int old_value = *counter.GetInternalPointer();
|
|
|
|
T.CheckCall(T.undefined());
|
|
|
|
CHECK_EQ(old_value + 1, *counter.GetInternalPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef COUNTER_NAME
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
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-06-23 06:43:34 +00:00
|
|
|
TEST(IsDate) {
|
|
|
|
FunctionTester T("(function(a) { return %_IsDate(a); })", flags);
|
|
|
|
|
|
|
|
T.CheckTrue(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());
|
|
|
|
T.CheckFalse(T.null());
|
|
|
|
T.CheckFalse(T.Val("x"));
|
|
|
|
T.CheckFalse(T.Val(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
TEST(IsFunction) {
|
|
|
|
FunctionTester T("(function(a) { return %_IsFunction(a); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-06-23 06:43:34 +00:00
|
|
|
T.CheckFalse(T.NewObject("new Date()"));
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckTrue(T.NewObject("(function() {})"));
|
|
|
|
T.CheckFalse(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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(IsMinusZero) {
|
2014-10-20 07:56:50 +00:00
|
|
|
FunctionTester T("(function(a) { return %_IsMinusZero(a); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
T.CheckFalse(T.Val(1));
|
|
|
|
T.CheckFalse(T.Val(1.1));
|
|
|
|
T.CheckTrue(T.Val(-0.0));
|
|
|
|
T.CheckFalse(T.Val(-2));
|
|
|
|
T.CheckFalse(T.Val(-2.3));
|
|
|
|
T.CheckFalse(T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
TEST(IsRegExp) {
|
|
|
|
FunctionTester T("(function(a) { return %_IsRegExp(a); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
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() {})"));
|
2014-07-30 13:54:45 +00:00
|
|
|
T.CheckFalse(T.NewObject("([1])"));
|
|
|
|
T.CheckFalse(T.NewObject("({})"));
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckTrue(T.NewObject("(/x/)"));
|
2014-07-30 13:54:45 +00:00
|
|
|
T.CheckFalse(T.undefined());
|
|
|
|
T.CheckFalse(T.null());
|
|
|
|
T.CheckFalse(T.Val("x"));
|
|
|
|
T.CheckFalse(T.Val(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-03-24 15:20:46 +00:00
|
|
|
TEST(MapGetInstanceType) {
|
|
|
|
FunctionTester T(
|
|
|
|
"(function(a) { return %_MapGetInstanceType(%_HeapObjectGetMap(a)); })",
|
|
|
|
flags);
|
|
|
|
|
|
|
|
Factory* factory = T.main_isolate()->factory();
|
|
|
|
T.CheckCall(T.Val(ODDBALL_TYPE), T.null());
|
|
|
|
T.CheckCall(T.Val(ODDBALL_TYPE), T.undefined());
|
|
|
|
T.CheckCall(T.Val(HEAP_NUMBER_TYPE), T.Val(3.1415));
|
|
|
|
T.CheckCall(T.Val(SYMBOL_TYPE), factory->NewSymbol());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ObjectEquals) {
|
2014-10-20 07:56:50 +00:00
|
|
|
FunctionTester T("(function(a,b) { return %_ObjectEquals(a,b); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
CompileRun("var o = {}");
|
|
|
|
|
|
|
|
T.CheckTrue(T.NewObject("(o)"), T.NewObject("(o)"));
|
|
|
|
T.CheckTrue(T.Val("internal"), T.Val("internal"));
|
|
|
|
T.CheckTrue(T.true_value(), T.true_value());
|
|
|
|
T.CheckFalse(T.true_value(), T.false_value());
|
|
|
|
T.CheckFalse(T.NewObject("({})"), T.NewObject("({})"));
|
|
|
|
T.CheckFalse(T.Val("a"), T.Val("b"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-26 08:36:28 +00:00
|
|
|
TEST(OneByteSeqStringGetChar) {
|
|
|
|
FunctionTester T("(function(a,b) { return %_OneByteSeqStringGetChar(a,b); })",
|
|
|
|
flags);
|
|
|
|
|
|
|
|
Handle<SeqOneByteString> string =
|
|
|
|
T.main_isolate()->factory()->NewRawOneByteString(3).ToHandleChecked();
|
|
|
|
string->SeqOneByteStringSet(0, 'b');
|
|
|
|
string->SeqOneByteStringSet(1, 'a');
|
|
|
|
string->SeqOneByteStringSet(2, 'r');
|
|
|
|
T.CheckCall(T.Val('b'), string, T.Val(0.0));
|
|
|
|
T.CheckCall(T.Val('a'), string, T.Val(1));
|
|
|
|
T.CheckCall(T.Val('r'), string, T.Val(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OneByteSeqStringSetChar) {
|
|
|
|
FunctionTester T("(function(a,b) { %_OneByteSeqStringSetChar(a,88,b); })",
|
|
|
|
flags);
|
|
|
|
|
|
|
|
Handle<SeqOneByteString> string =
|
|
|
|
T.main_isolate()->factory()->NewRawOneByteString(3).ToHandleChecked();
|
|
|
|
string->SeqOneByteStringSet(0, 'b');
|
|
|
|
string->SeqOneByteStringSet(1, 'a');
|
|
|
|
string->SeqOneByteStringSet(2, 'r');
|
|
|
|
T.Call(T.Val(1), string);
|
|
|
|
CHECK_EQ('b', string->SeqOneByteStringGet(0));
|
|
|
|
CHECK_EQ('X', string->SeqOneByteStringGet(1));
|
|
|
|
CHECK_EQ('r', string->SeqOneByteStringGet(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
TEST(SetValueOf) {
|
2014-10-20 07:56:50 +00:00
|
|
|
FunctionTester T("(function(a,b) { return %_SetValueOf(a,b); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
T.CheckCall(T.Val("a"), T.NewObject("(new String)"), T.Val("a"));
|
|
|
|
T.CheckCall(T.Val(123), T.NewObject("(new Number)"), T.Val(123));
|
|
|
|
T.CheckCall(T.Val("x"), T.undefined(), T.Val("x"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
TEST(StringAdd) {
|
|
|
|
FunctionTester T("(function(a,b) { return %_StringAdd(a,b); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckCall(T.Val("aaabbb"), T.Val("aaa"), T.Val("bbb"));
|
|
|
|
T.CheckCall(T.Val("aaa"), T.Val("aaa"), T.Val(""));
|
|
|
|
T.CheckCall(T.Val("bbb"), T.Val(""), T.Val("bbb"));
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(StringCharAt) {
|
2014-10-20 07:56:50 +00:00
|
|
|
FunctionTester T("(function(a,b) { return %_StringCharAt(a,b); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
T.CheckCall(T.Val("e"), T.Val("huge fan!"), T.Val(3));
|
|
|
|
T.CheckCall(T.Val("f"), T.Val("\xE2\x9D\x8A fan!"), T.Val(2));
|
|
|
|
T.CheckCall(T.Val(""), T.Val("not a fan!"), T.Val(23));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(StringCharCodeAt) {
|
2014-10-20 07:56:50 +00:00
|
|
|
FunctionTester T("(function(a,b) { return %_StringCharCodeAt(a,b); })",
|
|
|
|
flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
T.CheckCall(T.Val('e'), T.Val("huge fan!"), T.Val(3));
|
|
|
|
T.CheckCall(T.Val('f'), T.Val("\xE2\x9D\x8A fan!"), T.Val(2));
|
|
|
|
T.CheckCall(T.nan(), T.Val("not a fan!"), T.Val(23));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
TEST(StringCharFromCode) {
|
|
|
|
FunctionTester T("(function(a) { return %_StringCharFromCode(a); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckCall(T.Val("a"), T.Val(97));
|
|
|
|
T.CheckCall(T.Val("\xE2\x9D\x8A"), T.Val(0x274A));
|
|
|
|
T.CheckCall(T.Val(""), T.undefined());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(StringCompare) {
|
2014-10-20 07:56:50 +00:00
|
|
|
FunctionTester T("(function(a,b) { return %_StringCompare(a,b); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
T.CheckCall(T.Val(-1), T.Val("aaa"), T.Val("bbb"));
|
|
|
|
T.CheckCall(T.Val(0.0), T.Val("bbb"), T.Val("bbb"));
|
|
|
|
T.CheckCall(T.Val(+1), T.Val("ccc"), T.Val("bbb"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
TEST(SubString) {
|
|
|
|
FunctionTester T("(function(a,b) { return %_SubString(a,b,b+3); })", flags);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
T.CheckCall(T.Val("aaa"), T.Val("aaabbb"), T.Val(0.0));
|
|
|
|
T.CheckCall(T.Val("abb"), T.Val("aaabbb"), T.Val(2));
|
|
|
|
T.CheckCall(T.Val("aaa"), T.Val("aaa"), T.Val(0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-26 08:36:28 +00:00
|
|
|
TEST(TwoByteSeqStringGetChar) {
|
|
|
|
FunctionTester T("(function(a,b) { return %_TwoByteSeqStringGetChar(a,b); })",
|
|
|
|
flags);
|
|
|
|
|
|
|
|
Handle<SeqTwoByteString> string =
|
|
|
|
T.main_isolate()->factory()->NewRawTwoByteString(3).ToHandleChecked();
|
|
|
|
string->SeqTwoByteStringSet(0, 'b');
|
|
|
|
string->SeqTwoByteStringSet(1, 'a');
|
|
|
|
string->SeqTwoByteStringSet(2, 'r');
|
|
|
|
T.CheckCall(T.Val('b'), string, T.Val(0.0));
|
|
|
|
T.CheckCall(T.Val('a'), string, T.Val(1));
|
|
|
|
T.CheckCall(T.Val('r'), string, T.Val(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TwoByteSeqStringSetChar) {
|
|
|
|
FunctionTester T("(function(a,b) { %_TwoByteSeqStringSetChar(a,88,b); })",
|
|
|
|
flags);
|
|
|
|
|
|
|
|
Handle<SeqTwoByteString> string =
|
|
|
|
T.main_isolate()->factory()->NewRawTwoByteString(3).ToHandleChecked();
|
|
|
|
string->SeqTwoByteStringSet(0, 'b');
|
|
|
|
string->SeqTwoByteStringSet(1, 'a');
|
|
|
|
string->SeqTwoByteStringSet(2, 'r');
|
|
|
|
T.Call(T.Val(1), string);
|
|
|
|
CHECK_EQ('b', string->SeqTwoByteStringGet(0));
|
|
|
|
CHECK_EQ('X', string->SeqTwoByteStringGet(1));
|
|
|
|
CHECK_EQ('r', string->SeqTwoByteStringGet(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-24 15:20:46 +00:00
|
|
|
TEST(ValueOf) {
|
|
|
|
FunctionTester T("(function(a) { return %_ValueOf(a); })", flags);
|
|
|
|
|
|
|
|
T.CheckCall(T.Val("a"), T.Val("a"));
|
|
|
|
T.CheckCall(T.Val("b"), T.NewObject("(new String('b'))"));
|
|
|
|
T.CheckCall(T.Val(123), T.Val(123));
|
|
|
|
T.CheckCall(T.Val(456), T.NewObject("(new Number(456))"));
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|