Commit 72230246 authored by jgruber's avatar jgruber Committed by Commit Bot

[factory] Simplify JSFunction creation

There's three common situations in which we need to create JSFunction
objects.  1) from the compiler, 2) from tests, and 3) everything else
(mostly during bootstrapping).

This is an attempt to simplify case 3), which previously relied on
several Factory::NewFunction overloads where it was not clear how the
semantics of each overload differed.

This CL removes all but one overload, and packs arguments into a new
NewFunctionArgs helper class.

It also removes the hacks around
SFI::set_lazy_deserialization_builtin_id by explicitly passing
builtin_id into Factory::NewSharedFunctionInfo.

Drive-by-fix: Properly set is_constructor hint in
SimpleCreateSharedFunctionInfo.

Bug: v8:6624
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ica94d95e72e443055db5e7ff9e8cdf4115201ef1
Reviewed-on: https://chromium-review.googlesource.com/757094
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49224}
parent 279805c1
...@@ -10060,34 +10060,33 @@ Local<Function> debug::GetBuiltin(Isolate* v8_isolate, Builtin builtin) { ...@@ -10060,34 +10060,33 @@ Local<Function> debug::GetBuiltin(Isolate* v8_isolate, Builtin builtin) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
i::HandleScope handle_scope(isolate); i::HandleScope handle_scope(isolate);
i::Builtins::Name name; i::Builtins::Name builtin_id;
switch (builtin) { switch (builtin) {
case kObjectKeys: case kObjectKeys:
name = i::Builtins::kObjectKeys; builtin_id = i::Builtins::kObjectKeys;
break; break;
case kObjectGetPrototypeOf: case kObjectGetPrototypeOf:
name = i::Builtins::kObjectGetPrototypeOf; builtin_id = i::Builtins::kObjectGetPrototypeOf;
break; break;
case kObjectGetOwnPropertyDescriptor: case kObjectGetOwnPropertyDescriptor:
name = i::Builtins::kObjectGetOwnPropertyDescriptor; builtin_id = i::Builtins::kObjectGetOwnPropertyDescriptor;
break; break;
case kObjectGetOwnPropertyNames: case kObjectGetOwnPropertyNames:
name = i::Builtins::kObjectGetOwnPropertyNames; builtin_id = i::Builtins::kObjectGetOwnPropertyNames;
break; break;
case kObjectGetOwnPropertySymbols: case kObjectGetOwnPropertySymbols:
name = i::Builtins::kObjectGetOwnPropertySymbols; builtin_id = i::Builtins::kObjectGetOwnPropertySymbols;
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
i::Handle<i::Code> call_code(isolate->builtins()->builtin(name));
i::Handle<i::JSFunction> fun = i::Handle<i::String> name = isolate->factory()->empty_string();
isolate->factory()->NewFunctionWithoutPrototype( i::Handle<i::Code> code(isolate->builtins()->builtin(builtin_id));
isolate->factory()->empty_string(), call_code, i::NewFunctionArgs args = i::NewFunctionArgs::ForBuiltinWithoutPrototype(
i::LanguageMode::kSloppy); name, code, builtin_id, i::LanguageMode::kSloppy);
if (i::Builtins::IsLazy(name)) { i::Handle<i::JSFunction> fun = isolate->factory()->NewFunction(args);
fun->shared()->set_lazy_deserialization_builtin_id(name);
}
fun->shared()->DontAdaptArguments(); fun->shared()->DontAdaptArguments();
return Utils::ToLocal(handle_scope.CloseAndEscape(fun)); return Utils::ToLocal(handle_scope.CloseAndEscape(fun));
} }
......
This diff is collapsed.
...@@ -108,17 +108,19 @@ BUILTIN(ConsoleTimeStamp) { ...@@ -108,17 +108,19 @@ BUILTIN(ConsoleTimeStamp) {
namespace { namespace {
void InstallContextFunction(Handle<JSObject> target, const char* name, void InstallContextFunction(Handle<JSObject> target, const char* name,
Builtins::Name call, int context_id, Builtins::Name builtin_id, int context_id,
Handle<Object> context_name) { Handle<Object> context_name) {
Factory* const factory = target->GetIsolate()->factory(); Factory* const factory = target->GetIsolate()->factory();
Handle<Code> call_code(target->GetIsolate()->builtins()->builtin(call)); Handle<Code> code(target->GetIsolate()->builtins()->builtin(builtin_id));
Handle<String> name_string = Handle<String> name_string =
Name::ToFunctionName(factory->InternalizeUtf8String(name)) Name::ToFunctionName(factory->InternalizeUtf8String(name))
.ToHandleChecked(); .ToHandleChecked();
Handle<JSFunction> fun = factory->NewFunctionWithoutPrototype( NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithoutPrototype(
name_string, call_code, LanguageMode::kSloppy); name_string, code, builtin_id, i::LanguageMode::kSloppy);
Handle<JSFunction> fun = factory->NewFunction(args);
fun->shared()->set_native(true); fun->shared()->set_native(true);
fun->shared()->DontAdaptArguments(); fun->shared()->DontAdaptArguments();
fun->shared()->set_length(1); fun->shared()->set_length(1);
...@@ -139,9 +141,13 @@ BUILTIN(ConsoleContext) { ...@@ -139,9 +141,13 @@ BUILTIN(ConsoleContext) {
Factory* const factory = isolate->factory(); Factory* const factory = isolate->factory();
Handle<String> name = factory->InternalizeUtf8String("Context"); Handle<String> name = factory->InternalizeUtf8String("Context");
Handle<JSFunction> cons = factory->NewFunction(name); NewFunctionArgs arguments = NewFunctionArgs::ForFunctionWithoutCode(
Handle<JSObject> empty = factory->NewJSObject(isolate->object_function()); name, isolate->sloppy_function_map(), LanguageMode::kSloppy);
JSFunction::SetPrototype(cons, empty); Handle<JSFunction> cons = factory->NewFunction(arguments);
Handle<JSObject> prototype = factory->NewJSObject(isolate->object_function());
JSFunction::SetPrototype(cons, prototype);
Handle<JSObject> context = factory->NewJSObject(cons, TENURED); Handle<JSObject> context = factory->NewJSObject(cons, TENURED);
DCHECK(context->IsJSObject()); DCHECK(context->IsJSObject());
int id = isolate->last_console_context_id() + 1; int id = isolate->last_console_context_id() + 1;
......
...@@ -48,6 +48,8 @@ class Builtins { ...@@ -48,6 +48,8 @@ class Builtins {
builtin_count builtin_count
}; };
static const int32_t kNoBuiltinId = -1;
static bool IsBuiltinId(int maybe_id) { static bool IsBuiltinId(int maybe_id) {
return 0 <= maybe_id && maybe_id < builtin_count; return 0 <= maybe_id && maybe_id < builtin_count;
} }
......
This diff is collapsed.
...@@ -29,6 +29,7 @@ class BoilerplateDescription; ...@@ -29,6 +29,7 @@ class BoilerplateDescription;
class ConstantElementsPair; class ConstantElementsPair;
class CoverageInfo; class CoverageInfo;
class DebugInfo; class DebugInfo;
class NewFunctionArgs;
class JSModuleNamespace; class JSModuleNamespace;
struct SourceRange; struct SourceRange;
class PreParsedScopeData; class PreParsedScopeData;
...@@ -621,18 +622,14 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -621,18 +622,14 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy(int size); Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy(int size);
Handle<JSFunction> NewFunction(Handle<Map> map, // Creates a new JSFunction according to the given args. This is the function
Handle<SharedFunctionInfo> info, // you'll probably want to use when creating a JSFunction from the runtime.
Handle<Object> context_or_undefined, Handle<JSFunction> NewFunction(const NewFunctionArgs& args);
PretenureFlag pretenure = TENURED);
Handle<JSFunction> NewFunction( // For testing only. Creates a sloppy function without code.
Handle<String> name, Handle<Code> code, Handle<Object> prototype, Handle<JSFunction> NewFunctionForTest(Handle<String> name);
LanguageMode language_mode = LanguageMode::kSloppy,
MutableMode prototype_mutability = MUTABLE); // Function creation from SharedFunctionInfo.
Handle<JSFunction> NewFunction(Handle<String> name);
Handle<JSFunction> NewFunctionWithoutPrototype(
Handle<String> name, Handle<Code> code,
LanguageMode language_mode = LanguageMode::kSloppy);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo( Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info, Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info,
...@@ -651,16 +648,12 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -651,16 +648,12 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<SharedFunctionInfo> function_info, Handle<Context> context, Handle<SharedFunctionInfo> function_info, Handle<Context> context,
PretenureFlag pretenure = TENURED); PretenureFlag pretenure = TENURED);
Handle<JSFunction> NewFunction( // The choke-point for JSFunction creation. Handles allocation and
Handle<String> name, Handle<Code> code, Handle<Object> prototype, // initialization. All other utility methods call into this.
InstanceType type, int instance_size, int inobject_properties, Handle<JSFunction> NewFunction(Handle<Map> map,
LanguageMode language_mode = LanguageMode::kSloppy, Handle<SharedFunctionInfo> info,
MutableMode prototype_mutability = MUTABLE); Handle<Object> context_or_undefined,
Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code, PretenureFlag pretenure = TENURED);
InstanceType type, int instance_size,
int inobject_properties);
Handle<JSFunction> NewFunction(Handle<Map> map, Handle<String> name,
MaybeHandle<Code> maybe_code);
// Create a serialized scope info. // Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length); Handle<ScopeInfo> NewScopeInfo(int length);
...@@ -768,7 +761,8 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -768,7 +761,8 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<ScopeInfo> scope_info); Handle<ScopeInfo> scope_info);
Handle<SharedFunctionInfo> NewSharedFunctionInfo( Handle<SharedFunctionInfo> NewSharedFunctionInfo(
MaybeHandle<String> name, MaybeHandle<Code> code, bool is_constructor, MaybeHandle<String> name, MaybeHandle<Code> code, bool is_constructor,
FunctionKind kind = kNormalFunction); FunctionKind kind = kNormalFunction,
int maybe_builtin_index = Builtins::kNoBuiltinId);
Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral( Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, Handle<Script> script); FunctionLiteral* literal, Handle<Script> script);
...@@ -875,6 +869,59 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -875,6 +869,59 @@ class V8_EXPORT_PRIVATE Factory final {
PretenureFlag pretenure = NOT_TENURED); PretenureFlag pretenure = NOT_TENURED);
}; };
// Utility class to simplify argument handling around JSFunction creation.
class NewFunctionArgs final {
public:
static NewFunctionArgs ForWasm(Handle<String> name, Handle<Code> code,
Handle<Map> map);
static NewFunctionArgs ForBuiltin(Handle<String> name, Handle<Code> code,
Handle<Map> map, int builtin_id);
static NewFunctionArgs ForFunctionWithoutCode(Handle<String> name,
Handle<Map> map,
LanguageMode language_mode);
static NewFunctionArgs ForBuiltinWithPrototype(
Handle<String> name, Handle<Code> code, Handle<Object> prototype,
InstanceType type, int instance_size, int inobject_properties,
int builtin_id, MutableMode prototype_mutability);
static NewFunctionArgs ForBuiltinWithoutPrototype(Handle<String> name,
Handle<Code> code,
int builtin_id,
LanguageMode language_mode);
Handle<Map> GetMap(Isolate* isolate) const;
private:
NewFunctionArgs() {} // Use the static factory constructors.
void SetShouldCreateAndSetInitialMap();
void SetShouldSetPrototype();
void SetShouldSetLanguageMode();
// Sentinel value.
static const int kUninitialized = -1;
Handle<String> name_;
MaybeHandle<Map> maybe_map_;
MaybeHandle<Code> maybe_code_;
bool should_create_and_set_initial_map_ = false;
InstanceType type_;
int instance_size_ = kUninitialized;
int inobject_properties_ = kUninitialized;
bool should_set_prototype_ = false;
MaybeHandle<Object> maybe_prototype_;
bool should_set_language_mode_ = false;
LanguageMode language_mode_;
int maybe_builtin_id_ = kUninitialized;
MutableMode prototype_mutability_;
friend class Factory;
};
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -320,14 +320,6 @@ int SharedFunctionInfo::lazy_deserialization_builtin_id() const { ...@@ -320,14 +320,6 @@ int SharedFunctionInfo::lazy_deserialization_builtin_id() const {
return id; return id;
} }
void SharedFunctionInfo::set_lazy_deserialization_builtin_id(int builtin_id) {
DCHECK(function_data()->IsUndefined(GetIsolate()) ||
HasLazyDeserializationBuiltinId());
DCHECK(Builtins::IsBuiltinId(builtin_id));
DCHECK(Builtins::IsLazy(builtin_id));
set_function_data(Smi::FromInt(builtin_id));
}
bool SharedFunctionInfo::HasBuiltinFunctionId() { bool SharedFunctionInfo::HasBuiltinFunctionId() {
return function_identifier()->IsSmi(); return function_identifier()->IsSmi();
} }
......
...@@ -165,7 +165,6 @@ class SharedFunctionInfo : public HeapObject { ...@@ -165,7 +165,6 @@ class SharedFunctionInfo : public HeapObject {
// mainly used during optimization). // mainly used during optimization).
inline bool HasLazyDeserializationBuiltinId() const; inline bool HasLazyDeserializationBuiltinId() const;
inline int lazy_deserialization_builtin_id() const; inline int lazy_deserialization_builtin_id() const;
inline void set_lazy_deserialization_builtin_id(int builtin_id);
// [function identifier]: This field holds an additional identifier for the // [function identifier]: This field holds an additional identifier for the
// function. // function.
......
...@@ -782,8 +782,9 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry( ...@@ -782,8 +782,9 @@ Handle<JSFunction> WasmDebugInfo::GetCWasmEntry(
isolate->factory()->NewSharedFunctionInfo(name, new_entry_code, false); isolate->factory()->NewSharedFunctionInfo(name, new_entry_code, false);
shared->set_internal_formal_parameter_count( shared->set_internal_formal_parameter_count(
compiler::CWasmEntryParameters::kNumParameters); compiler::CWasmEntryParameters::kNumParameters);
Handle<JSFunction> new_entry = isolate->factory()->NewFunction( NewFunctionArgs args = NewFunctionArgs::ForWasm(
isolate->sloppy_function_map(), name, new_entry_code); name, new_entry_code, isolate->sloppy_function_map());
Handle<JSFunction> new_entry = isolate->factory()->NewFunction(args);
new_entry->set_context( new_entry->set_context(
*debug_info->wasm_instance()->compiled_module()->native_context()); *debug_info->wasm_instance()->compiled_module()->native_context());
new_entry->set_shared(*shared); new_entry->set_shared(*shared);
......
...@@ -871,8 +871,9 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) { ...@@ -871,8 +871,9 @@ void WasmJs::Install(Isolate* isolate, bool exposed_on_global_object) {
// Setup WebAssembly // Setup WebAssembly
Handle<String> name = v8_str(isolate, "WebAssembly"); Handle<String> name = v8_str(isolate, "WebAssembly");
Handle<JSFunction> cons = factory->NewFunction(isolate->strict_function_map(), NewFunctionArgs args = NewFunctionArgs::ForFunctionWithoutCode(
name, MaybeHandle<Code>()); name, isolate->strict_function_map(), LanguageMode::kStrict);
Handle<JSFunction> cons = factory->NewFunction(args);
JSFunction::SetPrototype(cons, isolate->initial_object_prototype()); JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
cons->shared()->set_instance_class_name(*name); cons->shared()->set_instance_class_name(*name);
Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED); Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED);
......
...@@ -658,8 +658,9 @@ Handle<WasmExportedFunction> WasmExportedFunction::New( ...@@ -658,8 +658,9 @@ Handle<WasmExportedFunction> WasmExportedFunction::New(
isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false); isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false);
shared->set_length(arity); shared->set_length(arity);
shared->set_internal_formal_parameter_count(arity); shared->set_internal_formal_parameter_count(arity);
Handle<JSFunction> js_function = isolate->factory()->NewFunction( NewFunctionArgs args = NewFunctionArgs::ForWasm(
isolate->sloppy_function_map(), name, export_wrapper); name, export_wrapper, isolate->sloppy_function_map());
Handle<JSFunction> js_function = isolate->factory()->NewFunction(args);
js_function->set_shared(*shared); js_function->set_shared(*shared);
Handle<Symbol> instance_symbol(isolate->factory()->wasm_instance_symbol()); Handle<Symbol> instance_symbol(isolate->factory()->wasm_instance_symbol());
......
...@@ -139,8 +139,8 @@ TEST(StressJS) { ...@@ -139,8 +139,8 @@ TEST(StressJS) {
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate()); v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate());
env->Enter(); env->Enter();
Handle<JSFunction> function = factory->NewFunction( Handle<JSFunction> function =
factory->function_string()); factory->NewFunctionForTest(factory->function_string());
// Force the creation of an initial map and set the code to // Force the creation of an initial map and set the code to
// something empty. // something empty.
factory->NewJSObject(function); factory->NewJSObject(function);
......
...@@ -361,7 +361,7 @@ TEST(GarbageCollection) { ...@@ -361,7 +361,7 @@ TEST(GarbageCollection) {
{ {
HandleScope inner_scope(isolate); HandleScope inner_scope(isolate);
// Allocate a function and keep it in global object's property. // Allocate a function and keep it in global object's property.
Handle<JSFunction> function = factory->NewFunction(name); Handle<JSFunction> function = factory->NewFunctionForTest(name);
JSReceiver::SetProperty(global, name, function, LanguageMode::kSloppy) JSReceiver::SetProperty(global, name, function, LanguageMode::kSloppy)
.Check(); .Check();
// Allocate an object. Unrooted after leaving the scope. // Allocate an object. Unrooted after leaving the scope.
...@@ -927,7 +927,7 @@ TEST(FunctionAllocation) { ...@@ -927,7 +927,7 @@ TEST(FunctionAllocation) {
v8::HandleScope sc(CcTest::isolate()); v8::HandleScope sc(CcTest::isolate());
Handle<String> name = factory->InternalizeUtf8String("theFunction"); Handle<String> name = factory->InternalizeUtf8String("theFunction");
Handle<JSFunction> function = factory->NewFunction(name); Handle<JSFunction> function = factory->NewFunctionForTest(name);
Handle<Smi> twenty_three(Smi::FromInt(23), isolate); Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
Handle<Smi> twenty_four(Smi::FromInt(24), isolate); Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
...@@ -1029,7 +1029,7 @@ TEST(JSObjectMaps) { ...@@ -1029,7 +1029,7 @@ TEST(JSObjectMaps) {
v8::HandleScope sc(CcTest::isolate()); v8::HandleScope sc(CcTest::isolate());
Handle<String> name = factory->InternalizeUtf8String("theFunction"); Handle<String> name = factory->InternalizeUtf8String("theFunction");
Handle<JSFunction> function = factory->NewFunction(name); Handle<JSFunction> function = factory->NewFunctionForTest(name);
Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
Handle<JSObject> obj = factory->NewJSObject(function); Handle<JSObject> obj = factory->NewJSObject(function);
......
...@@ -129,7 +129,7 @@ HEAP_TEST(MarkCompactCollector) { ...@@ -129,7 +129,7 @@ HEAP_TEST(MarkCompactCollector) {
{ HandleScope scope(isolate); { HandleScope scope(isolate);
// allocate a garbage // allocate a garbage
Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); Handle<String> func_name = factory->InternalizeUtf8String("theFunction");
Handle<JSFunction> function = factory->NewFunction(func_name); Handle<JSFunction> function = factory->NewFunctionForTest(func_name);
JSReceiver::SetProperty(global, func_name, function, LanguageMode::kSloppy) JSReceiver::SetProperty(global, func_name, function, LanguageMode::kSloppy)
.Check(); .Check();
......
...@@ -2118,7 +2118,7 @@ TEST(InterpreterInstanceOf) { ...@@ -2118,7 +2118,7 @@ TEST(InterpreterInstanceOf) {
Zone* zone = handles.main_zone(); Zone* zone = handles.main_zone();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<i::String> name = factory->NewStringFromAsciiChecked("cons"); Handle<i::String> name = factory->NewStringFromAsciiChecked("cons");
Handle<i::JSFunction> func = factory->NewFunction(name); Handle<i::JSFunction> func = factory->NewFunctionForTest(name);
Handle<i::JSObject> instance = factory->NewJSObject(func); Handle<i::JSObject> instance = factory->NewJSObject(func);
Handle<i::Object> other = factory->NewNumber(3.3333); Handle<i::Object> other = factory->NewNumber(3.3333);
Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other};
......
...@@ -891,7 +891,8 @@ TEST(TryHasOwnProperty) { ...@@ -891,7 +891,8 @@ TEST(TryHasOwnProperty) {
{ {
// Dictionary mode object. // Dictionary mode object.
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
Handle<JSObject> object = factory->NewJSObject(function); Handle<JSObject> object = factory->NewJSObject(function);
AddProperties(object, names, arraysize(names)); AddProperties(object, names, arraysize(names));
JSObject::NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0, "test"); JSObject::NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0, "test");
...@@ -908,7 +909,8 @@ TEST(TryHasOwnProperty) { ...@@ -908,7 +909,8 @@ TEST(TryHasOwnProperty) {
{ {
// Global object. // Global object.
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
JSFunction::EnsureHasInitialMap(function); JSFunction::EnsureHasInitialMap(function);
function->initial_map()->set_instance_type(JS_GLOBAL_OBJECT_TYPE); function->initial_map()->set_instance_type(JS_GLOBAL_OBJECT_TYPE);
function->initial_map()->set_is_prototype_map(true); function->initial_map()->set_is_prototype_map(true);
...@@ -958,7 +960,8 @@ TEST(TryHasOwnProperty) { ...@@ -958,7 +960,8 @@ TEST(TryHasOwnProperty) {
} }
{ {
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
Handle<JSProxy> object = factory->NewJSProxy(function, objects[0]); Handle<JSProxy> object = factory->NewJSProxy(function, objects[0]);
CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type()); CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type());
ft.CheckTrue(object, names[0], expect_bailout); ft.CheckTrue(object, names[0], expect_bailout);
...@@ -1031,11 +1034,11 @@ TEST(TryGetOwnProperty) { ...@@ -1031,11 +1034,11 @@ TEST(TryGetOwnProperty) {
factory->NewPrivateSymbol(), factory->NewPrivateSymbol(),
}; };
Handle<Object> values[] = { Handle<Object> values[] = {
factory->NewFunction(factory->empty_string()), factory->NewFunctionForTest(factory->empty_string()),
factory->NewSymbol(), factory->NewSymbol(),
factory->InternalizeUtf8String("a"), factory->InternalizeUtf8String("a"),
CreateAccessorPair(&ft, "() => 188;", "() => 199;"), CreateAccessorPair(&ft, "() => 188;", "() => 199;"),
factory->NewFunction(factory->InternalizeUtf8String("bb")), factory->NewFunctionForTest(factory->InternalizeUtf8String("bb")),
factory->InternalizeUtf8String("ccc"), factory->InternalizeUtf8String("ccc"),
CreateAccessorPair(&ft, "() => 88;", nullptr), CreateAccessorPair(&ft, "() => 88;", nullptr),
handle(Smi::FromInt(1), isolate), handle(Smi::FromInt(1), isolate),
...@@ -1043,7 +1046,8 @@ TEST(TryGetOwnProperty) { ...@@ -1043,7 +1046,8 @@ TEST(TryGetOwnProperty) {
CreateAccessorPair(&ft, nullptr, "() => 99;"), CreateAccessorPair(&ft, nullptr, "() => 99;"),
factory->NewHeapNumber(4.2), factory->NewHeapNumber(4.2),
handle(Smi::FromInt(153), isolate), handle(Smi::FromInt(153), isolate),
factory->NewJSObject(factory->NewFunction(factory->empty_string())), factory->NewJSObject(
factory->NewFunctionForTest(factory->empty_string())),
factory->NewPrivateSymbol(), factory->NewPrivateSymbol(),
}; };
STATIC_ASSERT(arraysize(values) < arraysize(names)); STATIC_ASSERT(arraysize(values) < arraysize(names));
...@@ -1093,7 +1097,8 @@ TEST(TryGetOwnProperty) { ...@@ -1093,7 +1097,8 @@ TEST(TryGetOwnProperty) {
{ {
// Dictionary mode object. // Dictionary mode object.
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
Handle<JSObject> object = factory->NewJSObject(function); Handle<JSObject> object = factory->NewJSObject(function);
AddProperties(object, names, arraysize(names), values, arraysize(values), AddProperties(object, names, arraysize(names), values, arraysize(values),
rand_gen.NextInt()); rand_gen.NextInt());
...@@ -1163,7 +1168,8 @@ TEST(TryGetOwnProperty) { ...@@ -1163,7 +1168,8 @@ TEST(TryGetOwnProperty) {
} }
{ {
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
Handle<JSProxy> object = factory->NewJSProxy(function, objects[0]); Handle<JSProxy> object = factory->NewJSProxy(function, objects[0]);
CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type()); CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type());
Handle<Object> value = ft.Call(object, names[0]).ToHandleChecked(); Handle<Object> value = ft.Call(object, names[0]).ToHandleChecked();
...@@ -1395,7 +1401,8 @@ TEST(TryLookupElement) { ...@@ -1395,7 +1401,8 @@ TEST(TryLookupElement) {
{ {
Handle<JSArray> handler = factory->NewJSArray(0); Handle<JSArray> handler = factory->NewJSArray(0);
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
Handle<JSProxy> object = factory->NewJSProxy(function, handler); Handle<JSProxy> object = factory->NewJSProxy(function, handler);
CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type()); CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type());
ft.CheckTrue(object, smi0, expect_bailout); ft.CheckTrue(object, smi0, expect_bailout);
......
...@@ -75,7 +75,8 @@ TEST(JSObjectAddingProperties) { ...@@ -75,7 +75,8 @@ TEST(JSObjectAddingProperties) {
Handle<FixedArray> empty_fixed_array(factory->empty_fixed_array()); Handle<FixedArray> empty_fixed_array(factory->empty_fixed_array());
Handle<PropertyArray> empty_property_array(factory->empty_property_array()); Handle<PropertyArray> empty_property_array(factory->empty_property_array());
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
Handle<Object> value(Smi::FromInt(42), isolate); Handle<Object> value(Smi::FromInt(42), isolate);
Handle<JSObject> object = factory->NewJSObject(function); Handle<JSObject> object = factory->NewJSObject(function);
...@@ -104,7 +105,8 @@ TEST(JSObjectInObjectAddingProperties) { ...@@ -104,7 +105,8 @@ TEST(JSObjectInObjectAddingProperties) {
Handle<FixedArray> empty_fixed_array(factory->empty_fixed_array()); Handle<FixedArray> empty_fixed_array(factory->empty_fixed_array());
Handle<PropertyArray> empty_property_array(factory->empty_property_array()); Handle<PropertyArray> empty_property_array(factory->empty_property_array());
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
int nof_inobject_properties = 10; int nof_inobject_properties = 10;
// force in object properties by changing the expected_nof_properties // force in object properties by changing the expected_nof_properties
function->shared()->set_expected_nof_properties(nof_inobject_properties); function->shared()->set_expected_nof_properties(nof_inobject_properties);
...@@ -151,7 +153,8 @@ TEST(JSObjectAddingElements) { ...@@ -151,7 +153,8 @@ TEST(JSObjectAddingElements) {
Handle<String> name; Handle<String> name;
Handle<FixedArray> empty_fixed_array(factory->empty_fixed_array()); Handle<FixedArray> empty_fixed_array(factory->empty_fixed_array());
Handle<PropertyArray> empty_property_array(factory->empty_property_array()); Handle<PropertyArray> empty_property_array(factory->empty_property_array());
Handle<JSFunction> function = factory->NewFunction(factory->empty_string()); Handle<JSFunction> function =
factory->NewFunctionForTest(factory->empty_string());
Handle<Object> value(Smi::FromInt(42), isolate); Handle<Object> value(Smi::FromInt(42), isolate);
Handle<JSObject> object = factory->NewJSObject(function); Handle<JSObject> object = factory->NewJSObject(function);
......
...@@ -66,11 +66,11 @@ static Handle<AccessorPair> CreateAccessorPair(bool with_getter, ...@@ -66,11 +66,11 @@ static Handle<AccessorPair> CreateAccessorPair(bool with_getter,
Handle<AccessorPair> pair = factory->NewAccessorPair(); Handle<AccessorPair> pair = factory->NewAccessorPair();
Handle<String> empty_string = factory->empty_string(); Handle<String> empty_string = factory->empty_string();
if (with_getter) { if (with_getter) {
Handle<JSFunction> func = factory->NewFunction(empty_string); Handle<JSFunction> func = factory->NewFunctionForTest(empty_string);
pair->set_getter(*func); pair->set_getter(*func);
} }
if (with_setter) { if (with_setter) {
Handle<JSFunction> func = factory->NewFunction(empty_string); Handle<JSFunction> func = factory->NewFunctionForTest(empty_string);
pair->set_setter(*func); pair->set_setter(*func);
} }
return pair; return pair;
...@@ -1484,7 +1484,7 @@ TEST(ReconfigureDataFieldAttribute_SameDataConstantAfterTargetMap) { ...@@ -1484,7 +1484,7 @@ TEST(ReconfigureDataFieldAttribute_SameDataConstantAfterTargetMap) {
TestConfig() { TestConfig() {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
js_func_ = factory->NewFunction(factory->empty_string()); js_func_ = factory->NewFunctionForTest(factory->empty_string());
} }
Handle<Map> AddPropertyAtBranch(int branch_id, Expectations& expectations, Handle<Map> AddPropertyAtBranch(int branch_id, Expectations& expectations,
...@@ -1570,7 +1570,7 @@ TEST(ReconfigureDataFieldAttribute_DataConstantToAccConstantAfterTargetMap) { ...@@ -1570,7 +1570,7 @@ TEST(ReconfigureDataFieldAttribute_DataConstantToAccConstantAfterTargetMap) {
TestConfig() { TestConfig() {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
js_func_ = factory->NewFunction(factory->empty_string()); js_func_ = factory->NewFunctionForTest(factory->empty_string());
pair_ = CreateAccessorPair(true, true); pair_ = CreateAccessorPair(true, true);
} }
...@@ -2641,7 +2641,8 @@ TEST(TransitionDataConstantToSameDataConstant) { ...@@ -2641,7 +2641,8 @@ TEST(TransitionDataConstantToSameDataConstant) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<JSFunction> js_func = factory->NewFunction(factory->empty_string()); Handle<JSFunction> js_func =
factory->NewFunctionForTest(factory->empty_string());
TransitionToDataConstantOperator transition_op(js_func); TransitionToDataConstantOperator transition_op(js_func);
SameMapChecker checker; SameMapChecker checker;
...@@ -2688,7 +2689,8 @@ TEST(TransitionDataConstantToDataField) { ...@@ -2688,7 +2689,8 @@ TEST(TransitionDataConstantToDataField) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<FieldType> any_type = FieldType::Any(isolate); Handle<FieldType> any_type = FieldType::Any(isolate);
Handle<JSFunction> js_func1 = factory->NewFunction(factory->empty_string()); Handle<JSFunction> js_func1 =
factory->NewFunctionForTest(factory->empty_string());
TransitionToDataConstantOperator transition_op1(js_func1); TransitionToDataConstantOperator transition_op1(js_func1);
Handle<Object> value2 = isolate->factory()->NewHeapNumber(0); Handle<Object> value2 = isolate->factory()->NewHeapNumber(0);
......
...@@ -168,8 +168,8 @@ TEST(Regress2060a) { ...@@ -168,8 +168,8 @@ TEST(Regress2060a) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<JSFunction> function = factory->NewFunction( Handle<JSFunction> function =
factory->function_string()); factory->NewFunctionForTest(factory->function_string());
Handle<JSObject> key = factory->NewJSObject(function); Handle<JSObject> key = factory->NewJSObject(function);
Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
...@@ -209,8 +209,8 @@ TEST(Regress2060b) { ...@@ -209,8 +209,8 @@ TEST(Regress2060b) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<JSFunction> function = factory->NewFunction( Handle<JSFunction> function =
factory->function_string()); factory->NewFunctionForTest(factory->function_string());
// Start second old-space page so that keys land on evacuation candidate. // Start second old-space page so that keys land on evacuation candidate.
Page* first_page = heap->old_space()->anchor()->next_page(); Page* first_page = heap->old_space()->anchor()->next_page();
......
...@@ -167,8 +167,8 @@ TEST(WeakSet_Regress2060a) { ...@@ -167,8 +167,8 @@ TEST(WeakSet_Regress2060a) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<JSFunction> function = factory->NewFunction( Handle<JSFunction> function =
factory->function_string()); factory->NewFunctionForTest(factory->function_string());
Handle<JSObject> key = factory->NewJSObject(function); Handle<JSObject> key = factory->NewJSObject(function);
Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
...@@ -208,8 +208,8 @@ TEST(WeakSet_Regress2060b) { ...@@ -208,8 +208,8 @@ TEST(WeakSet_Regress2060b) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<JSFunction> function = factory->NewFunction( Handle<JSFunction> function =
factory->function_string()); factory->NewFunctionForTest(factory->function_string());
// Start second old-space page so that keys land on evacuation candidate. // Start second old-space page so that keys land on evacuation candidate.
Page* first_page = heap->old_space()->anchor()->next_page(); Page* first_page = heap->old_space()->anchor()->next_page();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment