2016-08-03 12:20:39 +00:00
|
|
|
// Copyright 2016 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-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/common/globals.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/handles-inl.h"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/function-kind.h"
|
|
|
|
#include "src/objects/objects-inl.h"
|
2016-08-03 12:20:39 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
2017-08-11 11:22:28 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2016-08-03 12:20:39 +00:00
|
|
|
|
|
|
|
static void CheckObject(Isolate* isolate, Handle<Object> obj,
|
|
|
|
const char* string) {
|
2019-04-26 14:47:04 +00:00
|
|
|
Handle<String> print_string = String::Flatten(
|
|
|
|
isolate,
|
|
|
|
Handle<String>::cast(Object::NoSideEffectsToString(isolate, obj)));
|
2021-06-17 15:43:55 +00:00
|
|
|
CHECK(print_string->IsOneByteEqualTo(base::CStrVector(string)));
|
2016-08-03 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CheckSmi(Isolate* isolate, int value, const char* string) {
|
|
|
|
Handle<Object> handle(Smi::FromInt(value), isolate);
|
|
|
|
CheckObject(isolate, handle, string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CheckString(Isolate* isolate, const char* value,
|
|
|
|
const char* string) {
|
|
|
|
Handle<String> handle(isolate->factory()->NewStringFromAsciiChecked(value));
|
|
|
|
CheckObject(isolate, handle, string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CheckNumber(Isolate* isolate, double value, const char* string) {
|
|
|
|
Handle<Object> number = isolate->factory()->NewNumber(value);
|
|
|
|
CHECK(number->IsNumber());
|
|
|
|
CheckObject(isolate, number, string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CheckBoolean(Isolate* isolate, bool value, const char* string) {
|
|
|
|
CheckObject(isolate, value ? isolate->factory()->true_value()
|
|
|
|
: isolate->factory()->false_value(),
|
|
|
|
string);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(NoSideEffectsToString) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
CheckString(isolate, "fisk hest", "fisk hest");
|
|
|
|
CheckNumber(isolate, 42.3, "42.3");
|
|
|
|
CheckSmi(isolate, 42, "42");
|
|
|
|
CheckBoolean(isolate, true, "true");
|
|
|
|
CheckBoolean(isolate, false, "false");
|
|
|
|
CheckBoolean(isolate, false, "false");
|
2017-11-17 20:53:16 +00:00
|
|
|
Handle<Object> smi_42 = handle(Smi::FromInt(42), isolate);
|
|
|
|
CheckObject(isolate, BigInt::FromNumber(isolate, smi_42).ToHandleChecked(),
|
|
|
|
"42");
|
2016-08-03 12:20:39 +00:00
|
|
|
CheckObject(isolate, factory->undefined_value(), "undefined");
|
|
|
|
CheckObject(isolate, factory->null_value(), "null");
|
|
|
|
|
|
|
|
CheckObject(isolate, factory->error_to_string(), "[object Error]");
|
2017-09-08 05:35:10 +00:00
|
|
|
CheckObject(isolate, factory->unscopables_symbol(),
|
|
|
|
"Symbol(Symbol.unscopables)");
|
2016-08-03 12:20:39 +00:00
|
|
|
CheckObject(isolate, factory->NewError(isolate->error_function(),
|
|
|
|
factory->empty_string()),
|
|
|
|
"Error");
|
|
|
|
CheckObject(isolate, factory->NewError(
|
|
|
|
isolate->error_function(),
|
|
|
|
factory->NewStringFromAsciiChecked("fisk hest")),
|
|
|
|
"Error: fisk hest");
|
|
|
|
CheckObject(isolate, factory->NewJSObject(isolate->object_function()),
|
|
|
|
"#<Object>");
|
2021-03-12 16:55:47 +00:00
|
|
|
CheckObject(
|
|
|
|
isolate,
|
|
|
|
factory->NewJSProxy(factory->NewJSObject(isolate->object_function()),
|
|
|
|
factory->NewJSObject(isolate->object_function())),
|
|
|
|
"#<Object>");
|
2016-08-03 12:20:39 +00:00
|
|
|
}
|
2017-08-11 11:22:28 +00:00
|
|
|
|
2017-08-31 09:22:36 +00:00
|
|
|
TEST(EnumCache) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
i::Factory* factory = CcTest::i_isolate()->factory();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
// Create a nice transition tree:
|
|
|
|
// (a) --> (b) --> (c) shared DescriptorArray 1
|
|
|
|
// |
|
|
|
|
// +---> (cc) shared DescriptorArray 2
|
|
|
|
CompileRun(
|
|
|
|
"function O(a) { this.a = 1 };"
|
|
|
|
|
|
|
|
"a = new O();"
|
|
|
|
|
|
|
|
"b = new O();"
|
|
|
|
"b.b = 2;"
|
|
|
|
|
|
|
|
"c = new O();"
|
|
|
|
"c.b = 2;"
|
|
|
|
"c.c = 3;"
|
|
|
|
|
|
|
|
"cc = new O();"
|
|
|
|
"cc.b = 2;"
|
|
|
|
"cc.cc = 4;");
|
|
|
|
|
|
|
|
Handle<JSObject> a = Handle<JSObject>::cast(v8::Utils::OpenHandle(
|
|
|
|
*env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked()));
|
|
|
|
Handle<JSObject> b = Handle<JSObject>::cast(v8::Utils::OpenHandle(
|
|
|
|
*env->Global()->Get(env.local(), v8_str("b")).ToLocalChecked()));
|
|
|
|
Handle<JSObject> c = Handle<JSObject>::cast(v8::Utils::OpenHandle(
|
|
|
|
*env->Global()->Get(env.local(), v8_str("c")).ToLocalChecked()));
|
|
|
|
Handle<JSObject> cc = Handle<JSObject>::cast(v8::Utils::OpenHandle(
|
|
|
|
*env->Global()->Get(env.local(), v8_str("cc")).ToLocalChecked()));
|
|
|
|
|
|
|
|
// Check the transition tree.
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(a->map().instance_descriptors(), b->map().instance_descriptors());
|
|
|
|
CHECK_EQ(b->map().instance_descriptors(), c->map().instance_descriptors());
|
|
|
|
CHECK_NE(c->map().instance_descriptors(), cc->map().instance_descriptors());
|
|
|
|
CHECK_NE(b->map().instance_descriptors(), cc->map().instance_descriptors());
|
2017-08-31 09:22:36 +00:00
|
|
|
|
|
|
|
// Check that the EnumLength is unset.
|
|
|
|
CHECK_EQ(a->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(b->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(c->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(cc->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
|
|
|
|
// Check that the EnumCache is empty.
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(a->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(b->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(c->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(cc->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
|
|
|
|
|
|
|
// The EnumCache is shared on the DescriptorArray, creating it on {cc} has no
|
|
|
|
// effect on the other maps.
|
|
|
|
CompileRun("var s = 0; for (let key in cc) { s += cc[key] };");
|
|
|
|
{
|
|
|
|
CHECK_EQ(a->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(b->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(c->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(cc->map().EnumLength(), 3);
|
|
|
|
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(a->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(b->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(c->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
|
|
|
|
2021-03-05 11:23:36 +00:00
|
|
|
EnumCache enum_cache = cc->map().instance_descriptors().enum_cache();
|
2017-08-31 09:22:36 +00:00
|
|
|
CHECK_NE(enum_cache, *factory->empty_enum_cache());
|
|
|
|
CHECK_EQ(enum_cache.keys().length(), 3);
|
|
|
|
CHECK_EQ(enum_cache.indices().length(), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initializing the EnumCache for the the topmost map {a} will not create the
|
|
|
|
// cache for the other maps.
|
|
|
|
CompileRun("var s = 0; for (let key in a) { s += a[key] };");
|
|
|
|
{
|
|
|
|
CHECK_EQ(a->map().EnumLength(), 1);
|
|
|
|
CHECK_EQ(b->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(c->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(cc->map().EnumLength(), 3);
|
|
|
|
|
|
|
|
// The enum cache is shared on the descriptor array of maps {a}, {b} and
|
|
|
|
// {c} only.
|
2021-03-05 11:23:36 +00:00
|
|
|
EnumCache enum_cache = a->map().instance_descriptors().enum_cache();
|
2017-08-31 09:22:36 +00:00
|
|
|
CHECK_NE(enum_cache, *factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_EQ(a->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_EQ(b->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_EQ(c->map().instance_descriptors().enum_cache(), enum_cache);
|
2017-08-31 09:22:36 +00:00
|
|
|
|
|
|
|
CHECK_EQ(enum_cache.keys().length(), 1);
|
|
|
|
CHECK_EQ(enum_cache.indices().length(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creating the EnumCache for {c} will create a new EnumCache on the shared
|
|
|
|
// DescriptorArray.
|
|
|
|
Handle<EnumCache> previous_enum_cache(
|
2021-03-05 11:23:36 +00:00
|
|
|
a->map().instance_descriptors().enum_cache(), a->GetIsolate());
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FixedArray> previous_keys(previous_enum_cache->keys(),
|
|
|
|
a->GetIsolate());
|
|
|
|
Handle<FixedArray> previous_indices(previous_enum_cache->indices(),
|
|
|
|
a->GetIsolate());
|
2017-08-31 09:22:36 +00:00
|
|
|
CompileRun("var s = 0; for (let key in c) { s += c[key] };");
|
|
|
|
{
|
|
|
|
CHECK_EQ(a->map().EnumLength(), 1);
|
|
|
|
CHECK_EQ(b->map().EnumLength(), kInvalidEnumCacheSentinel);
|
|
|
|
CHECK_EQ(c->map().EnumLength(), 3);
|
|
|
|
CHECK_EQ(cc->map().EnumLength(), 3);
|
|
|
|
|
2021-03-05 11:23:36 +00:00
|
|
|
EnumCache enum_cache = c->map().instance_descriptors().enum_cache();
|
2017-08-31 09:22:36 +00:00
|
|
|
CHECK_NE(enum_cache, *factory->empty_enum_cache());
|
|
|
|
// The keys and indices caches are updated.
|
|
|
|
CHECK_EQ(enum_cache, *previous_enum_cache);
|
|
|
|
CHECK_NE(enum_cache.keys(), *previous_keys);
|
|
|
|
CHECK_NE(enum_cache.indices(), *previous_indices);
|
|
|
|
CHECK_EQ(previous_keys->length(), 1);
|
|
|
|
CHECK_EQ(previous_indices->length(), 1);
|
|
|
|
CHECK_EQ(enum_cache.keys().length(), 3);
|
|
|
|
CHECK_EQ(enum_cache.indices().length(), 3);
|
|
|
|
|
|
|
|
// The enum cache is shared on the descriptor array of maps {a}, {b} and
|
|
|
|
// {c} only.
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*previous_enum_cache);
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(a->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_EQ(b->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_EQ(c->map().instance_descriptors().enum_cache(), enum_cache);
|
2017-08-31 09:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// {b} can reuse the existing EnumCache, hence we only need to set the correct
|
|
|
|
// EnumLength on the map without modifying the cache itself.
|
|
|
|
previous_enum_cache =
|
2021-03-05 11:23:36 +00:00
|
|
|
handle(a->map().instance_descriptors().enum_cache(), a->GetIsolate());
|
2018-06-23 09:05:50 +00:00
|
|
|
previous_keys = handle(previous_enum_cache->keys(), a->GetIsolate());
|
|
|
|
previous_indices = handle(previous_enum_cache->indices(), a->GetIsolate());
|
2017-08-31 09:22:36 +00:00
|
|
|
CompileRun("var s = 0; for (let key in b) { s += b[key] };");
|
|
|
|
{
|
|
|
|
CHECK_EQ(a->map().EnumLength(), 1);
|
|
|
|
CHECK_EQ(b->map().EnumLength(), 2);
|
|
|
|
CHECK_EQ(c->map().EnumLength(), 3);
|
|
|
|
CHECK_EQ(cc->map().EnumLength(), 3);
|
|
|
|
|
2021-03-05 11:23:36 +00:00
|
|
|
EnumCache enum_cache = c->map().instance_descriptors().enum_cache();
|
2017-08-31 09:22:36 +00:00
|
|
|
CHECK_NE(enum_cache, *factory->empty_enum_cache());
|
|
|
|
// The keys and indices caches are not updated.
|
|
|
|
CHECK_EQ(enum_cache, *previous_enum_cache);
|
|
|
|
CHECK_EQ(enum_cache.keys(), *previous_keys);
|
|
|
|
CHECK_EQ(enum_cache.indices(), *previous_indices);
|
|
|
|
CHECK_EQ(enum_cache.keys().length(), 3);
|
|
|
|
CHECK_EQ(enum_cache.indices().length(), 3);
|
|
|
|
|
|
|
|
// The enum cache is shared on the descriptor array of maps {a}, {b} and
|
|
|
|
// {c} only.
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*factory->empty_enum_cache());
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_NE(cc->map().instance_descriptors().enum_cache(),
|
2017-08-31 09:22:36 +00:00
|
|
|
*previous_enum_cache);
|
2021-03-05 11:23:36 +00:00
|
|
|
CHECK_EQ(a->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_EQ(b->map().instance_descriptors().enum_cache(), enum_cache);
|
|
|
|
CHECK_EQ(c->map().instance_descriptors().enum_cache(), enum_cache);
|
2017-08-31 09:22:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 22:35:14 +00:00
|
|
|
TEST(ObjectMethodsThatTruncateMinusZero) {
|
|
|
|
LocalContext env;
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
Handle<Object> minus_zero = factory->NewNumber(-1.0 * 0.0);
|
|
|
|
CHECK(minus_zero->IsMinusZero());
|
|
|
|
|
|
|
|
Handle<Object> result =
|
|
|
|
Object::ToInteger(isolate, minus_zero).ToHandleChecked();
|
|
|
|
CHECK(result->IsZero());
|
|
|
|
|
|
|
|
result = Object::ToLength(isolate, minus_zero).ToHandleChecked();
|
|
|
|
CHECK(result->IsZero());
|
|
|
|
|
|
|
|
// Choose an error message template, doesn't matter which.
|
|
|
|
result = Object::ToIndex(isolate, minus_zero,
|
|
|
|
MessageTemplate::kInvalidAtomicAccessIndex)
|
|
|
|
.ToHandleChecked();
|
|
|
|
CHECK(result->IsZero());
|
|
|
|
}
|
|
|
|
|
2019-01-28 10:07:55 +00:00
|
|
|
#define TEST_FUNCTION_KIND(Name) \
|
|
|
|
TEST(Name) { \
|
|
|
|
for (int i = 0; i < FunctionKind::kLastFunctionKind; i++) { \
|
|
|
|
FunctionKind kind = static_cast<FunctionKind>(i); \
|
|
|
|
CHECK_EQ(FunctionKind##Name(kind), Name(kind)); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FunctionKindIsArrowFunction(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kArrowFunction:
|
|
|
|
case FunctionKind::kAsyncArrowFunction:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsArrowFunction)
|
|
|
|
|
|
|
|
bool FunctionKindIsAsyncGeneratorFunction(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kAsyncConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncGeneratorFunction:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsAsyncGeneratorFunction)
|
|
|
|
|
|
|
|
bool FunctionKindIsGeneratorFunction(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kGeneratorFunction:
|
|
|
|
case FunctionKind::kAsyncGeneratorFunction:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsGeneratorFunction)
|
|
|
|
|
|
|
|
bool FunctionKindIsAsyncFunction(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kAsyncFunction:
|
|
|
|
case FunctionKind::kAsyncArrowFunction:
|
|
|
|
case FunctionKind::kAsyncConciseMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncGeneratorFunction:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsAsyncFunction)
|
|
|
|
|
|
|
|
bool FunctionKindIsConciseMethod(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kConciseMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticConciseMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncConciseMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kClassMembersInitializerFunction:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsConciseMethod)
|
|
|
|
|
|
|
|
bool FunctionKindIsAccessorFunction(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kGetterFunction:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticGetterFunction:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kSetterFunction:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticSetterFunction:
|
2019-01-28 10:07:55 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsAccessorFunction)
|
|
|
|
|
|
|
|
bool FunctionKindIsDefaultConstructor(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kDefaultBaseConstructor:
|
|
|
|
case FunctionKind::kDefaultDerivedConstructor:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsDefaultConstructor)
|
|
|
|
|
|
|
|
bool FunctionKindIsBaseConstructor(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kBaseConstructor:
|
|
|
|
case FunctionKind::kDefaultBaseConstructor:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsBaseConstructor)
|
|
|
|
|
|
|
|
bool FunctionKindIsDerivedConstructor(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kDefaultDerivedConstructor:
|
|
|
|
case FunctionKind::kDerivedConstructor:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsDerivedConstructor)
|
|
|
|
|
|
|
|
bool FunctionKindIsClassConstructor(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kBaseConstructor:
|
|
|
|
case FunctionKind::kDefaultBaseConstructor:
|
|
|
|
case FunctionKind::kDefaultDerivedConstructor:
|
|
|
|
case FunctionKind::kDerivedConstructor:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsClassConstructor)
|
|
|
|
|
|
|
|
bool FunctionKindIsConstructable(FunctionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case FunctionKind::kGetterFunction:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticGetterFunction:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kSetterFunction:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticSetterFunction:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kArrowFunction:
|
|
|
|
case FunctionKind::kAsyncArrowFunction:
|
|
|
|
case FunctionKind::kAsyncFunction:
|
|
|
|
case FunctionKind::kAsyncConciseMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticAsyncConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kAsyncGeneratorFunction:
|
|
|
|
case FunctionKind::kGeneratorFunction:
|
|
|
|
case FunctionKind::kConciseGeneratorMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticConciseGeneratorMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kConciseMethod:
|
2021-01-29 08:24:03 +00:00
|
|
|
case FunctionKind::kStaticConciseMethod:
|
2019-01-28 10:07:55 +00:00
|
|
|
case FunctionKind::kClassMembersInitializerFunction:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsConstructable)
|
|
|
|
|
|
|
|
bool FunctionKindIsStrictFunctionWithoutPrototype(FunctionKind kind) {
|
|
|
|
return IsArrowFunction(kind) || IsConciseMethod(kind) ||
|
|
|
|
IsAccessorFunction(kind);
|
|
|
|
}
|
|
|
|
TEST_FUNCTION_KIND(IsStrictFunctionWithoutPrototype)
|
|
|
|
|
|
|
|
#undef TEST_FUNCTION_KIND
|
|
|
|
|
2017-08-11 11:22:28 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|