aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/factory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/heap/factory.cc')
-rw-r--r--deps/v8/src/heap/factory.cc280
1 files changed, 169 insertions, 111 deletions
diff --git a/deps/v8/src/heap/factory.cc b/deps/v8/src/heap/factory.cc
index 03896f7827..19c3665622 100644
--- a/deps/v8/src/heap/factory.cc
+++ b/deps/v8/src/heap/factory.cc
@@ -580,7 +580,7 @@ Handle<ObjectBoilerplateDescription> Factory::NewObjectBoilerplateDescription(
if (has_different_size_backing_store) {
DCHECK_IMPLIES((boilerplate == (all_properties - index_keys)),
has_seen_proto);
- description->set_backing_store_size(isolate(), backing_store_size);
+ description->set_backing_store_size(backing_store_size);
}
description->set_flags(0);
@@ -1232,8 +1232,8 @@ Handle<String> Factory::NewConsString(Handle<String> left, Handle<String> right,
result->set_hash_field(String::kEmptyHashField);
result->set_length(length);
- result->set_first(isolate(), *left, mode);
- result->set_second(isolate(), *right, mode);
+ result->set_first(*left, mode);
+ result->set_second(*right, mode);
return result;
}
@@ -1314,7 +1314,7 @@ Handle<String> Factory::NewProperSubString(Handle<String> str, int begin,
slice->set_hash_field(String::kEmptyHashField);
slice->set_length(length);
- slice->set_parent(isolate(), *str);
+ slice->set_parent(*str);
slice->set_offset(offset);
return slice;
}
@@ -1483,7 +1483,7 @@ Handle<ScriptContextTable> Factory::NewScriptContextTable() {
return context_table;
}
-Handle<Context> Factory::NewModuleContext(Handle<Module> module,
+Handle<Context> Factory::NewModuleContext(Handle<SourceTextModule> module,
Handle<NativeContext> outer,
Handle<ScopeInfo> scope_info) {
DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE);
@@ -1611,17 +1611,7 @@ Handle<Context> Factory::NewBuiltinContext(Handle<NativeContext> native_context,
Handle<Struct> Factory::NewStruct(InstanceType type,
AllocationType allocation) {
- Map map;
- switch (type) {
-#define MAKE_CASE(TYPE, Name, name) \
- case TYPE: \
- map = *name##_map(); \
- break;
- STRUCT_LIST(MAKE_CASE)
-#undef MAKE_CASE
- default:
- UNREACHABLE();
- }
+ Map map = Map::GetStructMap(isolate(), type);
int size = map.instance_size();
HeapObject result = AllocateRawWithImmortalMap(size, allocation, map);
Handle<Struct> str(Struct::cast(result), isolate());
@@ -1640,10 +1630,17 @@ Handle<AliasedArgumentsEntry> Factory::NewAliasedArgumentsEntry(
Handle<AccessorInfo> Factory::NewAccessorInfo() {
Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(
NewStruct(ACCESSOR_INFO_TYPE, AllocationType::kOld));
+ DisallowHeapAllocation no_gc;
info->set_name(*empty_string());
info->set_flags(0); // Must clear the flags, it was initialized as undefined.
info->set_is_sloppy(true);
info->set_initial_property_attributes(NONE);
+
+ // Clear some other fields that should not be undefined.
+ info->set_getter(Smi::kZero);
+ info->set_setter(Smi::kZero);
+ info->set_js_getter(Smi::kZero);
+
return info;
}
@@ -1970,15 +1967,15 @@ Map Factory::InitializeMap(Map map, InstanceType type, int instance_size,
// |layout_descriptor| are set.
map.set_visitor_id(Map::GetVisitorId(map));
map.set_bit_field(0);
- map.set_bit_field2(Map::IsExtensibleBit::kMask);
+ map.set_bit_field2(Map::NewTargetIsBaseBit::encode(true));
int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) |
Map::OwnsDescriptorsBit::encode(true) |
- Map::ConstructionCounterBits::encode(Map::kNoSlackTracking);
+ Map::ConstructionCounterBits::encode(Map::kNoSlackTracking) |
+ Map::IsExtensibleBit::encode(true);
map.set_bit_field3(bit_field3);
DCHECK(!map.is_in_retained_map_list());
map.clear_padding();
map.set_elements_kind(elements_kind);
- map.set_new_target_is_base(true);
isolate()->counters()->maps_created()->Increment();
if (FLAG_trace_maps) LOG(isolate(), MapCreate(map));
return map;
@@ -2293,9 +2290,9 @@ Handle<Object> Factory::NewError(Handle<JSFunction> constructor,
// as the result.
Handle<Object> no_caller;
- MaybeHandle<Object> maybe_error =
- ErrorUtils::Construct(isolate(), constructor, constructor, message,
- SKIP_NONE, no_caller, false);
+ MaybeHandle<Object> maybe_error = ErrorUtils::Construct(
+ isolate(), constructor, constructor, message, SKIP_NONE, no_caller,
+ ErrorUtils::StackTraceCollection::kDetailed);
if (maybe_error.is_null()) {
DCHECK(isolate()->has_pending_exception());
maybe_error = handle(isolate()->pending_exception(), isolate());
@@ -2341,7 +2338,7 @@ Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
Handle<JSFunction> function(JSFunction::cast(New(map, allocation)),
isolate());
- function->initialize_properties();
+ function->initialize_properties(isolate());
function->initialize_elements();
function->set_shared(*info);
function->set_code(info->GetCode());
@@ -2563,9 +2560,10 @@ Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
AllocationType::kOld);
}
-Handle<ModuleInfo> Factory::NewModuleInfo() {
- return NewFixedArrayWithMap<ModuleInfo>(
- RootIndex::kModuleInfoMap, ModuleInfo::kLength, AllocationType::kOld);
+Handle<SourceTextModuleInfo> Factory::NewSourceTextModuleInfo() {
+ return NewFixedArrayWithMap<SourceTextModuleInfo>(
+ RootIndex::kModuleInfoMap, SourceTextModuleInfo::kLength,
+ AllocationType::kOld);
}
Handle<PreparseData> Factory::NewPreparseData(int data_length,
@@ -2585,15 +2583,14 @@ Handle<PreparseData> Factory::NewPreparseData(int data_length,
Handle<UncompiledDataWithoutPreparseData>
Factory::NewUncompiledDataWithoutPreparseData(Handle<String> inferred_name,
int32_t start_position,
- int32_t end_position,
- int32_t function_literal_id) {
+ int32_t end_position) {
Handle<UncompiledDataWithoutPreparseData> result(
UncompiledDataWithoutPreparseData::cast(New(
uncompiled_data_without_preparse_data_map(), AllocationType::kOld)),
isolate());
UncompiledData::Initialize(*result, *inferred_name, start_position,
- end_position, function_literal_id);
+ end_position);
return result;
}
@@ -2601,7 +2598,6 @@ Handle<UncompiledDataWithPreparseData>
Factory::NewUncompiledDataWithPreparseData(Handle<String> inferred_name,
int32_t start_position,
int32_t end_position,
- int32_t function_literal_id,
Handle<PreparseData> preparse_data) {
Handle<UncompiledDataWithPreparseData> result(
UncompiledDataWithPreparseData::cast(
@@ -2609,8 +2605,7 @@ Factory::NewUncompiledDataWithPreparseData(Handle<String> inferred_name,
isolate());
UncompiledDataWithPreparseData::Initialize(
- *result, *inferred_name, start_position, end_position,
- function_literal_id, *preparse_data);
+ *result, *inferred_name, start_position, end_position, *preparse_data);
return result;
}
@@ -2755,7 +2750,7 @@ Handle<JSObject> Factory::NewJSObjectWithNullProto(AllocationType allocation) {
Handle<Map> new_map = Map::Copy(
isolate(), Handle<Map>(result->map(), isolate()), "ObjectWithNullProto");
Map::SetPrototype(isolate(), new_map, null_value());
- JSObject::MigrateToMap(result, new_map);
+ JSObject::MigrateToMap(isolate(), result, new_map);
return result;
}
@@ -2886,12 +2881,14 @@ Handle<JSObject> Factory::NewJSObjectFromMap(
return js_obj;
}
-Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity,
- AllocationType allocation) {
+Handle<JSObject> Factory::NewSlowJSObjectFromMap(
+ Handle<Map> map, int capacity, AllocationType allocation,
+ Handle<AllocationSite> allocation_site) {
DCHECK(map->is_dictionary_map());
Handle<NameDictionary> object_properties =
NameDictionary::New(isolate(), capacity);
- Handle<JSObject> js_object = NewJSObjectFromMap(map, allocation);
+ Handle<JSObject> js_object =
+ NewJSObjectFromMap(map, allocation, allocation_site);
js_object->set_raw_properties_or_hash(*object_properties);
return js_object;
}
@@ -2910,43 +2907,54 @@ Handle<JSObject> Factory::NewSlowJSObjectWithPropertiesAndElements(
DCHECK(elements->IsNumberDictionary());
object_map =
JSObject::GetElementsTransitionMap(object, DICTIONARY_ELEMENTS);
- JSObject::MigrateToMap(object, object_map);
+ JSObject::MigrateToMap(isolate(), object, object_map);
object->set_elements(*elements);
}
return object;
}
-Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
- AllocationType allocation) {
- NativeContext native_context = isolate()->raw_native_context();
- Map map = native_context.GetInitialJSArrayMap(elements_kind);
- if (map.is_null()) {
- JSFunction array_function = native_context.array_function();
- map = array_function.initial_map();
- }
- return Handle<JSArray>::cast(
- NewJSObjectFromMap(handle(map, isolate()), allocation));
-}
-
Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, int length,
int capacity,
ArrayStorageAllocationMode mode,
AllocationType allocation) {
- Handle<JSArray> array = NewJSArray(elements_kind, allocation);
- NewJSArrayStorage(array, length, capacity, mode);
- return array;
+ DCHECK(capacity >= length);
+ if (capacity == 0) {
+ return NewJSArrayWithElements(empty_fixed_array(), elements_kind, length,
+ allocation);
+ }
+
+ HandleScope inner_scope(isolate());
+ Handle<FixedArrayBase> elms =
+ NewJSArrayStorage(elements_kind, capacity, mode);
+ return inner_scope.CloseAndEscape(NewJSArrayWithUnverifiedElements(
+ elms, elements_kind, length, allocation));
}
Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
ElementsKind elements_kind,
int length,
AllocationType allocation) {
- DCHECK(length <= elements->length());
- Handle<JSArray> array = NewJSArray(elements_kind, allocation);
+ Handle<JSArray> array = NewJSArrayWithUnverifiedElements(
+ elements, elements_kind, length, allocation);
+ JSObject::ValidateElements(*array);
+ return array;
+}
+Handle<JSArray> Factory::NewJSArrayWithUnverifiedElements(
+ Handle<FixedArrayBase> elements, ElementsKind elements_kind, int length,
+ AllocationType allocation) {
+ DCHECK(length <= elements->length());
+ NativeContext native_context = isolate()->raw_native_context();
+ Map map = native_context.GetInitialJSArrayMap(elements_kind);
+ if (map.is_null()) {
+ JSFunction array_function = native_context.array_function();
+ map = array_function.initial_map();
+ }
+ Handle<JSArray> array = Handle<JSArray>::cast(
+ NewJSObjectFromMap(handle(map, isolate()), allocation));
+ DisallowHeapAllocation no_gc;
array->set_elements(*elements);
array->set_length(Smi::FromInt(length));
- JSObject::ValidateElements(*array);
return array;
}
@@ -2961,8 +2969,17 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array, int length, int capacity,
}
HandleScope inner_scope(isolate());
+ Handle<FixedArrayBase> elms =
+ NewJSArrayStorage(array->GetElementsKind(), capacity, mode);
+
+ array->set_elements(*elms);
+ array->set_length(Smi::FromInt(length));
+}
+
+Handle<FixedArrayBase> Factory::NewJSArrayStorage(
+ ElementsKind elements_kind, int capacity, ArrayStorageAllocationMode mode) {
+ DCHECK_GT(capacity, 0);
Handle<FixedArrayBase> elms;
- ElementsKind elements_kind = array->GetElementsKind();
if (IsDoubleElementsKind(elements_kind)) {
if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
elms = NewFixedDoubleArray(capacity);
@@ -2979,9 +2996,7 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array, int length, int capacity,
elms = NewFixedArrayWithHoles(capacity);
}
}
-
- array->set_elements(*elms);
- array->set_length(Smi::FromInt(length));
+ return elms;
}
Handle<JSWeakMap> Factory::NewJSWeakMap() {
@@ -3020,9 +3035,10 @@ Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
return Handle<JSGeneratorObject>::cast(NewJSObjectFromMap(map));
}
-Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) {
- Handle<ModuleInfo> module_info(code->scope_info().ModuleDescriptorInfo(),
- isolate());
+Handle<SourceTextModule> Factory::NewSourceTextModule(
+ Handle<SharedFunctionInfo> code) {
+ Handle<SourceTextModuleInfo> module_info(
+ code->scope_info().ModuleDescriptorInfo(), isolate());
Handle<ObjectHashTable> exports =
ObjectHashTable::New(isolate(), module_info->RegularExportCount());
Handle<FixedArray> regular_exports =
@@ -3035,8 +3051,10 @@ Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) {
: empty_fixed_array();
ReadOnlyRoots roots(isolate());
- Handle<Module> module =
- Handle<Module>::cast(NewStruct(MODULE_TYPE, AllocationType::kOld));
+ Handle<SourceTextModule> module(
+ SourceTextModule::cast(
+ New(source_text_module_map(), AllocationType::kOld)),
+ isolate());
module->set_code(*code);
module->set_exports(*exports);
module->set_regular_exports(*regular_exports);
@@ -3053,6 +3071,28 @@ Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) {
return module;
}
+Handle<SyntheticModule> Factory::NewSyntheticModule(
+ Handle<String> module_name, Handle<FixedArray> export_names,
+ v8::Module::SyntheticModuleEvaluationSteps evaluation_steps) {
+ ReadOnlyRoots roots(isolate());
+ Handle<SyntheticModule> module(
+ SyntheticModule::cast(New(synthetic_module_map(), AllocationType::kOld)),
+ isolate());
+ Handle<ObjectHashTable> exports =
+ ObjectHashTable::New(isolate(), static_cast<int>(export_names->length()));
+ Handle<Foreign> evaluation_steps_foreign =
+ NewForeign(reinterpret_cast<i::Address>(evaluation_steps));
+ module->set_exports(*exports);
+ module->set_hash(isolate()->GenerateIdentityHash(Smi::kMaxValue));
+ module->set_module_namespace(roots.undefined_value());
+ module->set_status(Module::kUninstantiated);
+ module->set_exception(roots.the_hole_value());
+ module->set_name(*module_name);
+ module->set_export_names(*export_names);
+ module->set_evaluation_steps(*evaluation_steps_foreign);
+ return module;
+}
+
Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag shared,
AllocationType allocation) {
Handle<JSFunction> array_buffer_fun(
@@ -3274,7 +3314,7 @@ Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target,
DCHECK(map->prototype().IsNull(isolate()));
Handle<JSProxy> result(JSProxy::cast(New(map, AllocationType::kYoung)),
isolate());
- result->initialize_properties();
+ result->initialize_properties(isolate());
result->set_target(*target);
result->set_handler(*handler);
return result;
@@ -3335,10 +3375,12 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfoForLiteral(
false);
TRACE_EVENT_OBJECT_CREATED_WITH_ID(
TRACE_DISABLED_BY_DEFAULT("v8.compile"), "SharedFunctionInfo",
- TRACE_ID_WITH_SCOPE(SharedFunctionInfo::kTraceScope, shared->TraceID()));
+ TRACE_ID_WITH_SCOPE(SharedFunctionInfo::kTraceScope,
+ shared->TraceID(literal)));
TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
TRACE_DISABLED_BY_DEFAULT("v8.compile"), "SharedFunctionInfo",
- TRACE_ID_WITH_SCOPE(SharedFunctionInfo::kTraceScope, shared->TraceID()),
+ TRACE_ID_WITH_SCOPE(SharedFunctionInfo::kTraceScope,
+ shared->TraceID(literal)),
shared->ToTracedValue(literal));
return shared;
}
@@ -3447,6 +3489,7 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
*empty_feedback_metadata(), SKIP_WRITE_BARRIER);
}
share->set_script_or_debug_info(*undefined_value(), SKIP_WRITE_BARRIER);
+ share->set_function_literal_id(kFunctionLiteralIdInvalid);
#if V8_SFI_HAS_UNIQUE_ID
share->set_unique_id(isolate()->GetNextUniqueSharedFunctionInfoId());
#endif
@@ -3639,68 +3682,82 @@ Handle<StackTraceFrame> Factory::NewStackTraceFrame(
return frame;
}
-Handle<StackFrameInfo> Factory::NewStackFrameInfo() {
- Handle<StackFrameInfo> stack_frame_info = Handle<StackFrameInfo>::cast(
- NewStruct(STACK_FRAME_INFO_TYPE, AllocationType::kYoung));
- stack_frame_info->set_line_number(0);
- stack_frame_info->set_column_number(0);
- stack_frame_info->set_script_id(0);
- stack_frame_info->set_promise_all_index(-1);
- stack_frame_info->set_script_name(*null_value());
- stack_frame_info->set_script_name_or_source_url(*null_value());
- stack_frame_info->set_function_name(*null_value());
- stack_frame_info->set_flag(0);
- return stack_frame_info;
-}
-
Handle<StackFrameInfo> Factory::NewStackFrameInfo(
Handle<FrameArray> frame_array, int index) {
FrameArrayIterator it(isolate(), frame_array, index);
DCHECK(it.HasFrame());
- Handle<StackFrameInfo> info = NewStackFrameInfo();
- info->set_flag(0);
-
const bool is_wasm = frame_array->IsAnyWasmFrame(index);
- info->set_is_wasm(is_wasm);
+ StackFrameBase* frame = it.Frame();
- // Line numbers are 1-based, for Wasm we need to adjust.
- int line = it.Frame()->GetLineNumber();
- if (is_wasm && line >= 0) line++;
- info->set_line_number(line);
+ int line = frame->GetLineNumber();
+ int column = frame->GetColumnNumber();
- // Column numbers are 1-based. For Wasm we use the position
- // as the iterator does not currently provide a column number.
- const int column =
- is_wasm ? it.Frame()->GetPosition() + 1 : it.Frame()->GetColumnNumber();
- info->set_column_number(column);
+ const int script_id = frame->GetScriptId();
- info->set_script_id(it.Frame()->GetScriptId());
- info->set_script_name(*it.Frame()->GetFileName());
- info->set_script_name_or_source_url(*it.Frame()->GetScriptNameOrSourceUrl());
+ Handle<Object> script_name = frame->GetFileName();
+ Handle<Object> script_or_url = frame->GetScriptNameOrSourceUrl();
// TODO(szuend): Adjust this, once it is decided what name to use in both
// "simple" and "detailed" stack traces. This code is for
// backwards compatibility to fullfill test expectations.
- auto function_name = it.Frame()->GetFunctionName();
+ auto function_name = frame->GetFunctionName();
+ bool is_user_java_script = false;
if (!is_wasm) {
- Handle<Object> function = it.Frame()->GetFunction();
+ Handle<Object> function = frame->GetFunction();
if (function->IsJSFunction()) {
Handle<JSFunction> fun = Handle<JSFunction>::cast(function);
- function_name = JSFunction::GetDebugName(fun);
- const bool is_user_java_script = fun->shared().IsUserJavaScript();
- info->set_is_user_java_script(is_user_java_script);
+ is_user_java_script = fun->shared().IsUserJavaScript();
}
}
+
+ Handle<Object> method_name = undefined_value();
+ Handle<Object> type_name = undefined_value();
+ Handle<Object> eval_origin = frame->GetEvalOrigin();
+ Handle<Object> wasm_module_name = frame->GetWasmModuleName();
+
+ // MethodName and TypeName are expensive to look up, so they are only
+ // included when they are strictly needed by the stack trace
+ // serialization code.
+ // Note: The {is_method_call} predicate needs to be kept in sync with
+ // the corresponding predicate in the stack trace serialization code
+ // in stack-frame-info.cc.
+ const bool is_toplevel = frame->IsToplevel();
+ const bool is_constructor = frame->IsConstructor();
+ const bool is_method_call = !(is_toplevel || is_constructor);
+ if (is_method_call) {
+ method_name = frame->GetMethodName();
+ type_name = frame->GetTypeName();
+ }
+
+ Handle<StackFrameInfo> info = Handle<StackFrameInfo>::cast(
+ NewStruct(STACK_FRAME_INFO_TYPE, AllocationType::kYoung));
+
+ DisallowHeapAllocation no_gc;
+
+ info->set_flag(0);
+ info->set_is_wasm(is_wasm);
+ info->set_is_asmjs_wasm(frame_array->IsAsmJsWasmFrame(index));
+ info->set_is_user_java_script(is_user_java_script);
+ info->set_line_number(line);
+ info->set_column_number(column);
+ info->set_script_id(script_id);
+
+ info->set_script_name(*script_name);
+ info->set_script_name_or_source_url(*script_or_url);
info->set_function_name(*function_name);
- info->set_wasm_module_name(*it.Frame()->GetWasmModuleName());
- info->set_is_eval(it.Frame()->IsEval());
- info->set_is_constructor(it.Frame()->IsConstructor());
- info->set_is_toplevel(it.Frame()->IsToplevel());
- info->set_is_async(it.Frame()->IsAsync());
- info->set_is_promise_all(it.Frame()->IsPromiseAll());
- info->set_promise_all_index(it.Frame()->GetPromiseIndex());
+ info->set_method_name(*method_name);
+ info->set_type_name(*type_name);
+ info->set_eval_origin(*eval_origin);
+ info->set_wasm_module_name(*wasm_module_name);
+
+ info->set_is_eval(frame->IsEval());
+ info->set_is_constructor(is_constructor);
+ info->set_is_toplevel(is_toplevel);
+ info->set_is_async(frame->IsAsync());
+ info->set_is_promise_all(frame->IsPromiseAll());
+ info->set_promise_all_index(frame->GetPromiseIndex());
return info;
}
@@ -3785,7 +3842,8 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<NativeContext> context,
return map;
}
-Handle<LoadHandler> Factory::NewLoadHandler(int data_count) {
+Handle<LoadHandler> Factory::NewLoadHandler(int data_count,
+ AllocationType allocation) {
Handle<Map> map;
switch (data_count) {
case 1:
@@ -3800,7 +3858,7 @@ Handle<LoadHandler> Factory::NewLoadHandler(int data_count) {
default:
UNREACHABLE();
}
- return handle(LoadHandler::cast(New(map, AllocationType::kOld)), isolate());
+ return handle(LoadHandler::cast(New(map, allocation)), isolate());
}
Handle<StoreHandler> Factory::NewStoreHandler(int data_count) {