v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
factory.cc
Go to the documentation of this file.
1// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/heap/factory.h"
6
7#include <algorithm> // For copy
8#include <memory> // For shared_ptr<>
9#include <optional>
10#include <string>
11#include <utility> // For move
12
14#include "src/base/bits.h"
20#include "src/common/globals.h"
24#include "src/flags/flags.h"
26#include "src/heap/heap-inl.h"
38#include "src/logging/log.h"
45#include "src/objects/bigint.h"
74#include "src/objects/objects.h"
84#include "src/roots/roots-inl.h"
85#include "src/roots/roots.h"
86#include "src/sandbox/isolate.h"
88#if V8_ENABLE_WEBASSEMBLY
94#include "src/wasm/wasm-value.h"
95#endif
96
99
100namespace v8 {
101namespace internal {
102
105 : isolate_(isolate),
106 local_isolate_(isolate_->main_thread_local_isolate()),
107 code_desc_(desc),
108 kind_(kind) {}
109
111 const CodeDesc& desc, CodeKind kind)
112 : isolate_(local_isolate->GetMainThreadIsolateUnsafe()),
113 local_isolate_(local_isolate),
114 code_desc_(desc),
115 kind_(kind) {}
116
118 int length) {
119 return local_isolate_->factory()->NewTrustedByteArray(length);
120}
121
123 return local_isolate_->factory()->NewCode(options);
124}
125
127 bool retry_allocation_or_fail) {
129 NewTrustedByteArray(code_desc_.reloc_size);
130
131 // Basic block profiling data for builtins is stored in the JS heap rather
132 // than in separately-allocated C++ objects. Allocate that data now if
133 // appropriate.
134 DirectHandle<OnHeapBasicBlockProfilerData> on_heap_profiler_data;
135 if (V8_UNLIKELY(profiler_data_ && isolate_->IsGeneratingEmbeddedBuiltins())) {
136 on_heap_profiler_data = profiler_data_->CopyToJSHeap(isolate_);
137
138 // Add the on-heap data to a global list, which keeps it alive and allows
139 // iteration.
140 DirectHandle<ArrayList> list(isolate_->heap()->basic_block_profiling_data(),
141 isolate_);
143 isolate_, list, on_heap_profiler_data, AllocationType::kOld);
144 isolate_->heap()->SetBasicBlockProfilingData(new_list);
145 }
146
147 Tagged<HeapObject> istream_allocation =
148 AllocateUninitializedInstructionStream(retry_allocation_or_fail);
149 if (istream_allocation.is_null()) {
150 return {};
151 }
152
154 {
155 // The InstructionStream object has not been fully initialized yet. We
156 // rely on the fact that no allocation will happen from this point on.
159 istream_allocation,
160 ReadOnlyRoots(local_isolate_).instruction_stream_map(),
161 code_desc_.body_size(), code_desc_.constant_pool_offset, *reloc_info);
162 istream = handle(raw_istream, local_isolate_);
163 DCHECK(IsAligned(istream->instruction_start(), kCodeAlignment));
164 DCHECK_IMPLIES(!local_isolate_->heap()->heap()->code_region().is_empty(),
165 local_isolate_->heap()->heap()->code_region().contains(
166 istream->address()));
167 }
168
170 {
172
173 NewCodeOptions new_code_options = {
174 kind_,
175 builtin_,
176 is_context_specialized_,
177 is_turbofanned_,
178 parameter_count_,
179 code_desc_.instruction_size(),
180 code_desc_.metadata_size(),
181 inlined_bytecode_size_,
182 osr_offset_,
183 code_desc_.handler_table_offset_relative(),
184 code_desc_.constant_pool_offset_relative(),
185 code_desc_.code_comments_offset_relative(),
186 code_desc_.builtin_jump_table_info_offset_relative(),
187 code_desc_.unwinding_info_offset_relative(),
188 interpreter_data_,
189 deoptimization_data_,
190 bytecode_offset_table_,
192 istream,
193 /*instruction_start=*/kNullAddress,
194 };
195 code = NewCode(new_code_options);
196 DCHECK_EQ(istream->body_size(), code->body_size());
197
198 {
200 Tagged<InstructionStream> raw_istream = *istream;
201
202 // Allow self references to created code object by patching the handle to
203 // point to the newly allocated InstructionStream object.
204 Handle<Object> self_reference;
205 if (self_reference_.ToHandle(&self_reference)) {
206 DCHECK_EQ(*self_reference,
207 ReadOnlyRoots(isolate_).self_reference_marker());
208 DCHECK_NE(kind_, CodeKind::BASELINE);
209 if (isolate_->IsGeneratingEmbeddedBuiltins()) {
210 isolate_->builtins_constants_table_builder()->PatchSelfReference(
211 self_reference, istream);
212 }
213 self_reference.PatchValue(raw_istream);
214 }
215
216 // Likewise, any references to the basic block counters marker need to be
217 // updated to point to the newly-allocated counters array.
218 if (V8_UNLIKELY(!on_heap_profiler_data.is_null())) {
219 isolate_->builtins_constants_table_builder()
220 ->PatchBasicBlockCountersReference(
221 handle(on_heap_profiler_data->counts(), isolate_));
222 }
223
224 // Migrate generated code.
225 // The generated code can contain embedded objects (typically from
226 // handles) in a pointer-to-tagged-value format (i.e. with indirection
227 // like a handle) that are dereferenced during the copy to point
228 // directly to the actual heap objects. These pointers can include
229 // references to the code object itself, through the self_reference
230 // parameter.
231 istream->Finalize(*code, *reloc_info, code_desc_, isolate_->heap());
232
233#ifdef VERIFY_HEAP
234 if (v8_flags.verify_heap) {
235 HeapObject::VerifyCodePointer(isolate_, raw_istream);
236 }
237#endif
238 }
239 }
240
241 // TODO(leszeks): Remove stack_slots_, it's already in the instruction stream.
242 DCHECK_EQ(stack_slots_, code->stack_slots());
243
244#ifdef ENABLE_DISASSEMBLER
245 if (V8_UNLIKELY(profiler_data_ && v8_flags.turbo_profiling_verbose)) {
246 std::ostringstream os;
247 code->Disassemble(nullptr, os, isolate_);
248 if (!on_heap_profiler_data.is_null()) {
249 DirectHandle<String> disassembly =
250 local_isolate_->factory()->NewStringFromAsciiChecked(
251 os.str().c_str(), AllocationType::kOld);
252 on_heap_profiler_data->set_code(*disassembly);
253 } else {
254 profiler_data_->SetCode(os);
255 }
256 }
257#endif // ENABLE_DISASSEMBLER
258
259 return code;
260}
261
263 bool retry_allocation_or_fail) {
264 LocalHeap* heap = local_isolate_->heap();
266 const int object_size = InstructionStream::SizeFor(code_desc_.body_size());
267 if (retry_allocation_or_fail) {
268 // Only allowed to do `retry_allocation_or_fail` from the main thread.
269 // TODO(leszeks): Remove the retrying allocation, always use TryBuild in
270 // the code builder.
271 DCHECK(local_isolate_->is_main_thread());
272 result =
273 heap->heap()->allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
275 CHECK(!result.is_null());
276 return result;
277 } else {
278 // Return null if we cannot allocate the code object.
279 return heap->AllocateRawWith<HeapAllocator::kLightRetry>(
280 object_size, AllocationType::kCode);
281 }
282}
283
285 return BuildInternal(false);
286}
287
289 return BuildInternal(true).ToHandleChecked();
290}
291
297
299 DirectHandle<Map> map, AllocationType allocation,
300 DirectHandle<AllocationSite> allocation_site) {
301 DCHECK_NE(map->instance_type(), MAP_TYPE);
302 const auto [write_barrier_mode, should_allocate_memento] =
303 allocation == AllocationType::kYoung
304 ? std::pair{SKIP_WRITE_BARRIER, !allocation_site.is_null()}
305 : std::pair{UPDATE_WRITE_BARRIER, false};
306 DCHECK_IMPLIES(should_allocate_memento, V8_ALLOCATION_SITE_TRACKING_BOOL);
307 const int instance_size = map->instance_size();
308 const int allocation_size =
309 should_allocate_memento
310 ? instance_size +
312 : instance_size;
315 allocation);
316 result->set_map_after_allocation(isolate(), *map, write_barrier_mode);
317 if (should_allocate_memento) {
318 const int aligned_size = ALIGN_TO_ALLOCATION_ALIGNMENT(instance_size);
320 Tagged<Object>(result.ptr() + aligned_size));
321 InitializeAllocationMemento(alloc_memento, *allocation_site);
322 }
323 return result;
324}
325
327 Tagged<AllocationMemento> memento, Tagged<AllocationSite> allocation_site) {
329 memento->set_map_after_allocation(isolate(), *allocation_memento_map(),
331 memento->set_allocation_site(allocation_site, SKIP_WRITE_BARRIER);
332 if (v8_flags.allocation_site_pretenuring) {
333 allocation_site->IncrementMementoCreateCount();
334 }
335}
336
338 AllocationType allocation) {
339 DCHECK(map->instance_type() != MAP_TYPE);
340 int size = map->instance_size();
343 allocation);
344 // New space objects are allocated white.
345 WriteBarrierMode write_barrier_mode = allocation == AllocationType::kYoung
348 result->set_map_after_allocation(isolate(), *map, write_barrier_mode);
349 return result;
350}
351
353 AllocationAlignment alignment,
354 AllocationType allocation,
355 AllocationOrigin origin) {
356 Heap* heap = isolate()->heap();
359 size, allocation, origin, alignment);
360 heap->CreateFillerObjectAt(result.address(), size);
362}
363
365 auto result = NewStructInternal<PrototypeInfo>(PROTOTYPE_INFO_TYPE,
368 result->set_prototype_users(Smi::zero());
369 result->set_registry_slot(MemoryChunk::UNREGISTERED);
370 result->set_bit_field(0);
371 result->set_module_namespace(*undefined_value(), SKIP_WRITE_BARRIER);
372 return direct_handle(result, isolate());
373}
374
377 AllocationType allocation) {
378 DCHECK(allocation == AllocationType::kOld ||
379 allocation == AllocationType::kSharedOld);
383 auto result = NewStructInternal<EnumCache>(ENUM_CACHE_TYPE, allocation);
385 result->set_keys(*keys);
386 result->set_indices(*indices);
387 return direct_handle(result, isolate());
388}
389
391 AllocationType allocation) {
392 auto result = NewStructInternal<Tuple2>(TUPLE2_TYPE, allocation);
393 return direct_handle(result, isolate());
394}
395
398 AllocationType allocation) {
399 auto result = NewStructInternal<Tuple2>(TUPLE2_TYPE, allocation);
401 result->set_value1(*value1);
402 result->set_value2(*value2);
403 return direct_handle(result, isolate());
404}
405
409 Hole::Initialize(isolate(), hole, hole_nan_value());
410 return hole;
411}
412
414 int length, AllocationType allocation) {
415 DCHECK_LE(0, length);
416 if (length == 0) return empty_property_array();
417 Tagged<HeapObject> result = AllocateRawFixedArray(length, allocation);
419 result->set_map_after_allocation(isolate(), *property_array_map(),
422 array->initialize_length(length);
423 MemsetTagged(array->data_start(), read_only_roots().undefined_value(),
424 length);
425 return direct_handle(array, isolate());
426}
427
429 int length, AllocationType allocation_type) {
430 DCHECK_LE(0, length);
431 if (length == 0) return empty_fixed_array();
432
433 int size = FixedArray::SizeFor(length);
434 Heap* heap = isolate()->heap();
435 AllocationResult allocation = heap->AllocateRaw(size, allocation_type);
437 if (!allocation.To(&result)) return MaybeHandle<FixedArray>();
438 if ((size > heap->MaxRegularHeapObjectSize(allocation_type)) &&
439 v8_flags.use_marking_progress_bar) {
442 .Enable(size);
443 }
445 result->set_map_after_allocation(isolate(), *fixed_array_map(),
448 array->set_length(length);
449 MemsetTagged(array->RawFieldOfFirstElement(), *undefined_value(), length);
450 return handle(array, isolate());
451}
452
455 DirectHandle<ClosureFeedbackCellArray> closure_feedback_cell_array,
456 DirectHandle<FeedbackCell> parent_feedback_cell) {
457 int length = shared->feedback_metadata()->slot_count();
458 DCHECK_LE(0, length);
459 int size = FeedbackVector::SizeFor(length);
460
463 size, AllocationType::kOld, *feedback_vector_map()));
465 vector->set_shared_function_info(*shared);
466 vector->set_length(length);
467 vector->set_invocation_count(0);
468 vector->set_invocation_count_before_stable(0);
469 vector->reset_osr_state();
470 vector->reset_flags();
471#ifndef V8_ENABLE_LEAPTIERING
472 vector->set_maybe_optimized_code(ClearedValue(isolate()));
473 vector->set_log_next_execution(v8_flags.log_function_events);
474#endif // !V8_ENABLE_LEAPTIERING
475 vector->set_closure_feedback_cell_array(*closure_feedback_cell_array);
476 vector->set_parent_feedback_cell(*parent_feedback_cell);
477
478 // TODO(leszeks): Initialize based on the feedback metadata.
479 MemsetTagged(ObjectSlot(vector->slots_start()), *undefined_value(), length);
480 return handle(vector, isolate());
481}
482
484 DCHECK_LE(0, length);
485 int size = EmbedderDataArray::SizeFor(length);
488 size, AllocationType::kYoung, *embedder_data_array_map()));
490 array->set_length(length);
491
492 if (length > 0) {
493 for (int i = 0; i < length; i++) {
494 // TODO(v8): consider initializing embedded data array with Smi::zero().
495 EmbedderDataSlot(array, i).Initialize(*undefined_value());
496 }
497 }
498 return direct_handle(array, isolate());
499}
500
502 DCHECK_LE(0, length);
504 if (length > 0) {
505 Cast<FixedDoubleArray>(array)->FillWithHoles(0, length);
506 }
507 return array;
508}
509
510template <typename T>
512 int capacity,
513 AllocationType allocation) {
514 // Capacity must be a power of two, since we depend on being able
515 // to divide and multiple by 2 (kLoadFactor) to derive capacity
516 // from number of buckets. If we decide to change kLoadFactor
517 // to something other than 2, capacity should be stored as another
518 // field of this object.
519 DCHECK_EQ(T::kLoadFactor, 2);
520 capacity =
521 base::bits::RoundUpToPowerOfTwo32(std::max({T::kMinCapacity, capacity}));
522 capacity = std::min({capacity, T::kMaxCapacity});
523
524 DCHECK_LT(0, capacity);
525 DCHECK_EQ(0, capacity % T::kLoadFactor);
526
527 int size = T::SizeFor(capacity);
529 AllocateRawWithImmortalMap(size, allocation, *map);
530 Handle<T> table(Cast<T>(result), isolate());
531 table->Initialize(isolate(), capacity);
532 return table;
533}
534
536 int capacity, AllocationType allocation) {
538 small_ordered_hash_set_map(), capacity, allocation);
539}
540
542 int capacity, AllocationType allocation) {
544 small_ordered_hash_map_map(), capacity, allocation);
545}
546
548 int capacity, AllocationType allocation) {
551 small_ordered_name_dictionary_map(), capacity, allocation);
552 dict->SetHash(PropertyArray::kNoHashSentinel);
553 return dict;
554}
555
561
567
569 int at_least_space_for) {
570 return NameDictionary::New(isolate(), at_least_space_for);
571}
572
575 PROPERTY_DESCRIPTOR_OBJECT_TYPE, AllocationType::kYoung);
577 object->set_flags(0);
578 Tagged<Hole> the_hole = read_only_roots().the_hole_value();
579 object->set_value(the_hole, SKIP_WRITE_BARRIER);
580 object->set_get(the_hole, SKIP_WRITE_BARRIER);
581 object->set_set(the_hole, SKIP_WRITE_BARRIER);
582 return direct_handle(object, isolate());
583}
584
587 // This function is only supposed to be used to create the canonical empty
588 // version and should not be used afterwards.
589 DCHECK(!ReadOnlyRoots(isolate()).is_initialized(
590 RootIndex::kEmptySwissPropertyDictionary));
591
592 ReadOnlyRoots roots(isolate());
593
594 DirectHandle<ByteArray> empty_meta_table =
597
598 Tagged<Map> map = roots.swiss_name_dictionary_map();
599 int size = SwissNameDictionary::SizeFor(0);
603 result->Initialize(isolate(), *empty_meta_table, 0);
604 return direct_handle(result, isolate());
605}
606
607// Internalized strings are created in the old generation (data space).
611 Utf8Decoder decoder(utf8_data);
612 if (decoder.is_ascii()) return InternalizeString(utf8_data);
613 if (decoder.is_one_byte()) {
614 std::unique_ptr<uint8_t[]> buffer(new uint8_t[decoder.utf16_length()]);
615 decoder.Decode(buffer.get(), utf8_data);
616 return InternalizeString(
617 base::Vector<const uint8_t>(buffer.get(), decoder.utf16_length()));
618 }
619 std::unique_ptr<uint16_t[]> buffer(new uint16_t[decoder.utf16_length()]);
620 decoder.Decode(buffer.get(), utf8_data);
621 return InternalizeString(
622 base::Vector<const base::uc16>(buffer.get(), decoder.utf16_length()));
623}
624
625template <typename SeqString, template <typename> typename HandleType>
626 requires(
627 std::is_convertible_v<HandleType<SeqString>, DirectHandle<SeqString>>)
629 uint32_t from, uint32_t length,
630 bool convert_encoding) {
631 // Callers should handle the empty and one-char case themselves.
632 DCHECK_GT(length, 1);
633 DCHECK_IMPLIES(from == 0, length != string->length());
634 SeqSubStringKey<SeqString> key(isolate(), string, from, length,
635 convert_encoding);
637}
638
640 Handle<SeqOneByteString> string, uint32_t from, uint32_t length,
641 bool convert_encoding);
643 Handle<SeqTwoByteString> string, uint32_t from, uint32_t length,
644 bool convert_encoding);
646 DirectHandle<SeqOneByteString> string, uint32_t from, uint32_t length,
647 bool convert_encoding);
649 DirectHandle<SeqTwoByteString> string, uint32_t from, uint32_t length,
650 bool convert_encoding);
651
652namespace {
653void ThrowInvalidEncodedStringBytes(Isolate* isolate, MessageTemplate message) {
654#if V8_ENABLE_WEBASSEMBLY
655 DCHECK(message == MessageTemplate::kWasmTrapStringInvalidWtf8 ||
656 message == MessageTemplate::kWasmTrapStringInvalidUtf8);
657 DirectHandle<JSObject> error_obj =
658 isolate->factory()->NewWasmRuntimeError(message);
659 JSObject::AddProperty(isolate, error_obj,
660 isolate->factory()->wasm_uncatchable_symbol(),
661 isolate->factory()->true_value(), NONE);
662 isolate->Throw(*error_obj);
663#else
664 // The default in JS-land is to use Utf8Variant::kLossyUtf8, which never
665 // throws an error, so if there is no WebAssembly compiled in we'll never
666 // get here.
667 UNREACHABLE();
668#endif // V8_ENABLE_WEBASSEMBLY
669}
670
671template <typename Decoder, typename PeekBytes>
672MaybeHandle<String> NewStringFromBytes(Isolate* isolate, PeekBytes peek_bytes,
673 AllocationType allocation,
674 MessageTemplate message) {
675 Decoder decoder(peek_bytes());
676 if (decoder.is_invalid()) {
677 if (message != MessageTemplate::kNone) {
678 ThrowInvalidEncodedStringBytes(isolate, message);
679 }
680 return MaybeHandle<String>();
681 }
682
683 if (decoder.utf16_length() == 0) return isolate->factory()->empty_string();
684
685 if (decoder.is_one_byte()) {
686 if (decoder.utf16_length() == 1) {
687 uint8_t codepoint;
688 decoder.Decode(&codepoint, peek_bytes());
689 return isolate->factory()->LookupSingleCharacterStringFromCode(codepoint);
690 }
691 // Allocate string.
694 isolate->factory()->NewRawOneByteString(
695 decoder.utf16_length(), allocation));
696
698 decoder.Decode(result->GetChars(no_gc), peek_bytes());
699 return result;
700 }
701
702 // Allocate string.
705 isolate->factory()->NewRawTwoByteString(
706 decoder.utf16_length(), allocation));
707
709 decoder.Decode(result->GetChars(no_gc), peek_bytes());
710 return result;
711}
712
713template <typename PeekBytes>
714MaybeHandle<String> NewStringFromUtf8Variant(Isolate* isolate,
715 PeekBytes peek_bytes,
716 unibrow::Utf8Variant utf8_variant,
717 AllocationType allocation) {
718 switch (utf8_variant) {
720 return NewStringFromBytes<Utf8Decoder>(isolate, peek_bytes, allocation,
721 MessageTemplate::kNone);
722#if V8_ENABLE_WEBASSEMBLY
723 case unibrow::Utf8Variant::kUtf8:
724 return NewStringFromBytes<StrictUtf8Decoder>(
725 isolate, peek_bytes, allocation,
726 MessageTemplate::kWasmTrapStringInvalidUtf8);
727 case unibrow::Utf8Variant::kUtf8NoTrap:
728 return NewStringFromBytes<StrictUtf8Decoder>(
729 isolate, peek_bytes, allocation, MessageTemplate::kNone);
730 case unibrow::Utf8Variant::kWtf8:
731 return NewStringFromBytes<Wtf8Decoder>(
732 isolate, peek_bytes, allocation,
733 MessageTemplate::kWasmTrapStringInvalidWtf8);
734#endif
735 }
736}
737
738} // namespace
739
742 AllocationType allocation) {
743 if (string.size() > kMaxInt) {
744 // The Utf8Decode can't handle longer inputs, and we couldn't create
745 // strings from them anyway.
747 }
748 auto peek_bytes = [&]() -> base::Vector<const uint8_t> { return string; };
749 return NewStringFromUtf8Variant(isolate(), peek_bytes, utf8_variant,
750 allocation);
751}
752
758
759#if V8_ENABLE_WEBASSEMBLY
761 DirectHandle<WasmArray> array, uint32_t start, uint32_t end,
762 unibrow::Utf8Variant utf8_variant, AllocationType allocation) {
763 DCHECK_EQ(sizeof(uint8_t), WasmArray::DecodeElementSizeFromMap(array->map()));
765 DCHECK_LE(end, array->length());
766 // {end - start} can never be more than what the Utf8Decoder can handle.
767 static_assert(WasmArray::MaxLength(sizeof(uint8_t)) <= kMaxInt);
768 auto peek_bytes = [&]() -> base::Vector<const uint8_t> {
769 const uint8_t* contents =
770 reinterpret_cast<const uint8_t*>(array->ElementAddress(0));
771 return {contents + start, end - start};
772 };
773 return NewStringFromUtf8Variant(isolate(), peek_bytes, utf8_variant,
774 allocation);
775}
776
777MaybeHandle<String> Factory::NewStringFromUtf8(
778 DirectHandle<ByteArray> array, uint32_t start, uint32_t end,
779 unibrow::Utf8Variant utf8_variant, AllocationType allocation) {
781 DCHECK_LE(end, array->length());
782 // {end - start} can never be more than what the Utf8Decoder can handle.
783 static_assert(ByteArray::kMaxLength <= kMaxInt);
784 auto peek_bytes = [&]() -> base::Vector<const uint8_t> {
785 const uint8_t* contents = reinterpret_cast<const uint8_t*>(array->begin());
786 return {contents + start, end - start};
787 };
788 return NewStringFromUtf8Variant(isolate(), peek_bytes, utf8_variant,
789 allocation);
790}
791
792namespace {
793struct Wtf16Decoder {
794 int length_;
795 bool is_one_byte_;
796 explicit Wtf16Decoder(base::Vector<const uint16_t> data)
797 : length_(data.length()),
798 is_one_byte_(String::IsOneByte(data.begin(), length_)) {}
799 bool is_invalid() const { return false; }
800 bool is_one_byte() const { return is_one_byte_; }
801 int utf16_length() const { return length_; }
802 template <typename Char>
803 void Decode(Char* out, base::Vector<const uint16_t> data) {
804 CopyChars(out, data.begin(), length_);
805 }
806};
807} // namespace
808
809MaybeDirectHandle<String> Factory::NewStringFromUtf16(
810 DirectHandle<WasmArray> array, uint32_t start, uint32_t end,
811 AllocationType allocation) {
812 DCHECK_EQ(sizeof(uint16_t),
815 DCHECK_LE(end, array->length());
816 // {end - start} can never be more than what the Utf8Decoder can handle.
817 static_assert(WasmArray::MaxLength(sizeof(uint16_t)) <= kMaxInt);
818 auto peek_bytes = [&]() -> base::Vector<const uint16_t> {
819 const uint16_t* contents =
820 reinterpret_cast<const uint16_t*>(array->ElementAddress(0));
821 return {contents + start, end - start};
822 };
823 return NewStringFromBytes<Wtf16Decoder>(isolate(), peek_bytes, allocation,
824 MessageTemplate::kNone);
825}
826#endif // V8_ENABLE_WEBASSEMBLY
827
829 Handle<SeqOneByteString> str, int begin, int length,
830 AllocationType allocation) {
832 {
834 utf8_data =
835 base::Vector<const uint8_t>(str->GetChars(no_gc) + begin, length);
836 }
837 Utf8Decoder decoder(utf8_data);
838
839 if (length == 1) {
840 uint16_t t;
841 // Decode even in the case of length 1 since it can be a bad character.
842 decoder.Decode(&t, utf8_data);
844 }
845
846 if (decoder.is_ascii()) {
847 // If the string is ASCII, we can just make a substring.
848 // TODO(v8): the allocation flag is ignored in this case.
849 return NewSubString(str, begin, begin + length);
850 }
851
852 DCHECK_GT(decoder.utf16_length(), 0);
853
854 if (decoder.is_one_byte()) {
855 // Allocate string.
858 isolate(), result,
859 NewRawOneByteString(decoder.utf16_length(), allocation));
861 // Update pointer references, since the original string may have moved after
862 // allocation.
863 utf8_data =
864 base::Vector<const uint8_t>(str->GetChars(no_gc) + begin, length);
865 decoder.Decode(result->GetChars(no_gc), utf8_data);
866 return result;
867 }
868
869 // Allocate string.
872 isolate(), result,
873 NewRawTwoByteString(decoder.utf16_length(), allocation));
874
876 // Update pointer references, since the original string may have moved after
877 // allocation.
878 utf8_data = base::Vector<const uint8_t>(str->GetChars(no_gc) + begin, length);
879 decoder.Decode(result->GetChars(no_gc), utf8_data);
880 return result;
881}
882
884 int length,
885 AllocationType allocation) {
887 if (length == 0) return empty_string();
888 if (String::IsOneByte(string, length)) {
889 if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
892 NewRawOneByteString(length, allocation));
894 CopyChars(result->GetChars(no_gc), string, length);
895 return result;
896 } else {
899 NewRawTwoByteString(length, allocation));
901 CopyChars(result->GetChars(no_gc), string, length);
902 return result;
903 }
904}
905
908 return NewStringFromTwoByte(string.begin(), string.length(), allocation);
909}
910
912 const ZoneVector<base::uc16>* string, AllocationType allocation) {
913 return NewStringFromTwoByte(string->data(), static_cast<int>(string->size()),
914 allocation);
915}
916
917#if V8_ENABLE_WEBASSEMBLY
918MaybeDirectHandle<String> Factory::NewStringFromTwoByteLittleEndian(
920#if defined(V8_TARGET_LITTLE_ENDIAN)
921 return NewStringFromTwoByte(str, allocation);
922#elif defined(V8_TARGET_BIG_ENDIAN)
923 // TODO(12868): Duplicate the guts of NewStringFromTwoByte, so that
924 // copying and transcoding the data can be done in a single pass.
926#else
927#error Unknown endianness
928#endif
929}
930#endif // V8_ENABLE_WEBASSEMBLY
931
933 DirectHandle<String> string, int len, uint32_t hash_field) {
934 if (string->IsOneByteRepresentation()) {
938 String::WriteToFlat(*string, result->GetChars(no_gc), 0, len);
939 return result;
940 }
941
945 String::WriteToFlat(*string, result->GetChars(no_gc), 0, len);
946 return result;
947}
948
950 DirectHandle<String> string, MaybeDirectHandle<Map>* internalized_map) {
951 // The serializer requires internalized strings to be in ReadOnlySpace s.t.
952 // other objects referencing the string can be allocated in RO space
953 // themselves.
954 if (isolate()->enable_ro_allocation_for_snapshot() &&
955 isolate()->serializer_enabled()) {
957 }
958 // Do not internalize young strings in-place: This allows us to ignore both
959 // string table and stub cache on scavenges.
960 if (HeapLayout::InYoungGeneration(*string)) {
962 }
963 // If the string table is shared, we need to copy if the string is not already
964 // in the shared heap.
965 if (v8_flags.shared_string_table && !HeapLayout::InAnySharedSpace(*string)) {
967 }
968 DCHECK_NOT_NULL(internalized_map);
970 // This method may be called concurrently, so snapshot the map from the input
971 // string instead of the calling IsType methods on HeapObject, which would
972 // reload the map each time.
973 Tagged<Map> map = string->map();
974 *internalized_map = GetInPlaceInternalizedStringMap(map);
975 if (!internalized_map->is_null()) {
977 }
980 }
982}
983
984template <class StringClass>
986 DirectHandle<String> string) {
988 GetInPlaceInternalizedStringMap(string->map()).ToHandleChecked();
989 Tagged<StringClass> external_string =
992 external_string->InitExternalPointerFields(isolate());
993 Tagged<StringClass> cast_string = Cast<StringClass>(*string);
994 external_string->set_length(cast_string->length());
995 external_string->set_raw_hash_field(cast_string->raw_hash_field());
996 external_string->SetResource(isolate(), nullptr);
997 isolate()->heap()->RegisterExternalString(external_string);
998 return direct_handle(external_string, isolate());
999}
1000
1005
1007 DirectHandle<String> string, MaybeDirectHandle<Map>* shared_map) {
1008 DCHECK(v8_flags.shared_string_table);
1009 // TODO(pthier): Avoid copying LO-space strings. Update page flags instead.
1010 if (!HeapLayout::InAnySharedSpace(*string)) {
1012 }
1013 DCHECK_NOT_NULL(shared_map);
1015 InstanceType instance_type = string->map()->instance_type();
1016 if (StringShape(instance_type).IsShared()) {
1018 }
1019 switch (instance_type) {
1021 *shared_map = shared_seq_two_byte_string_map();
1024 *shared_map = shared_seq_one_byte_string_map();
1027 *shared_map = shared_external_two_byte_string_map();
1030 *shared_map = shared_external_one_byte_string_map();
1033 *shared_map = shared_uncached_external_two_byte_string_map();
1036 *shared_map = shared_uncached_external_one_byte_string_map();
1038 default:
1040 }
1041}
1042
1044 uint16_t trail) {
1045 DCHECK_GE(lead, 0xD800);
1046 DCHECK_LE(lead, 0xDBFF);
1047 DCHECK_GE(trail, 0xDC00);
1048 DCHECK_LE(trail, 0xDFFF);
1049
1051 isolate()->factory()->NewRawTwoByteString(2).ToHandleChecked();
1053 base::uc16* dest = str->GetChars(no_gc);
1054 dest[0] = lead;
1055 dest[1] = trail;
1056 return str;
1057}
1058
1060 uint32_t begin, uint32_t length) {
1061 DCHECK(str->IsFlat()); // Callers must flatten.
1062 DCHECK_GT(length, 0); // Callers must handle empty string.
1063 bool one_byte;
1064 {
1066 String::FlatContent flat = str->GetFlatContent(no_gc);
1067 if (flat.IsOneByte()) {
1068 one_byte = true;
1069 } else {
1070 one_byte = String::IsOneByte(flat.ToUC16Vector().data() + begin, length);
1071 }
1072 }
1073 if (one_byte) {
1075 NewRawOneByteString(length).ToHandleChecked();
1077 uint8_t* dest = result->GetChars(no_gc);
1078 String::WriteToFlat(*str, dest, begin, length);
1079 return result;
1080 } else {
1082 NewRawTwoByteString(length).ToHandleChecked();
1084 base::uc16* dest = result->GetChars(no_gc);
1085 String::WriteToFlat(*str, dest, begin, length);
1086 return result;
1087 }
1088}
1089
1091 uint32_t begin, uint32_t end) {
1092#if VERIFY_HEAP
1093 if (v8_flags.verify_heap) str->StringVerify(isolate());
1094#endif
1095 DCHECK_LE(begin, str->length());
1096 DCHECK_LE(end, str->length());
1097
1098 str = String::Flatten(isolate(), str);
1099
1100 if (begin >= end) return empty_string();
1101 uint32_t length = end - begin;
1102
1103 if (length == 1) {
1104 return LookupSingleCharacterStringFromCode(str->Get(begin));
1105 }
1106 if (length == 2) {
1107 // Optimization for 2-byte strings often used as keys in a decompression
1108 // dictionary. Check whether we already have the string in the string
1109 // table to prevent creation of many unnecessary strings.
1110 uint16_t c1 = str->Get(begin);
1111 uint16_t c2 = str->Get(begin + 1);
1112 return MakeOrFindTwoCharacterString(c1, c2);
1113 }
1114
1115 if (!v8_flags.string_slices || length < SlicedString::kMinLength) {
1116 return NewCopiedSubstring(str, begin, length);
1117 }
1118
1119 int offset = begin;
1120
1121 if (IsSlicedString(*str)) {
1122 auto slice = Cast<SlicedString>(str);
1123 str = direct_handle(slice->parent(), isolate());
1124 offset += slice->offset();
1125 }
1126 if (IsThinString(*str)) {
1127 auto thin = Cast<ThinString>(str);
1128 str = direct_handle(thin->actual(), isolate());
1129 }
1130
1131 DCHECK(IsSeqString(*str) || IsExternalString(*str));
1132 DirectHandle<Map> map = str->IsOneByteRepresentation()
1133 ? sliced_one_byte_string_map()
1134 : sliced_two_byte_string_map();
1135 Tagged<SlicedString> slice =
1138 slice->set_raw_hash_field(String::kEmptyHashField);
1139 slice->set_length(length);
1140 slice->set_parent(*str);
1141 slice->set_offset(offset);
1142 return handle(slice, isolate());
1143}
1144
1146 const ExternalOneByteString::Resource* resource) {
1147 size_t length = resource->length();
1148 if (length > static_cast<size_t>(String::kMaxLength)) {
1150 }
1151 if (length == 0) return empty_string();
1152
1153 DirectHandle<Map> map = resource->IsCacheable()
1154 ? external_one_byte_string_map()
1155 : uncached_external_one_byte_string_map();
1156 Tagged<ExternalOneByteString> external_string =
1159 external_string->InitExternalPointerFields(isolate());
1160 external_string->set_length(static_cast<int>(length));
1161 external_string->set_raw_hash_field(String::kEmptyHashField);
1162 external_string->SetResource(isolate(), resource);
1163
1164 isolate()->heap()->RegisterExternalString(external_string);
1165
1166 return Handle<String>(external_string, isolate());
1167}
1168
1170 const ExternalTwoByteString::Resource* resource) {
1171 size_t length = resource->length();
1172 if (length > static_cast<size_t>(String::kMaxLength)) {
1174 }
1175 if (length == 0) return empty_string();
1176
1177 DirectHandle<Map> map = resource->IsCacheable()
1178 ? external_two_byte_string_map()
1179 : uncached_external_two_byte_string_map();
1183 string->InitExternalPointerFields(isolate());
1184 string->set_length(static_cast<int>(length));
1185 string->set_raw_hash_field(String::kEmptyHashField);
1186 string->SetResource(isolate(), resource);
1187
1188 isolate()->heap()->RegisterExternalString(string);
1189
1190 return Handle<ExternalTwoByteString>(string, isolate());
1191}
1192
1194 Handle<String> string) {
1196 isolate()->native_context()->initial_string_iterator_map(), isolate());
1197 DirectHandle<String> flat_string = String::Flatten(isolate(), string);
1200
1202 Tagged<JSStringIterator> raw = *iterator;
1203 raw->set_string(*flat_string);
1204 raw->set_index(0);
1205 return iterator;
1206}
1207
1209 DCHECK(allocation != AllocationType::kYoung);
1210 // Statically ensure that it is safe to allocate symbols in paged spaces.
1211 static_assert(sizeof(Symbol) <= kMaxRegularHeapObjectSize);
1212
1214 sizeof(Symbol), allocation, read_only_roots().symbol_map()));
1216 // Generate a random hash value.
1218 symbol->set_raw_hash_field(
1220 if (isolate()->read_only_heap()->roots_init_complete()) {
1221 symbol->set_description(read_only_roots().undefined_value(),
1223 } else {
1224 // Can't use setter during bootstrapping as its typecheck tries to access
1225 // the roots table before it is initialized.
1226 symbol->description_.store(&*symbol, read_only_roots().undefined_value(),
1228 }
1229 symbol->set_flags(0);
1230 DCHECK(!symbol->is_private());
1231 return symbol;
1232}
1233
1235 return handle(NewSymbolInternal(allocation), isolate());
1236}
1237
1239 DCHECK(allocation != AllocationType::kYoung);
1240 Tagged<Symbol> symbol = NewSymbolInternal(allocation);
1242 symbol->set_is_private(true);
1243 return handle(symbol, isolate());
1244}
1245
1249 symbol->set_is_private_name();
1250 symbol->set_description(*name);
1251 return direct_handle(symbol, isolate());
1252}
1253
1255 int variadic_part_length,
1256 AllocationType allocation) {
1259 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, variadic_part_length);
1260 DCHECK_LE(Context::SizeFor(variadic_part_length), size);
1261
1264 allocation);
1265 result->set_map_after_allocation(isolate(), *map);
1268 context->set_length(variadic_part_length);
1269 DCHECK_EQ(context->SizeFromMap(*map), size);
1270 if (size > Context::kTodoHeaderSize) {
1271 ObjectSlot start = context->RawField(Context::kTodoHeaderSize);
1272 ObjectSlot end = context->RawField(size);
1273 size_t slot_count = end - start;
1274 MemsetTagged(start, *undefined_value(), slot_count);
1275 }
1276 return context;
1277}
1278
1279// Creates new maps and new native context and wires them up.
1280//
1281// +-+------------->|NativeContext|
1282// | | |
1283// | | map
1284// | | v
1285// | | |context_map| <Map(NATIVE_CONTEXT_TYPE)>
1286// | | | |
1287// | +--native_context--+ map
1288// | v
1289// | +------->|contextful_meta_map| <Map(MAP_TYPE)>
1290// | | | |
1291// | +-----map-----+ |
1292// | |
1293// +-----native_context-----+
1294//
1296 // All maps that belong to this new native context will have this meta map.
1297 // The native context does not exist yet, so create the map as contextless
1298 // for now.
1299 DirectHandle<Map> contextful_meta_map =
1300 NewContextlessMap(MAP_TYPE, Map::kSize);
1301 contextful_meta_map->set_map(isolate(), *contextful_meta_map);
1302
1304 contextful_meta_map, NATIVE_CONTEXT_TYPE, kVariableSizeSentinel);
1305
1306 if (v8_flags.log_maps) {
1307 LOG(isolate(),
1308 MapEvent("NewNativeContext", isolate()->factory()->meta_map(),
1309 contextful_meta_map, "contextful meta map"));
1310 LOG(isolate(),
1311 MapEvent("NewNativeContext", isolate()->factory()->meta_map(),
1312 context_map, "native context map"));
1313 }
1314
1316 context_map, NativeContext::kSize, NativeContext::NATIVE_CONTEXT_SLOTS,
1319 contextful_meta_map->set_native_context(context);
1320 context_map->set_native_context(context);
1321 context->set_meta_map(*contextful_meta_map);
1322 context->set_scope_info(*native_scope_info());
1323 context->set_previous(Context());
1324 context->set_extension(*undefined_value());
1325 context->set_errors_thrown(Smi::zero());
1326 context->set_is_wasm_js_installed(Smi::zero());
1327 context->set_is_wasm_jspi_installed(Smi::zero());
1328 context->set_math_random_index(Smi::zero());
1329 context->set_serialized_objects(*empty_fixed_array());
1330 context->init_microtask_queue(isolate(), nullptr);
1331 context->set_retained_maps(*empty_weak_array_list());
1332 return handle(context, isolate());
1333}
1334
1337 DCHECK(scope_info->is_script_scope());
1338 int variadic_part_length = scope_info->ContextLength();
1339
1340 DirectHandle<FixedArray> side_data;
1341 if (v8_flags.const_tracking_let ||
1342 v8_flags.script_context_mutable_heap_number) {
1343 side_data = NewFixedArray(scope_info->ContextLocalCount());
1344 } else {
1345 side_data = empty_fixed_array();
1346 }
1347 Tagged<Context> context =
1348 NewContextInternal(direct_handle(outer->script_context_map(), isolate()),
1349 Context::SizeFor(variadic_part_length),
1350 variadic_part_length, AllocationType::kOld);
1352 context->set_scope_info(*scope_info);
1353 context->set_previous(*outer);
1354 context->set(Context::CONTEXT_SIDE_TABLE_PROPERTY_INDEX, *side_data);
1355 DCHECK(context->IsScriptContext());
1356 return direct_handle(context, isolate());
1357}
1358
1360 static constexpr int kInitialCapacity = 0;
1361 return ScriptContextTable::New(isolate(), kInitialCapacity);
1362}
1363
1366 DirectHandle<ScopeInfo> scope_info) {
1367 // TODO(v8:13567): Const tracking let in module contexts.
1368 DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE);
1369 int variadic_part_length = scope_info->ContextLength();
1371 isolate()->module_context_map(), Context::SizeFor(variadic_part_length),
1372 variadic_part_length, AllocationType::kOld);
1374 context->set_scope_info(*scope_info);
1375 context->set_previous(*outer);
1376 context->set_extension(*module);
1377 DCHECK(context->IsModuleContext());
1378 return direct_handle(context, isolate());
1379}
1380
1384 switch (scope_info->scope_type()) {
1385 case EVAL_SCOPE:
1386 map = isolate()->eval_context_map();
1387 break;
1388 case FUNCTION_SCOPE:
1389 map = isolate()->function_context_map();
1390 break;
1391 default:
1392 UNREACHABLE();
1393 }
1394 int variadic_part_length = scope_info->ContextLength();
1395 Tagged<Context> context =
1396 NewContextInternal(map, Context::SizeFor(variadic_part_length),
1397 variadic_part_length, AllocationType::kYoung);
1399 context->set_scope_info(*scope_info);
1400 context->set_previous(*outer);
1401 return direct_handle(context, isolate());
1402}
1403
1404#if V8_SINGLE_GENERATION_BOOL
1405#define DCHECK_NEWLY_ALLOCATED_OBJECT_IS_YOUNG(isolate, object)
1406#elif V8_ENABLE_STICKY_MARK_BITS_BOOL
1407#define DCHECK_NEWLY_ALLOCATED_OBJECT_IS_YOUNG(isolate, object) \
1408 DCHECK_IMPLIES(!isolate->heap()->incremental_marking()->IsMajorMarking(), \
1409 HeapLayout::InYoungGeneration(object))
1410#else
1411#define DCHECK_NEWLY_ALLOCATED_OBJECT_IS_YOUNG(isolate, object) \
1412 DCHECK(HeapLayout::InYoungGeneration(object))
1413#endif
1414
1417 DirectHandle<Object> thrown_object) {
1418 DCHECK_EQ(scope_info->scope_type(), CATCH_SCOPE);
1420 // TODO(ishell): Take the details from CatchContext class.
1421 int variadic_part_length = Context::MIN_CONTEXT_SLOTS + 1;
1423 isolate()->catch_context_map(), Context::SizeFor(variadic_part_length),
1424 variadic_part_length, AllocationType::kYoung);
1427 context->set_scope_info(*scope_info, SKIP_WRITE_BARRIER);
1428 context->set_previous(*previous, SKIP_WRITE_BARRIER);
1429 context->set(Context::THROWN_OBJECT_INDEX, *thrown_object,
1431 return direct_handle(context, isolate());
1432}
1433
1437 DCHECK(scope_info->IsDebugEvaluateScope());
1438 DirectHandle<HeapObject> ext = extension.is_null()
1439 ? Cast<HeapObject>(undefined_value())
1441 // TODO(ishell): Take the details from DebugEvaluateContextContext class.
1442 int variadic_part_length = Context::MIN_CONTEXT_EXTENDED_SLOTS + 1;
1443 Tagged<Context> context =
1444 NewContextInternal(isolate()->debug_evaluate_context_map(),
1445 Context::SizeFor(variadic_part_length),
1446 variadic_part_length, AllocationType::kYoung);
1449 context->set_scope_info(*scope_info, SKIP_WRITE_BARRIER);
1450 context->set_previous(*previous, SKIP_WRITE_BARRIER);
1451 context->set_extension(*ext, SKIP_WRITE_BARRIER);
1452 if (!wrapped.is_null()) {
1453 context->set(Context::WRAPPED_CONTEXT_INDEX, *wrapped, SKIP_WRITE_BARRIER);
1454 }
1455 return handle(context, isolate());
1456}
1457
1459 DirectHandle<ScopeInfo> scope_info,
1461 DCHECK_EQ(scope_info->scope_type(), WITH_SCOPE);
1462 // TODO(ishell): Take the details from WithContext class.
1463 int variadic_part_length = Context::MIN_CONTEXT_EXTENDED_SLOTS;
1465 isolate()->with_context_map(), Context::SizeFor(variadic_part_length),
1466 variadic_part_length, AllocationType::kYoung);
1469 context->set_scope_info(*scope_info, SKIP_WRITE_BARRIER);
1470 context->set_previous(*previous, SKIP_WRITE_BARRIER);
1471 context->set_extension(*extension, SKIP_WRITE_BARRIER);
1472 return handle(context, isolate());
1473}
1474
1477 DCHECK_IMPLIES(scope_info->scope_type() != BLOCK_SCOPE,
1478 scope_info->scope_type() == CLASS_SCOPE);
1479 int variadic_part_length = scope_info->ContextLength();
1481 isolate()->block_context_map(), Context::SizeFor(variadic_part_length),
1482 variadic_part_length, AllocationType::kYoung);
1485 context->set_scope_info(*scope_info, SKIP_WRITE_BARRIER);
1486 context->set_previous(*previous, SKIP_WRITE_BARRIER);
1487 return direct_handle(context, isolate());
1488}
1489
1491 DirectHandle<NativeContext> native_context, int variadic_part_length) {
1492 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, variadic_part_length);
1494 isolate()->function_context_map(), Context::SizeFor(variadic_part_length),
1495 variadic_part_length, AllocationType::kYoung);
1498 context->set_scope_info(read_only_roots().empty_scope_info(),
1500 context->set_previous(*native_context, SKIP_WRITE_BARRIER);
1501 return direct_handle(context, isolate());
1502}
1503
1505 int aliased_context_slot) {
1507 ALIASED_ARGUMENTS_ENTRY_TYPE, AllocationType::kYoung);
1508 entry->set_aliased_context_slot(aliased_context_slot);
1509 return direct_handle(entry, isolate());
1510}
1511
1514 Cast<AccessorInfo>(New(accessor_info_map(), AllocationType::kOld));
1516 info->set_name(*empty_string(), SKIP_WRITE_BARRIER);
1517 info->set_data(*undefined_value(), SKIP_WRITE_BARRIER);
1518 info->set_flags(0); // Must clear the flags, it was initialized as undefined.
1519 info->set_is_sloppy(true);
1520 info->set_initial_property_attributes(NONE);
1521
1522 info->init_getter(isolate(), kNullAddress);
1523 info->init_setter(isolate(), kNullAddress);
1524
1525 info->clear_padding();
1526
1527 return direct_handle(info, isolate());
1528}
1529
1531 AllocationType allocation) {
1533 Cast<InterceptorInfo>(New(interceptor_info_map(), allocation));
1535 info->set_data(*undefined_value());
1536 info->set_flags(0);
1537 info->clear_padding();
1538
1539 // Initialization of these lazy-initialized callback fields is the same
1540 // for named and indexed versions.
1541#define INIT_CALLBACK_FIELD(Name, name) info->init_named_##name();
1542
1544#undef INIT_CALLBACK_FIELD
1545
1546 return direct_handle(info, isolate());
1547}
1548
1550 DirectHandle<UnionOf<JSAny, FixedArray>> call_site_infos_or_formatted_stack,
1551 DirectHandle<StackTraceInfo> stack_trace) {
1553 ERROR_STACK_DATA_TYPE, AllocationType::kYoung);
1555 error_stack_data->set_call_site_infos_or_formatted_stack(
1556 *call_site_infos_or_formatted_stack, SKIP_WRITE_BARRIER);
1557 error_stack_data->set_stack_trace(*stack_trace, SKIP_WRITE_BARRIER);
1558 return direct_handle(error_stack_data, isolate());
1559}
1560
1562 ScriptEventType script_event_type) {
1563 int script_id = script->id();
1564 if (script_id != Script::kTemporaryScriptId) {
1565 DirectHandle<WeakArrayList> scripts = script_list();
1566 scripts = WeakArrayList::Append(isolate(), scripts,
1569 isolate()->heap()->set_script_list(*scripts);
1570 }
1571 if (IsString(script->source()) && isolate()->NeedsSourcePositions()) {
1572 Script::InitLineEnds(isolate(), script);
1573 }
1574 LOG(isolate(), ScriptEvent(script_event_type, script_id));
1575}
1576
1578 DirectHandle<String> source) {
1579 int script_id = isolate()->GetNextScriptId();
1580#ifdef V8_SCRIPTORMODULE_LEGACY_LIFETIME
1582#endif
1583 Handle<Script> new_script_handle =
1585 {
1587 Tagged<Script> new_script = *new_script_handle;
1588 const Tagged<Script> old_script = *script;
1589 new_script->set_source(*source);
1590 new_script->set_name(old_script->name());
1591 new_script->set_id(script_id);
1592 new_script->set_line_offset(old_script->line_offset());
1593 new_script->set_column_offset(old_script->column_offset());
1594 new_script->set_context_data(old_script->context_data());
1595 new_script->set_type(old_script->type());
1596 new_script->set_line_ends(Smi::zero());
1597 new_script->set_eval_from_shared_or_wrapped_arguments(
1598 script->eval_from_shared_or_wrapped_arguments());
1599 new_script->set_infos(*empty_weak_fixed_array(), SKIP_WRITE_BARRIER);
1600 new_script->set_eval_from_position(old_script->eval_from_position());
1601 new_script->set_flags(old_script->flags());
1602 new_script->set_host_defined_options(old_script->host_defined_options());
1603 new_script->set_source_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1604 new_script->set_compiled_lazy_function_positions(*undefined_value(),
1606#ifdef V8_SCRIPTORMODULE_LEGACY_LIFETIME
1607 new_script->set_script_or_modules(*list);
1608#endif
1609 }
1610 ProcessNewScript(new_script_handle, ScriptEventType::kCreate);
1611 return new_script_handle;
1612}
1613
1616 DCHECK(IsCallable(*callable));
1617 auto microtask = NewStructInternal<CallableTask>(CALLABLE_TASK_TYPE,
1620 microtask->set_callable(*callable, SKIP_WRITE_BARRIER);
1621 microtask->set_context(*context, SKIP_WRITE_BARRIER);
1622#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
1623 microtask->set_continuation_preserved_embedder_data(
1624 isolate()->isolate_data()->continuation_preserved_embedder_data(),
1626#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
1627 return direct_handle(microtask, isolate());
1628}
1629
1632 auto microtask = NewStructInternal<CallbackTask>(CALLBACK_TASK_TYPE,
1635 microtask->set_callback(*callback, SKIP_WRITE_BARRIER);
1636 microtask->set_data(*data, SKIP_WRITE_BARRIER);
1637#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
1638 microtask->set_continuation_preserved_embedder_data(
1639 isolate()->isolate_data()->continuation_preserved_embedder_data(),
1641#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
1642 return direct_handle(microtask, isolate());
1643}
1644
1647 DirectHandle<JSPromise> promise_to_resolve,
1649 DirectHandle<Context> context) {
1650 DCHECK(IsCallable(*then));
1652 PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE, AllocationType::kYoung);
1654 microtask->set_promise_to_resolve(*promise_to_resolve, SKIP_WRITE_BARRIER);
1655 microtask->set_thenable(*thenable, SKIP_WRITE_BARRIER);
1656 microtask->set_then(*then, SKIP_WRITE_BARRIER);
1657 microtask->set_context(*context, SKIP_WRITE_BARRIER);
1658#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
1659 microtask->set_continuation_preserved_embedder_data(
1660 isolate()->isolate_data()->continuation_preserved_embedder_data(),
1662#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
1663 return direct_handle(microtask, isolate());
1664}
1665
1666#if V8_ENABLE_WEBASSEMBLY
1667
1668DirectHandle<WasmTrustedInstanceData> Factory::NewWasmTrustedInstanceData() {
1671 WasmTrustedInstanceData::kSize, AllocationType::kTrusted,
1672 read_only_roots().wasm_trusted_instance_data_map()));
1674 result->init_self_indirect_pointer(isolate());
1675 result->clear_padding();
1677 result->RawField(offset).store(read_only_roots().undefined_value());
1678 }
1679 return direct_handle(result, isolate());
1680}
1681
1682DirectHandle<WasmDispatchTable> Factory::NewWasmDispatchTable(
1683 int length, wasm::CanonicalValueType table_type) {
1685
1686 // TODO(jkummerow): Any chance to get a better estimate?
1687 size_t estimated_offheap_size = 0;
1688 DirectHandle<TrustedManaged<WasmDispatchTableData>> offheap_data =
1690 isolate(), estimated_offheap_size,
1691 std::make_shared<WasmDispatchTableData>());
1692
1693 int bytes = WasmDispatchTable::SizeFor(length);
1696 read_only_roots().wasm_dispatch_table_map()));
1698 result->init_self_indirect_pointer(isolate());
1701 result->set_protected_offheap_data(*offheap_data);
1702 result->set_protected_uses(*empty_protected_weak_fixed_array());
1703 result->set_table_type(table_type);
1704 for (int i = 0; i < length; ++i) {
1706 result->clear_entry_padding(i);
1707 }
1708 return direct_handle(result, isolate());
1709}
1710
1711DirectHandle<WasmTypeInfo> Factory::NewWasmTypeInfo(
1712 wasm::CanonicalValueType type, wasm::CanonicalValueType element_type,
1713 DirectHandle<Map> opt_parent) {
1714 // We pretenure WasmTypeInfo objects for two reasons:
1715 // (1) They are referenced by Maps, which are assumed to be long-lived,
1716 // so pretenuring the WTI is a bit more efficient.
1717 // (2) The object visitors need to read the WasmTypeInfo to find tagged
1718 // fields in Wasm structs; in the middle of a GC cycle that's only
1719 // safe to do if the WTI is in old space.
1720 DirectHandleVector<Object> supertypes(isolate());
1721 if (opt_parent.is_null()) {
1722 supertypes.resize(wasm::kMinimumSupertypeArraySize, undefined_value());
1723 } else {
1724 DirectHandle<WasmTypeInfo> parent_type_info(opt_parent->wasm_type_info(),
1725 isolate());
1726 int first_undefined_index = -1;
1727 for (int i = 0; i < parent_type_info->supertypes_length(); i++) {
1728 DirectHandle<Object> supertype(parent_type_info->supertypes(i),
1729 isolate());
1730 if (IsUndefined(*supertype) && first_undefined_index == -1) {
1731 first_undefined_index = i;
1732 }
1733 supertypes.emplace_back(supertype);
1734 }
1735 if (first_undefined_index >= 0) {
1736 supertypes[first_undefined_index] = opt_parent;
1737 } else {
1738 supertypes.emplace_back(opt_parent);
1739 }
1740 }
1741 Tagged<Map> map = *wasm_type_info_map();
1743 WasmTypeInfo::SizeFor(static_cast<int>(supertypes.size())),
1744 AllocationType::kOld, map));
1746 result->set_supertypes_length(static_cast<int>(supertypes.size()));
1747 for (size_t i = 0; i < supertypes.size(); i++) {
1748 result->set_supertypes(static_cast<int>(i), *supertypes[i]);
1749 }
1750 result->set_canonical_type(type.raw_bit_field());
1751 result->set_canonical_element_type(element_type.raw_bit_field());
1752 return direct_handle(result, isolate());
1753}
1754
1755DirectHandle<WasmImportData> Factory::NewWasmImportData(
1756 DirectHandle<HeapObject> callable, wasm::Suspend suspend,
1757 MaybeDirectHandle<WasmTrustedInstanceData> instance_data,
1758 const wasm::CanonicalSig* sig) {
1759 Tagged<Map> map = *wasm_import_data_map();
1761 map->instance_size(), AllocationType::kTrusted, map));
1763 result->set_native_context(*isolate()->native_context());
1764 result->set_callable(Cast<UnionOf<Undefined, JSReceiver>>(*callable));
1765 result->set_suspend(suspend);
1766 if (instance_data.is_null()) {
1767 result->clear_instance_data();
1768 } else {
1769 result->set_instance_data(*instance_data.ToHandleChecked());
1770 }
1771 result->set_wrapper_budget(v8_flags.wasm_wrapper_tiering_budget);
1772 result->clear_call_origin();
1773 result->set_sig(sig);
1774#if TAGGED_SIZE_8_BYTES
1775 result->set_optional_padding(0);
1776#endif
1777 return direct_handle(result, isolate());
1778}
1779
1780DirectHandle<WasmImportData> Factory::NewWasmImportData(
1781 DirectHandle<WasmImportData> import_data) {
1782 return NewWasmImportData(
1783 direct_handle(import_data->callable(), isolate()), import_data->suspend(),
1784 direct_handle(import_data->instance_data(), isolate()),
1785 import_data->sig());
1786}
1787
1788DirectHandle<WasmFastApiCallData> Factory::NewWasmFastApiCallData(
1789 DirectHandle<HeapObject> signature, DirectHandle<Object> callback_data) {
1790 Tagged<Map> map = *wasm_fast_api_call_data_map();
1792 map->instance_size(), AllocationType::kOld, map));
1793 result->set_signature(*signature);
1794 result->set_callback_data(*callback_data);
1795 result->set_cached_map(read_only_roots().null_value());
1796 return direct_handle(result, isolate());
1797}
1798
1799DirectHandle<WasmInternalFunction> Factory::NewWasmInternalFunction(
1800 DirectHandle<TrustedObject> implicit_arg, int function_index) {
1803 WasmInternalFunction::kSize, AllocationType::kTrusted,
1804 *wasm_internal_function_map()));
1805 internal->init_self_indirect_pointer(isolate());
1806 {
1808 internal->set_call_target(wasm::kInvalidWasmCodePointer);
1809 DCHECK(IsWasmTrustedInstanceData(*implicit_arg) ||
1810 IsWasmImportData(*implicit_arg));
1811 internal->set_implicit_arg(*implicit_arg);
1812 // Default values, will be overwritten by the caller.
1813 internal->set_function_index(function_index);
1814 internal->set_external(*undefined_value());
1815 }
1816
1817 return direct_handle(internal, isolate());
1818}
1819
1820DirectHandle<WasmFuncRef> Factory::NewWasmFuncRef(
1821 DirectHandle<WasmInternalFunction> internal_function,
1822 DirectHandle<Map> rtt) {
1823 Tagged<HeapObject> raw =
1824 AllocateRaw(WasmFuncRef::kSize, AllocationType::kOld);
1826 DCHECK_EQ(WASM_FUNC_REF_TYPE, rtt->instance_type());
1827 DCHECK_EQ(WasmFuncRef::kSize, rtt->instance_size());
1828 raw->set_map_after_allocation(isolate(), *rtt);
1829 Tagged<WasmFuncRef> func_ref = Cast<WasmFuncRef>(raw);
1830 func_ref->set_internal(*internal_function);
1831 return direct_handle(func_ref, isolate());
1832}
1833
1834DirectHandle<WasmJSFunctionData> Factory::NewWasmJSFunctionData(
1835 wasm::CanonicalTypeIndex sig_index, DirectHandle<JSReceiver> callable,
1836 DirectHandle<Code> wrapper_code, DirectHandle<Map> rtt,
1837 wasm::Suspend suspend, wasm::Promise promise) {
1838 // TODO(clemensb): Should this be passed instead of looked up here?
1839 const wasm::CanonicalSig* sig =
1841 DirectHandle<WasmImportData> import_data = NewWasmImportData(
1842 callable, suspend, DirectHandle<WasmTrustedInstanceData>(), sig);
1843
1844 // Rough guess for a wrapper that may be shared with other users of it.
1845 constexpr size_t kOffheapDataSizeEstimate = 100;
1846 DirectHandle<TrustedManaged<WasmJSFunctionData::OffheapData>> offheap_data =
1848 isolate(), kOffheapDataSizeEstimate,
1849 std::make_shared<WasmJSFunctionData::OffheapData>(
1850 sig->signature_hash()));
1851
1852 DirectHandle<WasmInternalFunction> internal =
1853 NewWasmInternalFunction(import_data, -1);
1854 DirectHandle<WasmFuncRef> func_ref = NewWasmFuncRef(internal, rtt);
1855 import_data->SetFuncRefAsCallOrigin(*internal);
1856 Tagged<Map> map = *wasm_js_function_data_map();
1859 map->instance_size(), AllocationType::kTrusted, map));
1860 result->init_self_indirect_pointer(isolate());
1862 result->set_func_ref(*func_ref);
1863 result->set_internal(*internal);
1864 result->set_wrapper_code(*wrapper_code);
1865 result->set_canonical_sig_index(sig_index.index);
1866 result->set_js_promise_flags(WasmFunctionData::SuspendField::encode(suspend) |
1868 result->set_protected_offheap_data(*offheap_data);
1869 return direct_handle(result, isolate());
1870}
1871
1872DirectHandle<WasmResumeData> Factory::NewWasmResumeData(
1873 DirectHandle<WasmSuspenderObject> suspender, wasm::OnResume on_resume) {
1874 Tagged<Map> map = *wasm_resume_data_map();
1877 map->instance_size(), AllocationType::kOld, map));
1879 result->set_suspender(*suspender);
1880 result->set_on_resume(static_cast<int>(on_resume));
1881 return direct_handle(result, isolate());
1882}
1883
1884DirectHandle<WasmSuspenderObject> Factory::NewWasmSuspenderObject() {
1885 DirectHandle<JSPromise> promise = NewJSPromise();
1886 Tagged<Map> map = *wasm_suspender_object_map();
1889 map->instance_size(), AllocationType::kOld, map));
1890 auto suspender = handle(obj, isolate());
1891 // Ensure that all properties are initialized before the allocation below.
1892 suspender->init_stack(IsolateForSandbox(isolate()), nullptr);
1893 suspender->set_parent(*undefined_value());
1894 suspender->set_promise(*promise);
1895 suspender->set_resume(*undefined_value());
1896 suspender->set_reject(*undefined_value());
1897 // Instantiate the callable object which resumes this Suspender. This will be
1898 // used implicitly as the onFulfilled callback of the returned JS promise.
1899 DirectHandle<WasmResumeData> resume_data =
1900 NewWasmResumeData(suspender, wasm::OnResume::kContinue);
1901 DirectHandle<SharedFunctionInfo> resume_sfi =
1902 NewSharedFunctionInfoForWasmResume(resume_data);
1903 DirectHandle<Context> context(isolate()->native_context());
1904 DirectHandle<JSObject> resume =
1905 Factory::JSFunctionBuilder{isolate(), resume_sfi, context}.Build();
1906
1907 DirectHandle<WasmResumeData> reject_data =
1908 isolate()->factory()->NewWasmResumeData(suspender,
1910 DirectHandle<SharedFunctionInfo> reject_sfi =
1911 isolate()->factory()->NewSharedFunctionInfoForWasmResume(reject_data);
1912 DirectHandle<JSObject> reject =
1913 Factory::JSFunctionBuilder{isolate(), reject_sfi, context}.Build();
1914 suspender->set_resume(*resume);
1915 suspender->set_reject(*reject);
1916 return suspender;
1917}
1918
1919DirectHandle<WasmExportedFunctionData> Factory::NewWasmExportedFunctionData(
1920 DirectHandle<Code> export_wrapper,
1921 DirectHandle<WasmTrustedInstanceData> instance_data,
1922 DirectHandle<WasmFuncRef> func_ref,
1923 DirectHandle<WasmInternalFunction> internal_function,
1924 const wasm::CanonicalSig* sig, wasm::CanonicalTypeIndex type_index,
1925 int wrapper_budget, wasm::Promise promise) {
1926 int func_index = internal_function->function_index();
1927 DirectHandle<Cell> wrapper_budget_cell =
1928 NewCell(Smi::FromInt(wrapper_budget));
1929 Tagged<Map> map = *wasm_exported_function_data_map();
1932 map->instance_size(), AllocationType::kTrusted, map));
1933 result->init_self_indirect_pointer(isolate());
1935 result->set_func_ref(*func_ref);
1936 result->set_internal(*internal_function);
1937 result->set_wrapper_code(*export_wrapper);
1938 result->set_instance_data(*instance_data);
1939 result->set_function_index(func_index);
1940 result->set_sig(sig);
1941 result->set_canonical_type_index(type_index.index);
1942 result->set_wrapper_budget(*wrapper_budget_cell);
1943 // We can't skip the write barrier because Code objects are not immovable.
1944 result->set_c_wrapper_code(*BUILTIN_CODE(isolate(), Illegal),
1946 result->set_packed_args_size(0);
1947 result->set_js_promise_flags(
1950 return direct_handle(result, isolate());
1951}
1952
1953DirectHandle<WasmCapiFunctionData> Factory::NewWasmCapiFunctionData(
1954 Address call_target, DirectHandle<Foreign> embedder_data,
1955 DirectHandle<Code> wrapper_code, DirectHandle<Map> rtt,
1956 wasm::CanonicalTypeIndex sig_index, const wasm::CanonicalSig* sig) {
1957 DirectHandle<WasmImportData> import_data =
1958 NewWasmImportData(undefined_value(), wasm::kNoSuspend,
1959 DirectHandle<WasmTrustedInstanceData>(), sig);
1960 DirectHandle<WasmInternalFunction> internal =
1961 NewWasmInternalFunction(import_data, -1);
1962 DirectHandle<WasmFuncRef> func_ref = NewWasmFuncRef(internal, rtt);
1963 // We have no generic wrappers for C-API functions, so we don't need to
1964 // set any call origin on {import_data}.
1965 internal->set_call_target(
1967 ->GetOrCreateHandleForNativeFunction(call_target));
1968 Tagged<Map> map = *wasm_capi_function_data_map();
1971 map->instance_size(), AllocationType::kTrusted, map));
1972 result->init_self_indirect_pointer(isolate());
1974 result->set_func_ref(*func_ref);
1975 result->set_internal(*internal);
1976 result->set_canonical_sig_index(sig_index.index);
1977 result->set_wrapper_code(*wrapper_code);
1978 result->set_embedder_data(*embedder_data);
1979 result->set_sig(sig);
1980 result->set_js_promise_flags(
1983 return direct_handle(result, isolate());
1984}
1985
1986Tagged<WasmArray> Factory::NewWasmArrayUninitialized(uint32_t length,
1987 DirectHandle<Map> map) {
1988 Tagged<HeapObject> raw =
1991 raw->set_map_after_allocation(isolate(), *map);
1993 result->set_raw_properties_or_hash(*empty_fixed_array(), kRelaxedStore);
1994 result->set_length(length);
1995 return result;
1996}
1997
1998DirectHandle<WasmArray> Factory::NewWasmArray(wasm::ValueType element_type,
1999 uint32_t length,
2000 wasm::WasmValue initial_value,
2001 DirectHandle<Map> map) {
2002 Tagged<WasmArray> result = NewWasmArrayUninitialized(length, map);
2004 if (element_type.is_numeric()) {
2005 if (initial_value.zero_byte_representation()) {
2006 memset(reinterpret_cast<void*>(result->ElementAddress(0)), 0,
2007 length * element_type.value_kind_size());
2008 } else {
2009 wasm::WasmValue packed = initial_value.Packed(element_type);
2010 for (uint32_t i = 0; i < length; i++) {
2011 Address address = result->ElementAddress(i);
2012 packed.CopyTo(reinterpret_cast<uint8_t*>(address));
2013 }
2014 }
2015 } else {
2016 for (uint32_t i = 0; i < length; i++) {
2017 result->SetTaggedElement(i, initial_value.to_ref());
2018 }
2019 }
2020 return direct_handle(result, isolate());
2021}
2022
2023DirectHandle<WasmArray> Factory::NewWasmArrayFromElements(
2024 const wasm::ArrayType* type, base::Vector<wasm::WasmValue> elements,
2025 DirectHandle<Map> map) {
2026 uint32_t length = static_cast<uint32_t>(elements.size());
2027 Tagged<WasmArray> result = NewWasmArrayUninitialized(length, map);
2029 if (type->element_type().is_numeric()) {
2030 for (uint32_t i = 0; i < length; i++) {
2031 Address address = result->ElementAddress(i);
2032 elements[i]
2033 .Packed(type->element_type())
2034 .CopyTo(reinterpret_cast<uint8_t*>(address));
2035 }
2036 } else {
2037 for (uint32_t i = 0; i < length; i++) {
2038 result->SetTaggedElement(i, elements[i].to_ref());
2039 }
2040 }
2041 return direct_handle(result, isolate());
2042}
2043
2044DirectHandle<WasmArray> Factory::NewWasmArrayFromMemory(
2045 uint32_t length, DirectHandle<Map> map,
2046 wasm::CanonicalValueType element_type, Address source) {
2047 DCHECK(element_type.is_numeric());
2048 Tagged<WasmArray> result = NewWasmArrayUninitialized(length, map);
2050#if V8_TARGET_BIG_ENDIAN
2051 MemCopyAndSwitchEndianness(reinterpret_cast<void*>(result->ElementAddress(0)),
2052 reinterpret_cast<void*>(source), length,
2053 element_type.value_kind_size());
2054#else
2055 MemCopy(reinterpret_cast<void*>(result->ElementAddress(0)),
2056 reinterpret_cast<void*>(source),
2057 length * element_type.value_kind_size());
2058#endif
2059
2060 return direct_handle(result, isolate());
2061}
2062
2063DirectHandle<Object> Factory::NewWasmArrayFromElementSegment(
2064 DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
2065 DirectHandle<WasmTrustedInstanceData> shared_trusted_instance_data,
2066 uint32_t segment_index, uint32_t start_offset, uint32_t length,
2067 DirectHandle<Map> map, wasm::CanonicalValueType element_type) {
2068 DCHECK(element_type.is_reference());
2069
2070 // If the element segment has not been initialized yet, lazily initialize it
2071 // now.
2072 AccountingAllocator allocator;
2073 Zone zone(&allocator, ZONE_NAME);
2074 std::optional<MessageTemplate> opt_error = wasm::InitializeElementSegment(
2075 &zone, isolate(), trusted_instance_data, shared_trusted_instance_data,
2076 segment_index);
2077 if (opt_error.has_value()) {
2078 return direct_handle(Smi::FromEnum(opt_error.value()), isolate());
2079 }
2080
2081 DirectHandle<FixedArray> elements = direct_handle(
2083 trusted_instance_data->element_segments()->get(segment_index)),
2084 isolate());
2085
2086 Tagged<WasmArray> result = NewWasmArrayUninitialized(length, map);
2088 if (length > 0) {
2089 isolate()->heap()->CopyRange(result, result->ElementSlot(0),
2090 elements->RawFieldOfElementAt(start_offset),
2091 length, SKIP_WRITE_BARRIER);
2092 }
2093 return direct_handle(result, isolate());
2094}
2095
2096Handle<WasmStruct> Factory::NewWasmStructUninitialized(
2097 const wasm::StructType* type, DirectHandle<Map> map,
2098 AllocationType allocation) {
2099 Tagged<HeapObject> raw = AllocateRaw(WasmStruct::Size(type), allocation);
2100 raw->set_map_after_allocation(isolate(), *map);
2102 result->set_raw_properties_or_hash(*empty_fixed_array(), kRelaxedStore);
2103 return handle(result, isolate());
2104}
2105
2106DirectHandle<WasmStruct> Factory::NewWasmStruct(const wasm::StructType* type,
2107 wasm::WasmValue* args,
2108 DirectHandle<Map> map) {
2109 Tagged<HeapObject> raw =
2111 raw->set_map_after_allocation(isolate(), *map);
2113 result->set_raw_properties_or_hash(*empty_fixed_array(), kRelaxedStore);
2114 for (uint32_t i = 0; i < type->field_count(); i++) {
2115 int offset = type->field_offset(i);
2116 if (type->field(i).is_numeric()) {
2117 Address address = result->RawFieldAddress(offset);
2118 args[i]
2119 .Packed(type->field(i))
2120 .CopyTo(reinterpret_cast<uint8_t*>(address));
2121 } else {
2122 offset += WasmStruct::kHeaderSize;
2124 }
2125 }
2126 return direct_handle(result, isolate());
2127}
2128
2129DirectHandle<SharedFunctionInfo>
2130Factory::NewSharedFunctionInfoForWasmExportedFunction(
2131 DirectHandle<String> name, DirectHandle<WasmExportedFunctionData> data,
2132 int len, AdaptArguments adapt) {
2133 return NewSharedFunctionInfo(name, data, Builtin::kNoBuiltinId, len, adapt);
2134}
2135
2136DirectHandle<SharedFunctionInfo>
2137Factory::NewSharedFunctionInfoForWasmJSFunction(
2138 DirectHandle<String> name, DirectHandle<WasmJSFunctionData> data) {
2139 return NewSharedFunctionInfo(name, data, Builtin::kNoBuiltinId, 0,
2140 kDontAdapt);
2141}
2142
2143DirectHandle<SharedFunctionInfo> Factory::NewSharedFunctionInfoForWasmResume(
2144 DirectHandle<WasmResumeData> data) {
2146}
2147
2148DirectHandle<SharedFunctionInfo>
2149Factory::NewSharedFunctionInfoForWasmCapiFunction(
2150 DirectHandle<WasmCapiFunctionData> data) {
2151 return NewSharedFunctionInfo(MaybeDirectHandle<String>(), data,
2154}
2155#endif // V8_ENABLE_WEBASSEMBLY
2156
2158 static_assert(Cell::kSize <= kMaxRegularHeapObjectSize);
2160 Cell::kSize, AllocationType::kOld, *cell_map()));
2163 return handle(result, isolate());
2164}
2165
2167 static_assert(Cell::kSize <= kMaxRegularHeapObjectSize);
2169 Cell::kSize, AllocationType::kOld, *cell_map()));
2170 result->set_value(read_only_roots().undefined_value(),
2172 return handle(result, isolate());
2173}
2174
2178 *no_closures_cell_map()));
2180 result->set_value(read_only_roots().undefined_value());
2181 result->clear_interrupt_budget();
2182#ifdef V8_ENABLE_LEAPTIERING
2183 result->clear_dispatch_handle();
2184#endif // V8_ENABLE_LEAPTIERING
2185 result->clear_padding();
2186 return direct_handle(result, isolate());
2187}
2188
2193 *one_closure_cell_map()));
2195 result->set_value(*value);
2196 result->clear_interrupt_budget();
2197#ifdef V8_ENABLE_LEAPTIERING
2198 result->clear_dispatch_handle();
2199#endif // V8_ENABLE_LEAPTIERING
2200 result->clear_padding();
2201 return direct_handle(result, isolate());
2202}
2203
2205 AllocationType allocation) {
2207 FeedbackCell::kAlignedSize, allocation, *many_closures_cell_map()));
2209 result->set_value(read_only_roots().undefined_value());
2210 result->clear_interrupt_budget();
2211 result->clear_dispatch_handle();
2212 result->clear_padding();
2213 return direct_handle(result, isolate());
2214}
2215
2217 PropertyDetails details,
2219 AllocationType allocation) {
2220 DCHECK(IsUniqueName(*name));
2221 static_assert(PropertyCell::kSize <= kMaxRegularHeapObjectSize);
2223 PropertyCell::kSize, allocation, *global_property_cell_map()));
2225 cell->set_dependent_code(
2228 WriteBarrierMode mode = allocation == AllocationType::kYoung
2231 cell->set_name(*name, mode);
2232 cell->set_value(*value, mode);
2233 cell->set_property_details_raw(details.AsSmi(), SKIP_WRITE_BARRIER);
2234 return handle(cell, isolate());
2235}
2236
2239 static_assert(ContextSidePropertyCell::kSize <= kMaxRegularHeapObjectSize);
2241 AllocateRawWithImmortalMap(ContextSidePropertyCell::kSize, allocation,
2242 *global_context_side_property_cell_map()));
2244 cell->set_context_side_property_raw(Smi::FromInt(property), kReleaseStore);
2245 cell->set_dependent_code(
2248 return direct_handle(cell, isolate());
2249}
2250
2256
2258 int number_of_transitions, int slack) {
2259 int capacity = TransitionArray::LengthFor(number_of_transitions + slack);
2261 NewWeakFixedArrayWithMap(read_only_roots().transition_array_map(),
2262 capacity, AllocationType::kOld));
2263 // Transition arrays are AllocationType::kOld. When black allocation is on we
2264 // have to add the transition array to the list of
2265 // encountered_transition_arrays.
2266 Heap* heap = isolate()->heap();
2267 if (heap->incremental_marking()->black_allocation()) {
2268 heap->mark_compact_collector()->AddTransitionArray(*array);
2269 }
2270 array->WeakFixedArray::set(TransitionArray::kPrototypeTransitionsIndex,
2271 Smi::zero());
2272 array->WeakFixedArray::set(TransitionArray::kSideStepTransitionsIndex,
2273 Smi::zero());
2274 array->WeakFixedArray::set(TransitionArray::kTransitionLengthIndex,
2275 Smi::FromInt(number_of_transitions));
2276 return array;
2277}
2278
2280 DirectHandle<Map> map = with_weak_next
2281 ? allocation_site_map()
2282 : allocation_site_without_weaknext_map();
2285 site->Initialize();
2286
2287 if (with_weak_next) {
2288 // Link the site
2289 Cast<AllocationSiteWithWeakNext>(site)->set_weak_next(
2291 isolate()->heap()->allocation_sites_list()));
2294 }
2295 return site;
2296}
2297
2298template <typename MetaMapProviderFunc>
2299Handle<Map> Factory::NewMapImpl(MetaMapProviderFunc&& meta_map_provider,
2300 InstanceType type, int instance_size,
2301 ElementsKind elements_kind,
2302 int inobject_properties,
2303 AllocationType allocation_type) {
2304 static_assert(LAST_JS_OBJECT_TYPE == LAST_TYPE);
2306 DCHECK_IMPLIES(InstanceTypeChecker::IsJSObject(type) &&
2308 IsDictionaryElementsKind(elements_kind) ||
2309 IsTerminalElementsKind(elements_kind) ||
2310 IsSharedArrayElementsKind(elements_kind));
2311 DCHECK(allocation_type == AllocationType::kMap ||
2312 allocation_type == AllocationType::kSharedMap);
2315 Map::kSize, allocation_type);
2317 ReadOnlyRoots roots(isolate());
2318 result->set_map_after_allocation(isolate(), meta_map_provider());
2319
2320#if V8_STATIC_ROOTS_BOOL
2321 CHECK_IMPLIES(InstanceTypeChecker::IsJSReceiver(type),
2324#endif
2325 isolate()->counters()->maps_created()->Increment();
2326 return handle(InitializeMap(Cast<Map>(result), type, instance_size,
2327 elements_kind, inobject_properties, roots),
2328 isolate());
2329}
2330
2332 int instance_size,
2333 ElementsKind elements_kind,
2334 int inobject_properties,
2335 ReadOnlyRoots roots) {
2337 map->set_bit_field(0);
2338 map->set_bit_field2(Map::Bits2::NewTargetIsBaseBit::encode(true));
2339 int bit_field3 =
2340 Map::Bits3::EnumLengthBits::encode(kInvalidEnumCacheSentinel) |
2341 Map::Bits3::OwnsDescriptorsBit::encode(true) |
2342 Map::Bits3::ConstructionCounterBits::encode(Map::kNoSlackTracking) |
2343 Map::Bits3::IsExtensibleBit::encode(true);
2344 map->set_bit_field3(bit_field3);
2345 map->set_instance_type(type);
2346 map->init_prototype_and_constructor_or_back_pointer(roots);
2347 map->set_instance_size(instance_size);
2348 if (InstanceTypeChecker::IsJSObject(type)) {
2349 // JSObjects that may be allocated in RO space must have RO maps.
2352 // Shared space JS objects have fixed layout and can have RO maps. No other
2353 // JS objects have RO maps.
2354 DCHECK_IMPLIES(!IsMaybeReadOnlyJSObjectMap(*map) &&
2355 !IsAlwaysSharedSpaceJSObjectMap(*map),
2357 map->SetInObjectPropertiesStartInWords(instance_size / kTaggedSize -
2358 inobject_properties);
2359 DCHECK_EQ(map->GetInObjectProperties(), inobject_properties);
2360 map->set_prototype_validity_cell(roots.invalid_prototype_validity_cell(),
2362 } else {
2363 DCHECK_EQ(inobject_properties, 0);
2364 map->set_inobject_properties_start_or_constructor_function_index(0);
2365 map->set_prototype_validity_cell(Map::kPrototypeChainValidSmi,
2367 }
2368 map->set_dependent_code(DependentCode::empty_dependent_code(roots),
2370 map->set_raw_transitions(Smi::zero(), SKIP_WRITE_BARRIER);
2371 map->SetInObjectUnusedPropertyFields(inobject_properties);
2372 map->SetInstanceDescriptors(isolate(), roots.empty_descriptor_array(), 0,
2374 // Must be called only after |instance_type| and |instance_size| are set.
2375 map->set_visitor_id(Map::GetVisitorId(map));
2376 DCHECK(!map->is_in_retained_map_list());
2377 map->clear_padding();
2378 map->set_elements_kind(elements_kind);
2379 if (V8_UNLIKELY(v8_flags.log_maps)) {
2380 LOG(isolate(), MapCreate(map));
2381 }
2382 return map;
2383}
2384
2386 InstanceType type, int instance_size,
2387 ElementsKind elements_kind, int inobject_properties,
2388 AllocationType allocation_type) {
2389 auto meta_map_provider = [meta_map_holder] {
2390 // Tie new map to the same native context as given |meta_map_holder| object.
2391 Tagged<Map> meta_map = meta_map_holder->map();
2392 DCHECK(IsMapMap(meta_map));
2393 return meta_map;
2394 };
2395 Handle<Map> map =
2396 NewMapImpl(meta_map_provider, type, instance_size, elements_kind,
2397 inobject_properties, allocation_type);
2398 return map;
2399}
2400
2402 InstanceType type,
2403 int instance_size,
2404 ElementsKind elements_kind,
2405 int inobject_properties,
2406 AllocationType allocation_type) {
2407 DCHECK_EQ(*meta_map, meta_map->map());
2408 auto meta_map_provider = [meta_map] {
2409 // Use given meta map.
2410 return *meta_map;
2411 };
2412 DirectHandle<Map> map =
2413 NewMapImpl(meta_map_provider, type, instance_size, elements_kind,
2414 inobject_properties, allocation_type);
2415 return map;
2416}
2417
2419 DirectHandle<JSReceiver> creation_context_holder, InstanceType type,
2420 int instance_size, ElementsKind elements_kind, int inobject_properties,
2421 AllocationType allocation_type) {
2422 // TODO(ishell): There should probably be a DCHECK(IsNCSpecific(type)) here.
2423 auto meta_map_provider = [creation_context_holder] {
2424 // Tie new map to the creation context of given |creation_context_holder|
2425 // object.
2426 Tagged<Map> meta_map = creation_context_holder->map()->map();
2427 DCHECK(IsMapMap(meta_map));
2428 return meta_map;
2429 };
2430 DirectHandle<Map> map =
2431 NewMapImpl(meta_map_provider, type, instance_size, elements_kind,
2432 inobject_properties, allocation_type);
2433 return map;
2434}
2435
2438 int instance_size, ElementsKind elements_kind, int inobject_properties,
2439 AllocationType allocation_type) {
2441#if V8_ENABLE_WEBASSEMBLY
2442 InstanceTypeChecker::IsWasmStruct(type) ||
2443#endif // V8_ENABLE_WEBASSEMBLY
2444 InstanceTypeChecker::IsMap(type));
2445 auto meta_map_provider = [native_context] {
2446 // Tie new map to given native context.
2447 return native_context->meta_map();
2448 };
2449 DirectHandle<Map> map =
2450 NewMapImpl(meta_map_provider, type, instance_size, elements_kind,
2451 inobject_properties, allocation_type);
2452 return map;
2453}
2454
2456 InstanceType type, int instance_size, ElementsKind elements_kind,
2457 int inobject_properties, AllocationType allocation_type) {
2459 InstanceTypeChecker::IsMap(type));
2460 auto meta_map_provider = [this] {
2461 // Tie new map to current native context.
2462 return isolate()->raw_native_context()->meta_map();
2463 };
2464 Handle<Map> map =
2465 NewMapImpl(meta_map_provider, type, instance_size, elements_kind,
2466 inobject_properties, allocation_type);
2467 return map;
2468}
2469
2471 ElementsKind elements_kind,
2472 int inobject_properties,
2473 AllocationType allocation_type) {
2475 type == NATIVE_CONTEXT_TYPE || // just during NativeContext creation.
2476 type == JS_GLOBAL_PROXY_TYPE || // might be a placeholder object.
2477 type == JS_SPECIAL_API_OBJECT_TYPE || // might be a remote Api object.
2478 InstanceTypeChecker::IsMap(type));
2479 auto meta_map_provider = [this] {
2480 // The new map is not tied to any context.
2481 return ReadOnlyRoots(isolate()).meta_map();
2482 };
2483 Handle<Map> map =
2484 NewMapImpl(meta_map_provider, type, instance_size, elements_kind,
2485 inobject_properties, allocation_type);
2486 return map;
2487}
2488
2492
2495 DirectHandle<Map> map(source->map(), isolate());
2496
2497 // We can only clone regexps, normal objects, api objects, errors or arrays.
2498 // Copying anything else will break invariants.
2499 InstanceType instance_type = map->instance_type();
2500 bool is_clonable_js_type =
2501 instance_type == JS_REG_EXP_TYPE || instance_type == JS_OBJECT_TYPE ||
2502 instance_type == JS_ERROR_TYPE || instance_type == JS_ARRAY_TYPE ||
2503 instance_type == JS_SPECIAL_API_OBJECT_TYPE ||
2504 InstanceTypeChecker::IsJSApiObject(instance_type);
2505 bool is_clonable_wasm_type = false;
2506#if V8_ENABLE_WEBASSEMBLY
2507 is_clonable_wasm_type = instance_type == WASM_GLOBAL_OBJECT_TYPE ||
2508 instance_type == WASM_INSTANCE_OBJECT_TYPE ||
2509 instance_type == WASM_MEMORY_OBJECT_TYPE ||
2510 instance_type == WASM_MODULE_OBJECT_TYPE ||
2511 instance_type == WASM_TABLE_OBJECT_TYPE;
2512#endif // V8_ENABLE_WEBASSEMBLY
2513 CHECK(is_clonable_js_type || is_clonable_wasm_type);
2514
2515 DCHECK(site.is_null() || AllocationSite::CanTrack(instance_type));
2516
2517 int object_size = map->instance_size();
2518 int aligned_object_size = ALIGN_TO_ALLOCATION_ALIGNMENT(object_size);
2519 int adjusted_object_size = aligned_object_size;
2520 if (!site.is_null()) {
2522 adjusted_object_size +=
2524 }
2525 Tagged<HeapObject> raw_clone =
2527 adjusted_object_size, AllocationType::kYoung);
2528
2530
2531 Heap::CopyBlock(raw_clone.address(), source->address(), object_size);
2532 Handle<JSObject> clone(Cast<JSObject>(raw_clone), isolate());
2533
2534 if (v8_flags.enable_unconditional_write_barriers) {
2535 // By default, we shouldn't need to update the write barrier here, as the
2536 // clone will be allocated in new space.
2537 const ObjectSlot start(raw_clone.address());
2538 const ObjectSlot end(raw_clone.address() + object_size);
2539 WriteBarrier::ForRange(isolate()->heap(), raw_clone, start, end);
2540 }
2541 if (!site.is_null()) {
2543 Tagged<Object>(raw_clone.ptr() + aligned_object_size));
2544 InitializeAllocationMemento(alloc_memento, *site);
2545 }
2546
2547 SLOW_DCHECK(clone->GetElementsKind() == source->GetElementsKind());
2548 Tagged<FixedArrayBase> elements = source->elements();
2549 // Update elements if necessary.
2550 if (elements->length() > 0) {
2552 if (elements->map() == *fixed_cow_array_map()) {
2553 elem = elements;
2554 } else if (source->HasDoubleElements()) {
2555 elem = *CopyFixedDoubleArray(
2556 handle(Cast<FixedDoubleArray>(elements), isolate()));
2557 } else {
2558 elem = *CopyFixedArray(handle(Cast<FixedArray>(elements), isolate()));
2559 }
2560 clone->set_elements(elem);
2561 }
2562
2563 // Update properties if necessary.
2564 if (source->HasFastProperties()) {
2565 Tagged<PropertyArray> properties = source->property_array();
2566 if (properties->length() > 0) {
2567 // TODO(gsathya): Do not copy hash code.
2569 CopyArrayWithMap(direct_handle(properties, isolate()),
2570 direct_handle(properties->map(), isolate()));
2571 clone->set_raw_properties_or_hash(*prop, kRelaxedStore);
2572 }
2573 } else {
2574 DirectHandle<Object> copied_properties;
2576 copied_properties = SwissNameDictionary::ShallowCopy(
2577 isolate(),
2578 direct_handle(source->property_dictionary_swiss(), isolate()));
2579 } else {
2580 copied_properties =
2581 CopyFixedArray(handle(source->property_dictionary(), isolate()));
2582 }
2583 clone->set_raw_properties_or_hash(*copied_properties, kRelaxedStore);
2584 }
2585 return clone;
2586}
2587
2588namespace {
2589template <typename T>
2590void initialize_length(Tagged<T> array, int length) {
2591 array->set_length(length);
2592}
2593
2594template <>
2595void initialize_length<PropertyArray>(Tagged<PropertyArray> array, int length) {
2596 array->initialize_length(length);
2597}
2598
2599inline void InitEmbedderFields(Tagged<JSObject> obj,
2600 Tagged<Object> initial_value) {
2601 for (int i = 0; i < obj->GetEmbedderFieldCount(); i++) {
2602 EmbedderDataSlot(obj, i).Initialize(initial_value);
2603 }
2604}
2605
2606} // namespace
2607
2608template <typename T>
2610 AllocationType allocation) {
2611 int len = src->length();
2612 Tagged<HeapObject> new_object = AllocateRawFixedArray(len, allocation);
2614 new_object->set_map_after_allocation(isolate(), *map, SKIP_WRITE_BARRIER);
2615 Tagged<T> result = Cast<T>(new_object);
2616 initialize_length(result, len);
2617 // Copy the content.
2618 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
2619 T::CopyElements(isolate(), result, 0, *src, 0, len, mode);
2620 return handle(result, isolate());
2621}
2622
2623template <typename T>
2625 AllocationType allocation) {
2626 DCHECK_LT(0, grow_by);
2627 DCHECK_LE(grow_by, kMaxInt - src->length());
2628 int old_len = src->length();
2629 int new_len = old_len + grow_by;
2630 // TODO(jgruber,v8:14345): Use T::Allocate instead.
2631 Tagged<HeapObject> new_object = AllocateRawFixedArray(new_len, allocation);
2633 new_object->set_map_after_allocation(isolate(), src->map(),
2635 Tagged<T> result = Cast<T>(new_object);
2636 initialize_length(result, new_len);
2637 // Copy the content.
2638 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
2639 T::CopyElements(isolate(), result, 0, *src, 0, old_len, mode);
2640 // TODO(jgruber,v8:14345): Enable the static assert once all T's support it:
2641 // static_assert(T::kElementSize == kTaggedSize);
2642 MemsetTagged(ObjectSlot(result->RawFieldOfElementAt(old_len)),
2643 read_only_roots().undefined_value(), grow_by);
2644 return handle(result, isolate());
2645}
2646
2649 AllocationType allocation) {
2650 return CopyArrayWithMap(array, map, allocation);
2651}
2652
2654 int capacity, AllocationType allocation) {
2655 DCHECK_LE(0, capacity);
2656 if (capacity == 0) return empty_weak_array_list();
2657
2658 Tagged<HeapObject> heap_object =
2659 AllocateRawWeakArrayList(capacity, allocation);
2661 heap_object->set_map_after_allocation(isolate(), *weak_array_list_map(),
2664 result->set_length(0);
2665 result->set_capacity(capacity);
2666 return handle(result, isolate());
2667}
2668
2670 int capacity, AllocationType allocation) {
2672 NewUninitializedWeakArrayList(capacity, allocation);
2673 MemsetTagged(ObjectSlot(result->data_start()),
2674 read_only_roots().undefined_value(), capacity);
2675 return result;
2676}
2677
2679 DirectHandle<FixedArray> array, int grow_by, AllocationType allocation) {
2680 return CopyArrayAndGrow(array, grow_by, allocation);
2681}
2682
2685 DCHECK(!IsTransitionArray(*src)); // Compacted by GC, this code doesn't work
2686 return CopyArrayWithMap(src, weak_fixed_array_map(), AllocationType::kOld);
2687}
2688
2690 DirectHandle<WeakFixedArray> src, int grow_by) {
2691 DCHECK(!IsTransitionArray(*src)); // Compacted by GC, this code doesn't work
2692 return CopyArrayAndGrow(src, grow_by, AllocationType::kOld);
2693}
2694
2696 DirectHandle<WeakArrayList> src, int grow_by, AllocationType allocation) {
2697 int old_capacity = src->capacity();
2698 int new_capacity = old_capacity + grow_by;
2699 DCHECK_GE(new_capacity, old_capacity);
2701 NewUninitializedWeakArrayList(new_capacity, allocation);
2704 int old_len = src->length();
2705 raw->set_length(old_len);
2706 // Copy the content.
2707 WriteBarrierMode mode = raw->GetWriteBarrierMode(no_gc);
2708 raw->CopyElements(isolate(), 0, *src, 0, old_len, mode);
2709 MemsetTagged(ObjectSlot(raw->data_start() + old_len),
2710 read_only_roots().undefined_value(), new_capacity - old_len);
2711 return result;
2712}
2713
2715 DirectHandle<WeakArrayList> src, int new_capacity,
2716 AllocationType allocation) {
2718 NewUninitializedWeakArrayList(new_capacity, allocation);
2719
2720 // Copy the content.
2722 Tagged<WeakArrayList> raw_src = *src;
2723 Tagged<WeakArrayList> raw_result = *result;
2724 WriteBarrierMode mode = raw_result->GetWriteBarrierMode(no_gc);
2725 int copy_to = 0, length = raw_src->length();
2726 for (int i = 0; i < length; i++) {
2727 Tagged<MaybeObject> element = raw_src->Get(i);
2728 if (element.IsCleared()) continue;
2729 raw_result->Set(copy_to++, element, mode);
2730 }
2731 raw_result->set_length(copy_to);
2732
2733 MemsetTagged(ObjectSlot(raw_result->data_start() + copy_to),
2734 read_only_roots().undefined_value(), new_capacity - copy_to);
2735 return result;
2736}
2737
2742
2744 int new_len,
2745 AllocationType allocation) {
2746 DCHECK_LE(0, new_len);
2747 DCHECK_LE(new_len, array->length());
2748 if (new_len == 0) return empty_fixed_array();
2749 Tagged<HeapObject> heap_object = AllocateRawFixedArray(new_len, allocation);
2751 heap_object->set_map_after_allocation(isolate(), *fixed_array_map(),
2754 result->set_length(new_len);
2755 // Copy the content.
2756 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
2757 result->CopyElements(isolate(), 0, *array, 0, new_len, mode);
2758 return handle(result, isolate());
2759}
2760
2762 if (array->length() == 0) return array;
2764 direct_handle(array->map(), isolate()));
2765}
2766
2769 int len = array->length();
2770 if (len == 0) return array;
2773 Heap::CopyBlock(
2774 result->address() + offsetof(FixedDoubleArray, length_),
2775 array->address() + offsetof(FixedDoubleArray, length_),
2777 return result;
2778}
2779
2781 ReadOnlyRoots roots(isolate());
2782 auto num = isolate()->roots_table().FindHeapNumber(value);
2783 if (!num.is_null()) return num;
2784 // Add known HeapNumber constants to the read only roots. This ensures
2785 // r/o snapshots to be deterministic.
2788}
2789
2791 DirectHandle<JSFunction> constructor, MessageTemplate template_index,
2793 HandleScope scope(isolate());
2794
2796 isolate(), constructor, template_index, args, SKIP_NONE));
2797}
2798
2800 DirectHandle<String> message,
2801 DirectHandle<Object> options) {
2802 // Construct a new error object. If an exception is thrown, use the exception
2803 // as the result.
2804
2805 DirectHandle<Object> no_caller;
2806 if (options.is_null()) options = undefined_value();
2807 return ErrorUtils::Construct(isolate(), constructor, constructor, message,
2808 options, SKIP_NONE, no_caller,
2810 .ToHandleChecked();
2811}
2812
2819
2821 if (v8_flags.correctness_fuzzer_suppressions) {
2822 FATAL("Aborting on invalid string length");
2823 }
2824 // Invalidate the "string length" protector.
2825 if (Protectors::IsStringLengthOverflowLookupChainIntact(isolate())) {
2826 Protectors::InvalidateStringLengthOverflowLookupChain(isolate());
2827 }
2828 return NewRangeError(MessageTemplate::kInvalidStringLength);
2829}
2830
2832 Isolate* isolate, DirectHandle<Object> error,
2833 DirectHandle<Object> suppressed_error) {
2835 NewSuppressedError(MessageTemplate::kSuppressedErrorDuringDisposal);
2836
2838 err, isolate->factory()->error_string(), error, DONT_ENUM)
2839 .Assert();
2840
2842 err, isolate->factory()->suppressed_string(), suppressed_error, DONT_ENUM)
2843 .Assert();
2844
2845 return err;
2846}
2847
2848#define DEFINE_ERROR(NAME, name) \
2849 Handle<JSObject> Factory::New##NAME( \
2850 MessageTemplate template_index, \
2851 base::Vector<const DirectHandle<Object>> args) { \
2852 return NewError(isolate()->name##_function(), template_index, args); \
2853 }
2854DEFINE_ERROR(Error, error)
2855DEFINE_ERROR(EvalError, eval_error)
2856DEFINE_ERROR(RangeError, range_error)
2857DEFINE_ERROR(ReferenceError, reference_error)
2858DEFINE_ERROR(SyntaxError, syntax_error)
2859DEFINE_ERROR(SuppressedError, suppressed_error)
2860DEFINE_ERROR(TypeError, type_error)
2861DEFINE_ERROR(WasmCompileError, wasm_compile_error)
2862DEFINE_ERROR(WasmLinkError, wasm_link_error)
2863DEFINE_ERROR(WasmSuspendError, wasm_suspend_error)
2864DEFINE_ERROR(WasmRuntimeError, wasm_runtime_error)
2865#undef DEFINE_ERROR
2866
2868 DirectHandle<JSFunction> function) {
2869 // Make sure to use globals from the function's context, since the function
2870 // can be from a different context.
2871 DirectHandle<NativeContext> native_context(function->native_context(),
2872 isolate());
2873 DirectHandle<Map> new_map;
2874 if (V8_UNLIKELY(IsAsyncGeneratorFunction(function->shared()->kind()))) {
2875 new_map = direct_handle(
2876 native_context->async_generator_object_prototype_map(), isolate());
2877 } else if (IsResumableFunction(function->shared()->kind())) {
2878 // Generator and async function prototypes can share maps since they
2879 // don't have "constructor" properties.
2880 new_map = direct_handle(native_context->generator_object_prototype_map(),
2881 isolate());
2882 } else {
2883 // Each function prototype gets a fresh map to avoid unwanted sharing of
2884 // maps between prototypes of different constructors.
2885 DirectHandle<JSFunction> object_function(native_context->object_function(),
2886 isolate());
2887 DCHECK(object_function->has_initial_map());
2888 new_map = direct_handle(object_function->initial_map(), isolate());
2889 }
2890
2891 DCHECK(!new_map->is_prototype_map());
2892 DirectHandle<JSObject> prototype = NewJSObjectFromMap(new_map);
2893
2894 if (!IsResumableFunction(function->shared()->kind())) {
2895 JSObject::AddProperty(isolate(), prototype, constructor_string(), function,
2896 DONT_ENUM);
2897 }
2898
2899 return prototype;
2900}
2901
2903 AllocationType allocation_type) {
2904 auto external = Cast<JSExternalObject>(
2905 NewJSObjectFromMap(external_map(), allocation_type));
2906 external->init_value(isolate(), value);
2907 return external;
2908}
2909
2911 DirectHandle<Code> code, Address off_heap_entry) {
2912 CHECK_NOT_NULL(isolate()->embedded_blob_code());
2913 CHECK_NE(0, isolate()->embedded_blob_code_size());
2915
2916 DCHECK(code->has_instruction_stream()); // Just generated as on-heap code.
2917 DCHECK(Builtins::IsBuiltinId(code->builtin_id()));
2918 DCHECK_EQ(code->inlined_bytecode_size(), 0);
2919 DCHECK_EQ(code->osr_offset(), BytecodeOffset::None());
2920 DCHECK_EQ(code->raw_deoptimization_data_or_interpreter_data(), Smi::zero());
2921 // .. because we don't explicitly initialize these flags:
2922 DCHECK(!code->marked_for_deoptimization());
2923 DCHECK(!code->can_have_weak_objects());
2924 DCHECK(!code->embedded_objects_cleared());
2925 // This check would fail. We explicitly clear any existing position tables
2926 // below. Note this isn't strictly necessary - we could keep the position
2927 // tables if we'd properly allocate them into RO space when needed.
2928 // DCHECK_EQ(code->raw_position_table(), *empty_byte_array());
2929
2930 NewCodeOptions new_code_options = {
2931 code->kind(),
2932 code->builtin_id(),
2933 code->is_context_specialized(),
2934 code->is_turbofanned(),
2935 code->parameter_count(),
2936 code->instruction_size(),
2937 code->metadata_size(),
2938 code->inlined_bytecode_size(),
2939 code->osr_offset(),
2940 code->handler_table_offset(),
2941 code->constant_pool_offset(),
2942 code->code_comments_offset(),
2943 code->builtin_jump_table_info_offset(),
2944 code->unwinding_info_offset(),
2947 /*bytecode_offset_table=*/MaybeHandle<TrustedByteArray>{},
2948 /*source_position_table=*/MaybeHandle<TrustedByteArray>{},
2950 off_heap_entry,
2951 };
2952
2953 return NewCode(new_code_options);
2954}
2955
2959 int size = BytecodeArray::SizeFor(source->length());
2961 size, AllocationType::kTrusted, *bytecode_array_map()));
2963 Tagged<BytecodeArray> raw_source = *source;
2964 copy->init_self_indirect_pointer(isolate());
2965 copy->set_length(raw_source->length());
2966 copy->set_frame_size(raw_source->frame_size());
2967 copy->set_parameter_count(raw_source->parameter_count());
2968 copy->set_max_arguments(raw_source->max_arguments());
2969 copy->set_incoming_new_target_or_generator_register(
2970 raw_source->incoming_new_target_or_generator_register());
2971 copy->set_constant_pool(raw_source->constant_pool());
2972 copy->set_handler_table(raw_source->handler_table());
2973 copy->set_wrapper(*wrapper);
2974 if (raw_source->has_source_position_table(kAcquireLoad)) {
2975 copy->set_source_position_table(
2976 raw_source->source_position_table(kAcquireLoad), kReleaseStore);
2977 } else {
2978 copy->clear_source_position_table(kReleaseStore);
2979 }
2980 raw_source->CopyBytecodesTo(copy);
2981 wrapper->set_bytecode(copy);
2982 return direct_handle(copy, isolate());
2983}
2984
2986 AllocationType allocation,
2987 NewJSObjectType new_js_object_type) {
2989 DirectHandle<Map> map(constructor->initial_map(), isolate());
2990 // NewJSObjectFromMap does not support creating dictionary mode objects. Need
2991 // to use NewSlowJSObjectFromMap instead.
2992 DCHECK(!map->is_dictionary_map());
2993 return NewJSObjectFromMap(map, allocation,
2995 new_js_object_type);
2996}
2997
3000 NewSlowJSObjectFromMap(isolate()->slow_object_with_null_prototype_map());
3001 return result;
3002}
3003
3005 DirectHandle<Map> map(isolate()->object_function()->initial_map(), isolate());
3006 DirectHandle<Map> map_with_null_proto =
3008 null_value());
3009 return NewJSObjectFromMap(map_with_null_proto);
3010}
3011
3013 DirectHandle<JSFunction> constructor) {
3014 DCHECK(constructor->has_initial_map());
3015 DirectHandle<Map> map(constructor->initial_map(), isolate());
3016 DCHECK(map->is_dictionary_map());
3017
3018 // Make sure no field properties are described in the initial map.
3019 // This guarantees us that normalizing the properties does not
3020 // require us to change property values to PropertyCells.
3021 DCHECK_EQ(map->NextFreePropertyIndex(), 0);
3022
3023 // Make sure we don't have a ton of pre-allocated slots in the
3024 // global objects. They will be unused once we normalize the object.
3025 DCHECK_EQ(map->UnusedPropertyFields(), 0);
3026 DCHECK_EQ(map->GetInObjectProperties(), 0);
3027
3028 // Initial size of the backing store to avoid resize of the storage during
3029 // bootstrapping. The size differs between the JS global object ad the
3030 // builtins object.
3031 int initial_size = 64;
3032
3033 // Allocate a dictionary object for backing storage.
3034 int at_least_space_for = map->NumberOfOwnDescriptors() * 2 + initial_size;
3035 Handle<GlobalDictionary> dictionary =
3036 GlobalDictionary::New(isolate(), at_least_space_for);
3037
3038 // The global object might be created from an object template with accessors.
3039 // Fill these accessors into the dictionary.
3040 DirectHandle<DescriptorArray> descs(map->instance_descriptors(isolate()),
3041 isolate());
3042 for (InternalIndex i : map->IterateOwnDescriptors()) {
3043 PropertyDetails details = descs->GetDetails(i);
3044 // Only accessors are expected.
3048 DirectHandle<Name> name(descs->GetKey(i), isolate());
3049 DirectHandle<Object> value(descs->GetStrongValue(i), isolate());
3050 DirectHandle<PropertyCell> cell = NewPropertyCell(name, d, value);
3051 // |dictionary| already contains enough space for all properties.
3052 USE(GlobalDictionary::Add(isolate(), dictionary, name, cell, d));
3053 }
3054
3055 // Allocate the global object and initialize it with the backing store.
3058 InitializeJSObjectFromMap(*global, *dictionary, *map,
3060
3061 // Create a new map for the global object.
3063 Tagged<Map> raw_map = *new_map;
3064 raw_map->set_may_have_interesting_properties(true);
3065 raw_map->set_is_dictionary_map(true);
3066 LOG(isolate(), MapDetails(raw_map));
3067
3068 // Set up the global object as a normalized object.
3069 global->set_global_dictionary(*dictionary, kReleaseStore);
3070 global->set_map(isolate(), raw_map, kReleaseStore);
3071
3072 // Make sure result is a global object with properties in dictionary.
3073 DCHECK(IsJSGlobalObject(*global) && !global->HasFastProperties());
3074 return global;
3075}
3076
3079 DCHECK(IsJSAPIObjectWithEmbedderSlots(obj) || IsJSSpecialObject(obj));
3080 static_assert(JSSpecialObject::kCppHeapWrappableOffset ==
3081 JSAPIObjectWithEmbedderSlots::kCppHeapWrappableOffset);
3082 obj->SetupLazilyInitializedCppHeapPointerField(
3083 JSAPIObjectWithEmbedderSlots::kCppHeapWrappableOffset);
3084}
3085
3087 Tagged<Object> properties,
3088 Tagged<Map> map,
3089 NewJSObjectType new_js_object_type) {
3091 obj->set_raw_properties_or_hash(properties, kRelaxedStore);
3092 obj->initialize_elements();
3093 // TODO(1240798): Initialize the object's body using valid initial values
3094 // according to the object's initial map. For example, if the map's
3095 // instance type is JS_ARRAY_TYPE, the length field should be initialized
3096 // to a number (e.g. Smi::zero()) and the elements initialized to a
3097 // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object
3098 // verification code has to cope with (temporarily) invalid objects. See
3099 // for example, JSArray::JSArrayVerify).
3101 new_js_object_type == NewJSObjectType::kAPIWrapper);
3102 InitializeJSObjectBody(obj, map,
3103 new_js_object_type == NewJSObjectType::kNoAPIWrapper
3104 ? JSObject::kHeaderSize
3105 : JSAPIObjectWithEmbedderSlots::kHeaderSize);
3106 if (new_js_object_type == NewJSObjectType::kAPIWrapper) {
3108 }
3109}
3110
3112 int start_offset) {
3114 if (start_offset == map->instance_size()) return;
3115 DCHECK_LT(start_offset, map->instance_size());
3116
3117 // We cannot always fill with one_pointer_filler_map because objects
3118 // created from API functions expect their embedder fields to be initialized
3119 // with undefined_value.
3120 // Pre-allocated fields need to be initialized with undefined_value as well
3121 // so that object accesses before the constructor completes (e.g. in the
3122 // debugger) will not cause a crash.
3123
3124 // In case of Array subclassing the |map| could already be transitioned
3125 // to different elements kind from the initial map on which we track slack.
3126 bool in_progress = map->IsInobjectSlackTrackingInProgress();
3127 obj->InitializeBody(map, start_offset, in_progress,
3128 ReadOnlyRoots(isolate()).one_pointer_filler_map_word(),
3129 *undefined_value());
3130 if (in_progress) {
3131 map->FindRootMap(isolate())->InobjectSlackTrackingStep(isolate());
3132 }
3133}
3134
3136 DirectHandle<Map> map, AllocationType allocation,
3137 DirectHandle<AllocationSite> allocation_site,
3138 NewJSObjectType new_js_object_type) {
3139 // JSFunctions should be allocated using AllocateFunction to be
3140 // properly initialized.
3141 DCHECK(!InstanceTypeChecker::IsJSFunction(*map));
3142
3143 // Both types of global objects should be allocated using
3144 // AllocateGlobalObject to be properly initialized.
3145 DCHECK_NE(map->instance_type(), JS_GLOBAL_OBJECT_TYPE);
3146
3148 AllocateRawWithAllocationSite(map, allocation, allocation_site));
3149
3150 InitializeJSObjectFromMap(js_obj, *empty_fixed_array(), *map,
3151 new_js_object_type);
3152
3153 DCHECK(js_obj->HasFastElements() ||
3154 (isolate()->bootstrapper()->IsActive() ||
3155 *map == isolate()
3156 ->raw_native_context()
3157 ->js_array_template_literal_object_map()) ||
3158 js_obj->HasTypedArrayOrRabGsabTypedArrayElements() ||
3159 js_obj->HasFastStringWrapperElements() ||
3160 js_obj->HasFastArgumentsElements() ||
3161 js_obj->HasDictionaryElements() || js_obj->HasSharedArrayElements());
3162 return handle(js_obj, isolate());
3163}
3164
3166 DirectHandle<Map> map, int capacity, AllocationType allocation,
3167 DirectHandle<AllocationSite> allocation_site,
3168 NewJSObjectType new_js_object_type) {
3169 DCHECK(map->is_dictionary_map());
3170 DirectHandle<HeapObject> object_properties;
3172 object_properties = NewSwissNameDictionary(capacity, allocation);
3173 } else {
3174 object_properties = NameDictionary::New(isolate(), capacity);
3175 }
3176 Handle<JSObject> js_object =
3177 NewJSObjectFromMap(map, allocation, allocation_site, new_js_object_type);
3178 js_object->set_raw_properties_or_hash(*object_properties, kRelaxedStore);
3179 return js_object;
3180}
3181
3185
3189 DCHECK(IsPropertyDictionary(*properties));
3190
3191 DirectHandle<Map> object_map =
3192 isolate()->slow_object_with_object_prototype_map();
3193 if (object_map->prototype() != *prototype) {
3195 isolate(), object_map, prototype);
3196 }
3197 DCHECK(object_map->is_dictionary_map());
3198 DirectHandle<JSObject> object =
3200 object->set_raw_properties_or_hash(*properties);
3201 if (*elements != read_only_roots().empty_fixed_array()) {
3202 DCHECK(IsNumberDictionary(*elements));
3203 object_map =
3205 JSObject::MigrateToMap(isolate(), object, object_map);
3206 object->set_elements(*elements);
3207 }
3208 return object;
3209}
3210
3212 int capacity,
3214 AllocationType allocation) {
3215 DCHECK(capacity >= length);
3216 if (capacity == 0) {
3217 return NewJSArrayWithElements(empty_fixed_array(), elements_kind, length,
3218 allocation);
3219 }
3220
3221 HandleScope inner_scope(isolate());
3223 NewJSArrayStorage(elements_kind, capacity, mode);
3225 elms, elements_kind, length, allocation));
3226}
3227
3229 DirectHandle<FixedArrayBase> elements, ElementsKind elements_kind,
3230 int length, AllocationType allocation) {
3232 elements, elements_kind, length, allocation);
3233#ifdef ENABLE_SLOW_DCHECKS
3235#endif
3236 return array;
3237}
3238
3240 DirectHandle<FixedArrayBase> elements, ElementsKind elements_kind,
3241 int length, AllocationType allocation) {
3244 Tagged<Map> map = native_context->GetInitialJSArrayMap(elements_kind);
3245 if (map.is_null()) {
3246 Tagged<JSFunction> array_function = native_context->array_function();
3247 map = array_function->initial_map();
3248 }
3250 elements, length, allocation);
3251}
3252
3254 DirectHandle<Map> map, DirectHandle<FixedArrayBase> elements, int length,
3255 AllocationType allocation) {
3256 auto array = Cast<JSArray>(NewJSObjectFromMap(map, allocation));
3258 Tagged<JSArray> raw = *array;
3259 raw->set_elements(*elements);
3260 raw->set_length(Smi::FromInt(length));
3261 return array;
3262}
3263
3265 DirectHandle<FixedArray> cooked_strings,
3266 DirectHandle<FixedArray> raw_strings, int function_literal_id,
3267 int slot_id) {
3268 DirectHandle<JSArray> raw_object =
3270 raw_strings->length(), AllocationType::kOld);
3271 JSObject::SetIntegrityLevel(isolate(), raw_object, FROZEN, kThrowOnError)
3272 .ToChecked();
3273
3275 auto template_object =
3277 direct_handle(native_context->js_array_template_literal_object_map(),
3278 isolate()),
3279 cooked_strings, cooked_strings->length(), AllocationType::kOld));
3281 Tagged<TemplateLiteralObject> raw_template_object = *template_object;
3282 DCHECK_EQ(raw_template_object->map(),
3283 native_context->js_array_template_literal_object_map());
3284 raw_template_object->set_raw(*raw_object);
3285 raw_template_object->set_function_literal_id(function_literal_id);
3286 raw_template_object->set_slot_id(slot_id);
3287 return template_object;
3288}
3289
3291 int capacity, ArrayStorageAllocationMode mode) {
3292 DCHECK(capacity >= length);
3293
3294 if (capacity == 0) {
3295 Tagged<JSArray> raw = *array;
3297 raw->set_length(Smi::zero());
3298 raw->set_elements(*empty_fixed_array());
3299 return;
3300 }
3301
3302 HandleScope inner_scope(isolate());
3304 NewJSArrayStorage(array->GetElementsKind(), capacity, mode);
3306 Tagged<JSArray> raw = *array;
3307 raw->set_elements(*elms);
3308 raw->set_length(Smi::FromInt(length));
3309}
3310
3312 ElementsKind elements_kind, int capacity, ArrayStorageAllocationMode mode) {
3313 DCHECK_GT(capacity, 0);
3315 if (IsDoubleElementsKind(elements_kind)) {
3317 elms = NewFixedDoubleArray(capacity);
3318 } else {
3319 DCHECK_EQ(
3320 mode,
3322 elms = NewFixedDoubleArrayWithHoles(capacity);
3323 }
3324 } else {
3325 DCHECK(IsSmiOrObjectElementsKind(elements_kind));
3327 elms = NewFixedArray(capacity);
3328 } else {
3329 DCHECK_EQ(
3330 mode,
3332 elms = NewFixedArrayWithHoles(capacity);
3333 }
3334 }
3335 return elms;
3336}
3337
3340 DirectHandle<Map> map(native_context->js_weak_map_fun()->initial_map(),
3341 isolate());
3343 isolate());
3344 {
3345 // Do not leak handles for the hash table, it would make entries strong.
3346 HandleScope scope(isolate());
3348 }
3349 return weakmap;
3350}
3351
3353 DirectHandle<Map> map = isolate()->js_module_namespace_map();
3354 DirectHandle<JSModuleNamespace> module_namespace(
3360 module_namespace->FastPropertyAtPut(index, read_only_roots().Module_string(),
3362 return module_namespace;
3363}
3364
3366 DirectHandle<NativeContext> creation_context, DirectHandle<Object> target) {
3367 DCHECK(IsCallable(*target));
3369 Cast<Map>(creation_context->get(Context::WRAPPED_FUNCTION_MAP_INDEX)),
3370 isolate());
3371 // 2. Let wrapped be ! MakeBasicObject(internalSlotsList).
3372 // 3. Set wrapped.[[Prototype]] to
3373 // callerRealm.[[Intrinsics]].[[%Function->prototype%]].
3374 // 4. Set wrapped.[[Call]] as described in 2.1.
3377 // 5. Set wrapped.[[WrappedTargetFunction]] to Target.
3378 wrapped->set_wrapped_target_function(Cast<JSCallable>(*target));
3379 // 6. Set wrapped.[[Realm]] to callerRealm.
3380 wrapped->set_context(*creation_context);
3381 // TODO(v8:11989): https://github.com/tc39/proposal-shadowrealm/pull/348
3382
3383 return wrapped;
3384}
3385
3387 DirectHandle<JSFunction> function) {
3388 DCHECK(IsResumableFunction(function->shared()->kind()));
3390 DirectHandle<Map> map(function->initial_map(), isolate());
3391
3392 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE ||
3393 map->instance_type() == JS_ASYNC_GENERATOR_OBJECT_TYPE);
3394
3396}
3397
3400 DirectHandle<Map> map(native_context->js_disposable_stack_map(), isolate());
3401 DirectHandle<JSDisposableStackBase> disposable_stack(
3403 disposable_stack->set_status(0);
3404 return disposable_stack;
3405}
3406
3408 DirectHandle<Map> map) {
3409 DirectHandle<JSSyncDisposableStack> disposable_stack(
3411 disposable_stack->set_status(0);
3412 return disposable_stack;
3413}
3414
3416 DirectHandle<Map> map) {
3417 DirectHandle<JSAsyncDisposableStack> disposable_stack(
3419 disposable_stack->set_status(0);
3420 return disposable_stack;
3421}
3422
3426 sfi->scope_info()->ModuleDescriptorInfo(), isolate());
3428 ObjectHashTable::New(isolate(), module_info->RegularExportCount());
3429 DirectHandle<FixedArray> regular_exports =
3430 NewFixedArray(module_info->RegularExportCount());
3431 DirectHandle<FixedArray> regular_imports =
3432 NewFixedArray(module_info->regular_imports()->length());
3433 int requested_modules_length = module_info->module_requests()->length();
3434 DirectHandle<FixedArray> requested_modules =
3435 requested_modules_length > 0 ? NewFixedArray(requested_modules_length)
3436 : empty_fixed_array();
3437
3438 ReadOnlyRoots roots(isolate());
3440 New(source_text_module_map(), AllocationType::kOld));
3442 module->set_code(*sfi);
3443 module->set_exports(*exports);
3444 module->set_regular_exports(*regular_exports);
3445 module->set_regular_imports(*regular_imports);
3446 module->set_hash(isolate()->GenerateIdentityHash(Smi::kMaxValue));
3447 module->set_module_namespace(roots.undefined_value(), SKIP_WRITE_BARRIER);
3448 module->set_requested_modules(*requested_modules);
3449 module->set_status(Module::kUnlinked);
3450 module->set_exception(roots.the_hole_value(), SKIP_WRITE_BARRIER);
3451 module->set_top_level_capability(roots.undefined_value(), SKIP_WRITE_BARRIER);
3452 module->set_import_meta(roots.the_hole_value(), kReleaseStore,
3453 SKIP_WRITE_BARRIER);
3454 module->set_dfs_index(-1);
3455 module->set_dfs_ancestor_index(-1);
3456 module->set_flags(0);
3457 module->set_has_toplevel_await(IsModuleWithTopLevelAwait(sfi->kind()));
3458 module->set_async_evaluation_ordinal(SourceTextModule::kNotAsyncEvaluated);
3459 module->set_cycle_root(roots.the_hole_value(), SKIP_WRITE_BARRIER);
3460 module->set_async_parent_modules(roots.empty_array_list());
3461 module->set_pending_async_dependencies(0);
3462 return direct_handle(module, isolate());
3463}
3464
3466 DirectHandle<String> module_name, DirectHandle<FixedArray> export_names,
3468 ReadOnlyRoots roots(isolate());
3469
3471 ObjectHashTable::New(isolate(), static_cast<int>(export_names->length()));
3472 DirectHandle<Foreign> evaluation_steps_foreign =
3474 reinterpret_cast<Address>(evaluation_steps));
3475
3477 Cast<SyntheticModule>(New(synthetic_module_map(), AllocationType::kOld));
3479 module->set_hash(isolate()->GenerateIdentityHash(Smi::kMaxValue));
3480 module->set_module_namespace(roots.undefined_value(), SKIP_WRITE_BARRIER);
3481 module->set_status(Module::kUnlinked);
3482 module->set_exception(roots.the_hole_value(), SKIP_WRITE_BARRIER);
3483 module->set_top_level_capability(roots.undefined_value(), SKIP_WRITE_BARRIER);
3484 module->set_name(*module_name);
3485 module->set_export_names(*export_names);
3486 module->set_exports(*exports);
3487 module->set_evaluation_steps(*evaluation_steps_foreign);
3488 return handle(module, isolate());
3489}
3490
3492 std::shared_ptr<BackingStore> backing_store, AllocationType allocation) {
3494 isolate()->native_context()->array_buffer_fun()->initial_map(),
3495 isolate());
3497 if (backing_store->is_resizable_by_js()) {
3498 resizable_by_js = ResizableFlag::kResizable;
3499 }
3503 result->Setup(SharedFlag::kNotShared, resizable_by_js,
3504 std::move(backing_store), isolate());
3505 return result;
3506}
3507
3509 size_t byte_length, InitializedFlag initialized,
3510 AllocationType allocation) {
3511 return NewJSArrayBufferAndBackingStore(byte_length, byte_length, initialized,
3513 allocation);
3514}
3515
3517 size_t byte_length, size_t max_byte_length, InitializedFlag initialized,
3518 ResizableFlag resizable, AllocationType allocation) {
3519 DCHECK_LE(byte_length, max_byte_length);
3520 std::unique_ptr<BackingStore> backing_store = nullptr;
3521
3522 if (resizable == ResizableFlag::kResizable) {
3523 size_t page_size, initial_pages, max_pages;
3525 isolate(), byte_length, max_byte_length, kDontThrow, &page_size,
3526 &initial_pages, &max_pages)
3527 .IsNothing()) {
3529 }
3530
3532 isolate(), byte_length, max_byte_length, page_size, initial_pages,
3534 if (!backing_store) return MaybeHandle<JSArrayBuffer>();
3535 } else {
3536 if (byte_length > 0) {
3537 backing_store = BackingStore::Allocate(
3538 isolate(), byte_length, SharedFlag::kNotShared, initialized);
3539 if (!backing_store) return MaybeHandle<JSArrayBuffer>();
3540 }
3541 }
3543 isolate()->native_context()->array_buffer_fun()->initial_map(),
3544 isolate());
3545 auto array_buffer = Cast<JSArrayBuffer>(
3548 array_buffer->Setup(SharedFlag::kNotShared, resizable,
3549 std::move(backing_store), isolate());
3550 return array_buffer;
3551}
3552
3554 std::shared_ptr<BackingStore> backing_store) {
3556 isolate()->native_context()->shared_array_buffer_fun()->initial_map(),
3557 isolate());
3561 ResizableFlag resizable = backing_store->is_resizable_by_js()
3564 result->Setup(SharedFlag::kShared, resizable, std::move(backing_store),
3565 isolate());
3566 return result;
3567}
3568
3570 DirectHandle<Object> value, bool done) {
3571 DirectHandle<Map> map(isolate()->native_context()->iterator_result_map(),
3572 isolate());
3573 DirectHandle<JSIteratorResult> js_iter_result =
3576 Tagged<JSIteratorResult> raw = *js_iter_result;
3577 raw->set_value(*value, SKIP_WRITE_BARRIER);
3578 raw->set_done(*ToBoolean(done), SKIP_WRITE_BARRIER);
3579 return js_iter_result;
3580}
3581
3583 DirectHandle<JSReceiver> sync_iterator, DirectHandle<Object> next) {
3585 isolate()->native_context()->async_from_sync_iterator_map(), isolate());
3590 Tagged<JSAsyncFromSyncIterator> raw = *iterator;
3591 raw->set_sync_iterator(*sync_iterator, SKIP_WRITE_BARRIER);
3592 raw->set_next(*next, SKIP_WRITE_BARRIER);
3593 return iterator;
3594}
3595
3597 DirectHandle<Map> map(isolate()->native_context()->js_map_map(), isolate());
3599 JSMap::Initialize(js_map, isolate());
3600 return js_map;
3601}
3602
3604 DirectHandle<Map> map(isolate()->native_context()->js_set_map(), isolate());
3606 JSSet::Initialize(js_set, isolate());
3607 return js_set;
3608}
3609
3611 ExternalArrayType* array_type,
3612 size_t* element_size) {
3613 switch (kind) {
3614#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) \
3615 case TYPE##_ELEMENTS: \
3616 *array_type = kExternal##Type##Array; \
3617 *element_size = sizeof(ctype); \
3618 break;
3621#undef TYPED_ARRAY_CASE
3622
3623 default:
3624 UNREACHABLE();
3625 }
3626}
3627
3630 DirectHandle<JSArrayBuffer> buffer, size_t byte_offset,
3631 size_t byte_length) {
3632 if (!IsRabGsabTypedArrayElementsKind(map->elements_kind())) {
3633 CHECK_LE(byte_length, buffer->GetByteLength());
3634 CHECK_LE(byte_offset, buffer->GetByteLength());
3635 CHECK_LE(byte_offset + byte_length, buffer->GetByteLength());
3636 }
3637
3638 Handle<JSArrayBufferView> array_buffer_view =
3643 Tagged<JSArrayBufferView> raw = *array_buffer_view;
3644 raw->set_elements(*elements, SKIP_WRITE_BARRIER);
3645 raw->set_buffer(*buffer, SKIP_WRITE_BARRIER);
3646 raw->set_byte_offset(byte_offset);
3647 raw->set_byte_length(byte_length);
3648 raw->set_bit_field(0);
3649 // TODO(v8) remove once embedder data slots are always zero-initialized.
3650 InitEmbedderFields(raw, Smi::zero());
3651 DCHECK_EQ(raw->GetEmbedderFieldCount(),
3653 return array_buffer_view;
3654}
3655
3658 size_t byte_offset, size_t length, bool is_length_tracking) {
3659 size_t element_size;
3660 ElementsKind elements_kind;
3661 JSTypedArray::ForFixedTypedArray(type, &element_size, &elements_kind);
3662
3663 const bool is_backed_by_rab =
3664 buffer->is_resizable_by_js() && !buffer->is_shared();
3665
3667 if (is_backed_by_rab || is_length_tracking) {
3668 map = direct_handle(
3669 isolate()->raw_native_context()->TypedArrayElementsKindToRabGsabCtorMap(
3670 elements_kind),
3671 isolate());
3672 } else {
3673 map = direct_handle(
3674 isolate()->raw_native_context()->TypedArrayElementsKindToCtorMap(
3675 elements_kind),
3676 isolate());
3677 }
3678
3679 if (is_length_tracking) {
3680 // Security: enforce the invariant that length-tracking TypedArrays have
3681 // their length and byte_length set to 0.
3682 length = 0;
3683 }
3684
3685 CHECK_LE(length, JSTypedArray::kMaxByteLength / element_size);
3686 CHECK_EQ(0, byte_offset % element_size);
3687 size_t byte_length = length * element_size;
3688
3690 map, empty_byte_array(), buffer, byte_offset, byte_length));
3691 Tagged<JSTypedArray> raw = *typed_array;
3693 raw->set_length(length);
3694 raw->SetOffHeapDataPtr(isolate(), buffer->backing_store(), byte_offset);
3695 raw->set_is_length_tracking(is_length_tracking);
3696 raw->set_is_backed_by_rab(is_backed_by_rab);
3697 return typed_array;
3698}
3699
3701 DirectHandle<JSArrayBuffer> buffer, size_t byte_offset, size_t byte_length,
3702 bool is_length_tracking) {
3703 if (is_length_tracking) {
3704 // Security: enforce the invariant that length-tracking DataViews have their
3705 // byte_length set to 0.
3706 byte_length = 0;
3707 }
3708 bool is_backed_by_rab = !buffer->is_shared() && buffer->is_resizable_by_js();
3710 if (is_backed_by_rab || is_length_tracking) {
3711 map = direct_handle(
3712 isolate()->native_context()->js_rab_gsab_data_view_map(), isolate());
3713 } else {
3714 map = direct_handle(
3715 isolate()->native_context()->data_view_fun()->initial_map(), isolate());
3716 }
3719 map, empty_fixed_array(), buffer, byte_offset, byte_length));
3720 obj->set_data_pointer(
3721 isolate(), static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
3722 obj->set_is_length_tracking(is_length_tracking);
3723 obj->set_is_backed_by_rab(is_backed_by_rab);
3724 return obj;
3725}
3726
3728 DirectHandle<JSReceiver> target_function, DirectHandle<JSAny> bound_this,
3730 DirectHandle<JSPrototype> prototype) {
3731 DCHECK(IsCallable(*target_function));
3733 if (bound_args.length() >= Code::kMaxArguments) {
3735 NewRangeError(MessageTemplate::kTooManyArguments));
3736 }
3737
3739 target_function->GetCreationContext().value());
3740
3741 // Create the [[BoundArguments]] for the result.
3742 DirectHandle<FixedArray> bound_arguments;
3743 if (bound_args.empty()) {
3744 bound_arguments = empty_fixed_array();
3745 } else {
3746 bound_arguments = NewFixedArray(bound_args.length());
3747 for (int i = 0; i < bound_args.length(); ++i) {
3748 bound_arguments->set(i, *bound_args[i]);
3749 }
3750 }
3751
3752 // Setup the map for the JSBoundFunction instance.
3753 DirectHandle<Map> map =
3754 IsConstructor(*target_function)
3755 ? isolate()->bound_function_with_constructor_map()
3756 : isolate()->bound_function_without_constructor_map();
3757 if (map->prototype() != *prototype) {
3759 prototype);
3760 }
3761 DCHECK_EQ(IsConstructor(*target_function), map->is_constructor());
3762
3763 // Setup the JSBoundFunction instance.
3768 raw->set_bound_target_function(Cast<JSCallable>(*target_function),
3770 raw->set_bound_this(*bound_this, SKIP_WRITE_BARRIER);
3771 raw->set_bound_arguments(*bound_arguments, SKIP_WRITE_BARRIER);
3772 return result;
3773}
3774
3775// ES6 section 9.5.15 ProxyCreate (target, handler)
3777 DirectHandle<JSReceiver> handler) {
3778 // Allocate the proxy object.
3779 DirectHandle<Map> map = IsCallable(*target)
3780 ? IsConstructor(*target)
3781 ? isolate()->proxy_constructor_map()
3782 : isolate()->proxy_callable_map()
3783 : isolate()->proxy_map();
3784 DCHECK(IsNull(map->prototype(), isolate()));
3787 result->initialize_properties(isolate());
3788 result->set_target(*target, SKIP_WRITE_BARRIER);
3789 result->set_handler(*handler, SKIP_WRITE_BARRIER);
3790 return handle(result, isolate());
3791}
3792
3794 // Create an empty shell of a JSGlobalProxy that needs to be reinitialized
3795 // via ReinitializeJSGlobalProxy later.
3796 DirectHandle<Map> map = NewContextlessMap(JS_GLOBAL_PROXY_TYPE, size);
3797 // Maintain invariant expected from any JSGlobalProxy.
3798 {
3800 Tagged<Map> raw = *map;
3801 raw->set_is_access_check_needed(true);
3802 raw->set_may_have_interesting_properties(true);
3803 LOG(isolate(), MapDetails(raw));
3804 }
3808 // Create identity hash early in case there is any JS collection containing
3809 // a global proxy key and needs to be rehashed after deserialization.
3810 proxy->GetOrCreateIdentityHash(isolate());
3811 return proxy;
3812}
3813
3815 DirectHandle<JSFunction> constructor) {
3816 DCHECK(constructor->has_initial_map());
3817 DirectHandle<Map> map(constructor->initial_map(), isolate());
3818 DirectHandle<Map> old_map(object->map(), isolate());
3819
3820 // The proxy's hash should be retained across reinitialization.
3821 DirectHandle<Object> raw_properties_or_hash(object->raw_properties_or_hash(),
3822 isolate());
3823
3824 if (old_map->is_prototype_map()) {
3825 map = Map::Copy(isolate(), map, "CopyAsPrototypeForJSGlobalProxy");
3826 map->set_is_prototype_map(true);
3827 }
3828 JSObject::NotifyMapChange(old_map, map, isolate());
3829 old_map->NotifyLeafMapLayoutChange(isolate());
3830
3831 // Check that the already allocated object has the same size and type as
3832 // objects allocated using the constructor.
3833 DCHECK(map->instance_size() == old_map->instance_size());
3834 DCHECK(map->instance_type() == old_map->instance_type());
3835
3836 // In order to keep heap in consistent state there must be no allocations
3837 // before object re-initialization is finished.
3839
3840 // Reset the map for the object.
3841 Tagged<JSGlobalProxy> raw = *object;
3842 raw->set_map(isolate(), *map, kReleaseStore);
3843
3844 // Reinitialize the object from the constructor map.
3847 // Ensure that the object and constructor belongs to the same native context.
3848 DCHECK_EQ(object->map()->map(), constructor->map()->map());
3849}
3850
3852 MessageTemplate message, DirectHandle<Object> argument, int start_position,
3853 int end_position, DirectHandle<SharedFunctionInfo> shared_info,
3854 int bytecode_offset, DirectHandle<Script> script,
3855 DirectHandle<StackTraceInfo> stack_trace) {
3856 DirectHandle<Map> map = message_object_map();
3857 Tagged<JSMessageObject> message_obj =
3860 message_obj->set_raw_properties_or_hash(*empty_fixed_array(),
3862 message_obj->initialize_elements();
3863 message_obj->set_elements(*empty_fixed_array(), SKIP_WRITE_BARRIER);
3864 message_obj->set_type(message);
3865 message_obj->set_argument(*argument, SKIP_WRITE_BARRIER);
3866 message_obj->set_start_position(start_position);
3867 message_obj->set_end_position(end_position);
3868 message_obj->set_script(*script, SKIP_WRITE_BARRIER);
3869 if (start_position >= 0) {
3870 // If there's a start_position, then there's no need to store the
3871 // SharedFunctionInfo as it will never be necessary to regenerate the
3872 // position.
3873 message_obj->set_shared_info(Smi::FromInt(-1));
3874 message_obj->set_bytecode_offset(Smi::FromInt(0));
3875 } else {
3876 message_obj->set_bytecode_offset(Smi::FromInt(bytecode_offset));
3877 if (shared_info.is_null()) {
3878 message_obj->set_shared_info(Smi::FromInt(-1));
3879 DCHECK_EQ(bytecode_offset, -1);
3880 } else {
3881 message_obj->set_shared_info(*shared_info, SKIP_WRITE_BARRIER);
3882 DCHECK_GE(bytecode_offset, kFunctionEntryBytecodeOffset);
3883 }
3884 }
3885
3886 if (stack_trace.is_null()) {
3887 message_obj->set_stack_trace(*the_hole_value(), SKIP_WRITE_BARRIER);
3888 } else {
3889 message_obj->set_stack_trace(*stack_trace, SKIP_WRITE_BARRIER);
3890 }
3891 message_obj->set_error_level(v8::Isolate::kMessageError);
3892 return handle(message_obj, isolate());
3893}
3894
3896 MaybeDirectHandle<String> maybe_name,
3897 DirectHandle<FunctionTemplateInfo> function_template_info,
3899 return NewSharedFunctionInfo(
3900 maybe_name, function_template_info, Builtin::kNoBuiltinId,
3901 function_template_info->length(), kDontAdapt, kind);
3902}
3903
3910
3912 DirectHandle<BytecodeArray> bytecode_array, DirectHandle<Code> code) {
3913 Tagged<Map> map = *interpreter_data_map();
3916 *interpreter_data_map()));
3918 interpreter_data->init_self_indirect_pointer(isolate());
3919 interpreter_data->set_bytecode_array(*bytecode_array);
3920 interpreter_data->set_interpreter_trampoline(*code);
3921 return direct_handle(interpreter_data, isolate());
3922}
3923
3925 int mask = (number_string_cache()->length() >> 1) - 1;
3926 return number.value() & mask;
3927}
3928
3930 int mask = (number_string_cache()->length() >> 1) - 1;
3931 int64_t bits = base::bit_cast<int64_t>(number);
3932 return (static_cast<int>(bits) ^ static_cast<int>(bits >> 32)) & mask;
3933}
3934
3935Handle<String> Factory::SizeToString(size_t value, bool check_cache) {
3937 NumberCacheMode cache_mode =
3939 if (value <= Smi::kMaxValue) {
3940 int32_t int32v = static_cast<int32_t>(static_cast<uint32_t>(value));
3941 // SmiToString sets the hash when needed, we can return immediately.
3942 return SmiToString(Smi::FromInt(int32v), cache_mode);
3943 } else if (value <= kMaxSafeInteger) {
3944 // TODO(jkummerow): Refactor the cache to not require Objects as keys.
3945 double double_value = static_cast<double>(value);
3946 result = HeapNumberToString(NewHeapNumber(double_value), value, cache_mode);
3947 } else {
3948 char arr[kNumberToStringBufferSize];
3949 base::Vector<char> buffer(arr, arraysize(arr));
3950 // Build the string backwards from the least significant digit.
3951 int i = buffer.length();
3952 size_t value_copy = value;
3953 buffer[--i] = '\0';
3954 do {
3955 buffer[--i] = '0' + (value_copy % 10);
3956 value_copy /= 10;
3957 } while (value_copy > 0);
3958 char* string = buffer.begin() + i;
3959 // No way to cache this; we'd need an {Object} to use as key.
3961 }
3962 {
3964 Tagged<String> raw = *result;
3965 if (value <= JSArray::kMaxArrayIndex &&
3966 raw->raw_hash_field() == String::kEmptyHashField) {
3967 uint32_t raw_hash_field = StringHasher::MakeArrayIndexHash(
3968 static_cast<uint32_t>(value), raw->length());
3969 raw->set_raw_hash_field(raw_hash_field);
3970 }
3971 }
3972 return result;
3973}
3974
3977 DCHECK(!shared->HasDebugInfo(isolate()));
3978
3979 auto debug_info =
3982 Tagged<SharedFunctionInfo> raw_shared = *shared;
3983 debug_info->set_flags(DebugInfo::kNone, kRelaxedStore);
3984 debug_info->set_shared(raw_shared);
3985 debug_info->set_debugger_hints(0);
3986 DCHECK_EQ(DebugInfo::kNoDebuggingId, debug_info->debugging_id());
3987 debug_info->set_break_points(*empty_fixed_array(), SKIP_WRITE_BARRIER);
3988 debug_info->clear_original_bytecode_array();
3989 debug_info->clear_debug_bytecode_array();
3990
3991 return handle(debug_info, isolate());
3992}
3993
3995 auto new_break_point_info = NewStructInternal<BreakPointInfo>(
3996 BREAK_POINT_INFO_TYPE, AllocationType::kOld);
3998 new_break_point_info->set_source_position(source_position);
3999 new_break_point_info->set_break_points(*undefined_value(),
4001 return direct_handle(new_break_point_info, isolate());
4002}
4003
4006 auto new_break_point =
4009 new_break_point->set_id(id);
4010 new_break_point->set_condition(*condition);
4011 return handle(new_break_point, isolate());
4012}
4013
4015 DirectHandle<JSAny> receiver_or_instance,
4017 DirectHandle<HeapObject> code_object, int code_offset_or_source_position,
4018 int flags, DirectHandle<FixedArray> parameters) {
4019 auto info = NewStructInternal<CallSiteInfo>(CALL_SITE_INFO_TYPE,
4022 info->set_receiver_or_instance(*receiver_or_instance, SKIP_WRITE_BARRIER);
4023 info->set_function(*function, SKIP_WRITE_BARRIER);
4024 info->set_code_object(*code_object, SKIP_WRITE_BARRIER);
4025 info->set_code_offset_or_source_position(code_offset_or_source_position);
4026 info->set_flags(flags);
4027 info->set_parameters(*parameters, SKIP_WRITE_BARRIER);
4028 return handle(info, isolate());
4029}
4030
4033 int bytecode_offset_or_source_position, DirectHandle<String> function_name,
4034 bool is_constructor) {
4035 DCHECK_GE(bytecode_offset_or_source_position, 0);
4037 STACK_FRAME_INFO_TYPE, AllocationType::kYoung);
4039 info->set_flags(0);
4040 info->set_shared_or_script(*shared_or_script, SKIP_WRITE_BARRIER);
4041 info->set_bytecode_offset_or_source_position(
4042 bytecode_offset_or_source_position);
4043 info->set_function_name(*function_name, SKIP_WRITE_BARRIER);
4044 info->set_is_constructor(is_constructor);
4045 return direct_handle(info, isolate());
4046}
4047
4049 DirectHandle<FixedArray> frames) {
4051 STACK_TRACE_INFO_TYPE, AllocationType::kYoung);
4053 info->set_id(isolate()->heap()->NextStackTraceId());
4054 info->set_frames(*frames, SKIP_WRITE_BARRIER);
4055 return handle(info, isolate());
4056}
4057
4059 int length) {
4060 bool strict_mode_callee = is_strict(callee->shared()->language_mode()) ||
4061 !callee->shared()->has_simple_parameters();
4062 DirectHandle<Map> map = strict_mode_callee
4063 ? isolate()->strict_arguments_map()
4064 : isolate()->sloppy_arguments_map();
4066 false);
4067 DCHECK(!isolate()->has_exception());
4070 Object::SetProperty(isolate(), result, length_string(), value,
4073 .Assert();
4074 if (!strict_mode_callee) {
4075 Object::SetProperty(isolate(), result, callee_string(), callee,
4078 .Assert();
4079 }
4080 return result;
4081}
4082
4084 DirectHandle<NativeContext> context, int number_of_properties) {
4085 // Use initial slow object proto map for too many properties.
4086 if (number_of_properties >= JSObject::kMapCacheSize) {
4087 return handle(context->slow_object_with_object_prototype_map(), isolate());
4088 }
4089 // TODO(chromium:1503456): remove once fixed.
4090 CHECK_LE(0, number_of_properties);
4091
4092 DirectHandle<WeakFixedArray> cache(Cast<WeakFixedArray>(context->map_cache()),
4093 isolate());
4094
4095 // Check to see whether there is a matching element in the cache.
4096 Tagged<MaybeObject> result = cache->get(number_of_properties);
4097 Tagged<HeapObject> heap_object;
4098 if (result.GetHeapObjectIfWeak(&heap_object)) {
4099 Tagged<Map> map = Cast<Map>(heap_object);
4100 DCHECK(!map->is_dictionary_map());
4101 return handle(map, isolate());
4102 }
4103
4104 // Create a new map and add it to the cache.
4105 Handle<Map> map = Map::Create(isolate(), number_of_properties);
4106 DCHECK(!map->is_dictionary_map());
4107 cache->set(number_of_properties, MakeWeak(*map));
4108 return map;
4109}
4110
4113 DirectHandle<Map> map = mega_dom_handler_map();
4114 Tagged<MegaDomHandler> handler =
4117 handler->set_accessor(*accessor, kReleaseStore);
4118 handler->set_context(*context);
4119 return direct_handle(handler, isolate());
4120}
4121
4123 AllocationType allocation) {
4125 switch (data_count) {
4126 case 1:
4127 map = load_handler1_map();
4128 break;
4129 case 2:
4130 map = load_handler2_map();
4131 break;
4132 case 3:
4133 map = load_handler3_map();
4134 break;
4135 default:
4136 UNREACHABLE();
4137 }
4138 return handle(Cast<LoadHandler>(New(map, allocation)), isolate());
4139}
4140
4143 switch (data_count) {
4144 case 0:
4145 map = store_handler0_map();
4146 break;
4147 case 1:
4148 map = store_handler1_map();
4149 break;
4150 case 2:
4151 map = store_handler2_map();
4152 break;
4153 case 3:
4154 map = store_handler3_map();
4155 break;
4156 default:
4157 UNREACHABLE();
4158 }
4160}
4161
4163 DirectHandle<String> source,
4164 JSRegExp::Flags flags,
4166 DirectHandle<RegExpData> regexp_data =
4167 NewAtomRegExpData(source, flags, pattern);
4168 regexp->set_data(*regexp_data);
4169}
4170
4172 DirectHandle<String> source,
4173 JSRegExp::Flags flags, int capture_count,
4174 uint32_t backtrack_limit) {
4175 DirectHandle<RegExpData> regexp_data =
4176 NewIrRegExpData(source, flags, capture_count, backtrack_limit);
4177 regexp->set_data(*regexp_data);
4178}
4179
4181 DirectHandle<String> source,
4182 JSRegExp::Flags flags,
4183 int capture_count) {
4184 DirectHandle<RegExpData> regexp_data =
4185 NewExperimentalRegExpData(source, flags, capture_count);
4186 regexp->set_data(*regexp_data);
4187}
4188
4190 DirectHandle<String> source, JSRegExp::Flags flags,
4193 int size = AtomRegExpData::kSize;
4195 size, AllocationType::kTrusted, read_only_roots().atom_regexp_data_map());
4198 instance->init_self_indirect_pointer(isolate());
4199 instance->set_type_tag(RegExpData::Type::ATOM);
4200 instance->set_source(*source);
4201 instance->set_flags(flags);
4202 instance->set_pattern(*pattern);
4203 Tagged<RegExpDataWrapper> raw_wrapper = *wrapper;
4204 instance->set_wrapper(raw_wrapper);
4205 raw_wrapper->set_data(instance);
4206 return direct_handle(instance, isolate());
4207}
4208
4210 JSRegExp::Flags flags,
4211 int capture_count,
4212 uint32_t backtrack_limit) {
4214 int size = IrRegExpData::kSize;
4216 size, AllocationType::kTrusted, read_only_roots().ir_regexp_data_map());
4219 instance->init_self_indirect_pointer(isolate());
4220 instance->set_type_tag(RegExpData::Type::IRREGEXP);
4221 instance->set_source(*source);
4222 instance->set_flags(flags);
4223 instance->clear_latin1_code();
4224 instance->clear_uc16_code();
4225 instance->clear_latin1_bytecode();
4226 instance->clear_uc16_bytecode();
4227 instance->set_capture_name_map(Smi::FromInt(JSRegExp::kUninitializedValue));
4228 instance->set_max_register_count(JSRegExp::kUninitializedValue);
4229 instance->set_capture_count(capture_count);
4230 int ticks_until_tier_up = v8_flags.regexp_tier_up
4231 ? v8_flags.regexp_tier_up_ticks
4233 instance->set_ticks_until_tier_up(ticks_until_tier_up);
4234 instance->set_backtrack_limit(backtrack_limit);
4235 Tagged<RegExpDataWrapper> raw_wrapper = *wrapper;
4236 instance->set_wrapper(raw_wrapper);
4237 raw_wrapper->set_data(instance);
4238 return direct_handle(instance, isolate());
4239}
4240
4242 DirectHandle<String> source, JSRegExp::Flags flags, int capture_count) {
4244 int size = IrRegExpData::kSize;
4246 size, AllocationType::kTrusted, read_only_roots().ir_regexp_data_map());
4249 // TODO(mbid,v8:10765): At the moment the ExperimentalRegExpData is just an
4250 // alias of IrRegExpData, with most fields set to some default/uninitialized
4251 // value. This is because EXPERIMENTAL and IRREGEXP regexps take the same code
4252 // path in `RegExpExecInternal`, which reads off various fields from this
4253 // struct. `RegExpExecInternal` should probably distinguish between
4254 // EXPERIMENTAL and IRREGEXP, and then we can get rid of all the IRREGEXP only
4255 // fields.
4256 instance->init_self_indirect_pointer(isolate());
4257 instance->set_type_tag(RegExpData::Type::EXPERIMENTAL);
4258 instance->set_source(*source);
4259 instance->set_flags(flags);
4260 instance->clear_latin1_code();
4261 instance->clear_uc16_code();
4262 instance->clear_latin1_bytecode();
4263 instance->clear_uc16_bytecode();
4264 instance->set_capture_name_map(Smi::FromInt(JSRegExp::kUninitializedValue));
4265 instance->set_max_register_count(JSRegExp::kUninitializedValue);
4266 instance->set_capture_count(capture_count);
4267 instance->set_ticks_until_tier_up(JSRegExp::kUninitializedValue);
4268 instance->set_backtrack_limit(JSRegExp::kUninitializedValue);
4269 Tagged<RegExpDataWrapper> raw_wrapper = *wrapper;
4270 instance->set_wrapper(raw_wrapper);
4271 raw_wrapper->set_data(instance);
4272 return direct_handle(instance, isolate());
4273}
4274
4276 if (Name::Equals(isolate(), name, undefined_string())) {
4277 return undefined_value();
4278 }
4279 if (Name::Equals(isolate(), name, NaN_string())) return nan_value();
4280 if (Name::Equals(isolate(), name, Infinity_string())) return infinity_value();
4281 return Handle<Object>::null();
4282}
4283
4285 switch (hint) {
4287 return default_string();
4289 return number_string();
4291 return string_string();
4292 }
4293 UNREACHABLE();
4294}
4295
4297 FunctionMode function_mode,
4298 MaybeDirectHandle<JSFunction> maybe_empty_function) {
4299 bool has_prototype = IsFunctionModeWithPrototype(function_mode);
4300 int header_size = has_prototype ? JSFunction::kSizeWithPrototype
4302 int descriptors_count = has_prototype ? 5 : 4;
4303 int inobject_properties_count = 0;
4304 if (IsFunctionModeWithName(function_mode)) ++inobject_properties_count;
4305
4307 JS_FUNCTION_TYPE, header_size + inobject_properties_count * kTaggedSize,
4308 TERMINAL_FAST_ELEMENTS_KIND, inobject_properties_count);
4309 {
4311 Tagged<Map> raw_map = *map;
4312 raw_map->set_has_prototype_slot(has_prototype);
4313 raw_map->set_is_constructor(has_prototype);
4314 raw_map->set_is_callable(true);
4315 }
4316 DirectHandle<JSFunction> empty_function;
4317 if (maybe_empty_function.ToHandle(&empty_function)) {
4318 // Temporarily set constructor to empty function to calm down map verifier.
4319 map->SetConstructor(*empty_function);
4320 Map::SetPrototype(isolate(), map, empty_function);
4321 } else {
4322 // |maybe_empty_function| is allowed to be empty only during empty function
4323 // creation.
4324 DCHECK(IsUndefined(
4325 isolate()->raw_native_context()->get(Context::EMPTY_FUNCTION_INDEX)));
4326 }
4327
4328 //
4329 // Setup descriptors array.
4330 //
4331 Map::EnsureDescriptorSlack(isolate(), map, descriptors_count);
4332
4333 PropertyAttributes ro_attribs =
4335 PropertyAttributes rw_attribs =
4337 PropertyAttributes roc_attribs =
4338 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
4339
4340 int field_index = 0;
4341 static_assert(
4343 { // Add length accessor.
4345 length_string(), function_length_accessor(), roc_attribs);
4346 map->AppendDescriptor(isolate(), &d);
4347 }
4348
4349 static_assert(
4351 if (IsFunctionModeWithName(function_mode)) {
4352 // Add name field.
4353 DirectHandle<Name> name = isolate()->factory()->name_string();
4354 Descriptor d = Descriptor::DataField(isolate(), name, field_index++,
4355 roc_attribs, Representation::Tagged());
4356 map->AppendDescriptor(isolate(), &d);
4357
4358 } else {
4359 // Add name accessor.
4361 name_string(), function_name_accessor(), roc_attribs);
4362 map->AppendDescriptor(isolate(), &d);
4363 }
4364 { // Add arguments accessor.
4366 arguments_string(), function_arguments_accessor(), ro_attribs);
4367 map->AppendDescriptor(isolate(), &d);
4368 }
4369 { // Add caller accessor.
4371 caller_string(), function_caller_accessor(), ro_attribs);
4372 map->AppendDescriptor(isolate(), &d);
4373 }
4374 if (IsFunctionModeWithPrototype(function_mode)) {
4375 // Add prototype accessor.
4376 PropertyAttributes attribs =
4377 IsFunctionModeWithWritablePrototype(function_mode) ? rw_attribs
4378 : ro_attribs;
4380 prototype_string(), function_prototype_accessor(), attribs);
4381 map->AppendDescriptor(isolate(), &d);
4382 }
4383 DCHECK_EQ(inobject_properties_count, field_index);
4384 DCHECK_EQ(
4385 0, map->instance_descriptors(isolate())->number_of_slack_descriptors());
4386 LOG(isolate(), MapDetails(*map));
4387 return map;
4388}
4389
4391 FunctionMode function_mode, DirectHandle<JSFunction> empty_function) {
4392 bool has_prototype = IsFunctionModeWithPrototype(function_mode);
4393 int header_size = has_prototype ? JSFunction::kSizeWithPrototype
4395 int inobject_properties_count = 0;
4396 // length and prototype accessors or just length accessor.
4397 int descriptors_count = IsFunctionModeWithPrototype(function_mode) ? 2 : 1;
4398 if (IsFunctionModeWithName(function_mode)) {
4399 ++inobject_properties_count; // name property.
4400 } else {
4401 ++descriptors_count; // name accessor.
4402 }
4403 descriptors_count += inobject_properties_count;
4404
4406 JS_FUNCTION_TYPE, header_size + inobject_properties_count * kTaggedSize,
4407 TERMINAL_FAST_ELEMENTS_KIND, inobject_properties_count);
4408 {
4410 Tagged<Map> raw_map = *map;
4411 raw_map->set_has_prototype_slot(has_prototype);
4412 raw_map->set_is_constructor(has_prototype);
4413 raw_map->set_is_callable(true);
4414 // Temporarily set constructor to empty function to calm down map verifier.
4415 raw_map->SetConstructor(*empty_function);
4416 }
4417 Map::SetPrototype(isolate(), map, empty_function);
4418
4419 //
4420 // Setup descriptors array.
4421 //
4422 Map::EnsureDescriptorSlack(isolate(), map, descriptors_count);
4423
4424 PropertyAttributes rw_attribs =
4426 PropertyAttributes ro_attribs =
4428 PropertyAttributes roc_attribs =
4429 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
4430
4431 int field_index = 0;
4432 static_assert(JSFunction::kLengthDescriptorIndex == 0);
4433 { // Add length accessor.
4435 length_string(), function_length_accessor(), roc_attribs);
4436 map->AppendDescriptor(isolate(), &d);
4437 }
4438
4439 static_assert(JSFunction::kNameDescriptorIndex == 1);
4440 if (IsFunctionModeWithName(function_mode)) {
4441 // Add name field.
4442 DirectHandle<Name> name = isolate()->factory()->name_string();
4443 Descriptor d = Descriptor::DataField(isolate(), name, field_index++,
4444 roc_attribs, Representation::Tagged());
4445 map->AppendDescriptor(isolate(), &d);
4446
4447 } else {
4448 // Add name accessor.
4450 name_string(), function_name_accessor(), roc_attribs);
4451 map->AppendDescriptor(isolate(), &d);
4452 }
4453
4454 if (IsFunctionModeWithPrototype(function_mode)) {
4455 // Add prototype accessor.
4456 PropertyAttributes attribs =
4457 IsFunctionModeWithWritablePrototype(function_mode) ? rw_attribs
4458 : ro_attribs;
4460 prototype_string(), function_prototype_accessor(), attribs);
4461 map->AppendDescriptor(isolate(), &d);
4462 }
4463 DCHECK_EQ(inobject_properties_count, field_index);
4464 DCHECK_EQ(
4465 0, map->instance_descriptors(isolate())->number_of_slack_descriptors());
4466 LOG(isolate(), MapDetails(*map));
4467 return map;
4468}
4469
4471 DirectHandle<JSFunction> empty_function) {
4473 JS_CLASS_CONSTRUCTOR_TYPE, JSFunction::kSizeWithPrototype);
4474 {
4476 Tagged<Map> raw_map = *map;
4477 raw_map->set_has_prototype_slot(true);
4478 raw_map->set_is_constructor(true);
4479 raw_map->set_is_prototype_map(true);
4480 raw_map->set_is_callable(true);
4481 // Temporarily set constructor to empty function to calm down map verifier.
4482 raw_map->SetConstructor(*empty_function);
4483 }
4484 Map::SetPrototype(isolate(), map, empty_function);
4485
4486 //
4487 // Setup descriptors array.
4488 //
4490
4491 PropertyAttributes ro_attribs =
4493 PropertyAttributes roc_attribs =
4494 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
4495
4496 static_assert(JSFunction::kLengthDescriptorIndex == 0);
4497 { // Add length accessor.
4499 length_string(), function_length_accessor(), roc_attribs);
4500 map->AppendDescriptor(isolate(), &d);
4501 }
4502
4503 {
4504 // Add prototype accessor.
4506 prototype_string(), function_prototype_accessor(), ro_attribs);
4507 map->AppendDescriptor(isolate(), &d);
4508 }
4509 LOG(isolate(), MapDetails(*map));
4510 return map;
4511}
4512
4514 Handle<JSPromise> promise =
4515 Cast<JSPromise>(NewJSObject(isolate()->promise_function()));
4517 Tagged<JSPromise> raw = *promise;
4518 raw->set_reactions_or_result(Smi::zero(), SKIP_WRITE_BARRIER);
4519 raw->set_flags(0);
4520 // TODO(v8) remove once embedder data slots are always zero-initialized.
4521 InitEmbedderFields(*promise, Smi::zero());
4522 DCHECK_EQ(raw->GetEmbedderFieldCount(), v8::Promise::kEmbedderFieldCount);
4523 return promise;
4524}
4525
4529 undefined_value());
4530 return promise;
4531}
4532
4536
4538 return isolate()->roots_table()[RootIndex::kempty_string] != kNullAddress;
4539}
4540
4546
4554
4556 DirectHandle<JSFunction> constructor,
4557 MaybeDirectHandle<NumberDictionary> maybe_elements_template) {
4558 SharedObjectSafePublishGuard publish_guard;
4559
4560 DirectHandle<Map> instance_map(constructor->initial_map(), isolate());
4561 DirectHandle<PropertyArray> property_array;
4562 const int num_oob_fields =
4563 instance_map->NumberOfFields(ConcurrencyMode::kSynchronous) -
4564 instance_map->GetInObjectProperties();
4565 if (num_oob_fields > 0) {
4566 property_array =
4568 }
4569
4570 DirectHandle<NumberDictionary> elements_dictionary;
4571 bool has_elements_dictionary;
4572 if ((has_elements_dictionary =
4573 maybe_elements_template.ToHandle(&elements_dictionary))) {
4574 elements_dictionary = NumberDictionary::ShallowCopy(
4575 isolate(), elements_dictionary, AllocationType::kSharedOld);
4576 }
4577
4580
4581 // The struct object has not been fully initialized yet. Disallow allocation
4582 // from this point on.
4584 if (!property_array.is_null()) instance->SetProperties(*property_array);
4585 if (has_elements_dictionary) instance->set_elements(*elements_dictionary);
4586
4587 return instance;
4588}
4589
4591 DirectHandle<JSFunction> constructor, int length) {
4592 SharedObjectSafePublishGuard publish_guard;
4595 auto instance =
4597 instance->set_elements(*storage);
4599 constructor->initial_map(),
4601 instance->FastPropertyAtPut(index, Smi::FromInt(length), SKIP_WRITE_BARRIER);
4602 return instance;
4603}
4604
4606 SharedObjectSafePublishGuard publish_guard;
4607 DirectHandle<Map> map = js_atomics_mutex_map();
4608 auto mutex =
4611 mutex->set_owner_thread_id(ThreadId::Invalid().ToInteger());
4612 mutex->SetNullWaiterQueueHead();
4613 return mutex;
4614}
4615
4617 SharedObjectSafePublishGuard publish_guard;
4618 DirectHandle<Map> map = js_atomics_condition_map();
4621 cond->set_state(JSAtomicsCondition::kEmptyState);
4622 cond->SetNullWaiterQueueHead();
4623 return cond;
4624}
4625
4626namespace {
4627inline void InitializeTemplate(Tagged<TemplateInfo> that, bool is_cacheable) {
4628 that->set_template_info_flags(0);
4629 that->set_serial_number(TemplateInfo::kUninitializedSerialNumber);
4630 that->set_is_cacheable(is_cacheable);
4631}
4632
4633inline void InitializeTemplateWithProperties(
4634 Tagged<TemplateInfoWithProperties> that, ReadOnlyRoots roots,
4635 bool is_cacheable) {
4636 InitializeTemplate(that, is_cacheable);
4637
4638 that->set_number_of_properties(0);
4639 that->set_property_list(roots.undefined_value(), SKIP_WRITE_BARRIER);
4640 that->set_property_accessors(roots.undefined_value(), SKIP_WRITE_BARRIER);
4641}
4642
4643} // namespace
4644
4646 int length, bool do_not_cache) {
4647 const int size = FunctionTemplateInfo::SizeFor();
4651 read_only_roots().function_template_info_map()));
4652 {
4653 // Disallow GC until all fields of obj have acceptable types.
4656 ReadOnlyRoots roots(isolate());
4657 InitializeTemplateWithProperties(raw, roots, !do_not_cache);
4658 raw->set_class_name(roots.undefined_value(), SKIP_WRITE_BARRIER);
4659 raw->set_interface_name(roots.undefined_value(), SKIP_WRITE_BARRIER);
4660 raw->set_signature(roots.undefined_value(), SKIP_WRITE_BARRIER);
4661 raw->set_rare_data(roots.undefined_value(), kReleaseStore,
4663 raw->set_shared_function_info(roots.undefined_value(), SKIP_WRITE_BARRIER);
4664 raw->set_cached_property_name(roots.the_hole_value(), SKIP_WRITE_BARRIER);
4665
4666 raw->set_flag(0, kRelaxedStore);
4667 raw->set_undetectable(false);
4668 raw->set_needs_access_check(false);
4669 raw->set_accept_any_receiver(true);
4670 raw->set_exception_context(
4671 static_cast<uint32_t>(ExceptionContext::kUnknown));
4672
4673 raw->set_length(length);
4674 raw->SetInstanceType(0);
4675 raw->init_callback(isolate(), kNullAddress);
4676 raw->set_callback_data(roots.the_hole_value(), kReleaseStore,
4678 }
4679 return direct_handle(obj, isolate());
4680}
4681
4683 DirectHandle<FunctionTemplateInfo> constructor, bool do_not_cache) {
4684 const int size = ObjectTemplateInfo::SizeFor();
4687 read_only_roots().object_template_info_map()));
4688 {
4689 // Disallow GC until all fields of obj have acceptable types.
4691 Tagged<ObjectTemplateInfo> raw = *obj;
4692 ReadOnlyRoots roots(isolate());
4693 InitializeTemplateWithProperties(raw, roots, !do_not_cache);
4694 if (constructor.is_null()) {
4695 raw->set_constructor(roots.undefined_value(), SKIP_WRITE_BARRIER);
4696 } else {
4697 raw->set_constructor(*constructor);
4698 }
4699 raw->set_data(0);
4700 }
4701 return direct_handle(obj, isolate());
4702}
4703
4705 DirectHandle<FixedArray> property_names) {
4706 const int size = DictionaryTemplateInfo::SizeFor();
4707 DirectHandle<Map> map = dictionary_template_info_map();
4710 InitializeTemplate(obj, true);
4711 obj->set_property_names(*property_names);
4712 return direct_handle(obj, isolate());
4713}
4714
4716 // Statically ensure that it is safe to allocate foreigns in paged spaces.
4717 static_assert(TrustedForeign::kSize <= kMaxRegularHeapObjectSize);
4718 Tagged<Map> map = *trusted_foreign_map();
4719 Tagged<TrustedForeign> foreign =
4721 map->instance_size(), AllocationType::kTrusted, map));
4723 foreign->set_foreign_address(addr);
4724 return handle(foreign, isolate());
4725}
4726
4731
4733 DirectHandle<Code> code(sfi_->GetCode(isolate_), isolate_);
4734 // Retain the code across the call to BuildRaw, because it allocates and can
4735 // trigger code to be flushed. Otherwise the SFI's compiled state and the
4736 // function's compiled state can diverge, and the call to PostInstantiation
4737 // below can fail to initialize the feedback vector.
4738 IsCompiledScope is_compiled_scope(sfi_->is_compiled_scope(isolate_));
4739 Handle<JSFunction> result = BuildRaw(code);
4740
4741 if (code->kind() == CodeKind::BASELINE) {
4742 JSFunction::EnsureFeedbackVector(isolate_, result, &is_compiled_scope);
4743 }
4744
4745 Compiler::PostInstantiation(isolate_, result, &is_compiled_scope);
4746 return result;
4747}
4748
4750 DirectHandle<Code> code) {
4751 Isolate* isolate = isolate_;
4752 Factory* factory = isolate_->factory();
4753
4755 if (!maybe_map_.ToHandle(&map)) {
4756 // No specific map requested, use the default.
4757 map = direct_handle(
4758 Cast<Map>(context_->native_context()->get(sfi_->function_map_index())),
4759 isolate_);
4760 }
4761 DCHECK(InstanceTypeChecker::IsJSFunction(*map));
4762
4763 Handle<JSFunction> function_handle;
4764 bool many_closures_cell = false;
4765 {
4766 // Allocation.
4767 Tagged<JSFunction> function =
4768 Cast<JSFunction>(factory->New(map, allocation_type_));
4769
4771
4772 // Transition the feedback cell after allocating the JSFunction. This is so
4773 // that the leap-tiering-relevant one-to-many feedback cell mutation below
4774 // happens atomically with the closure count increase here, without the
4775 // object verifier potentially observing a many-closures cell with context
4776 // specialised code.
4777 DirectHandle<FeedbackCell> feedback_cell;
4779 if (maybe_feedback_cell_.ToHandle(&feedback_cell)) {
4780 // Track the newly-created closure.
4781 cell_transition = feedback_cell->IncrementClosureCount(isolate_);
4782 } else {
4783 // Fall back to the many_closures_cell.
4784 feedback_cell = isolate_->factory()->many_closures_cell();
4785 cell_transition = FeedbackCell::kMany;
4786 many_closures_cell = true;
4787 }
4788
4789 WriteBarrierMode mode = allocation_type_ == AllocationType::kYoung
4792 // Header initialization.
4793 function->initialize_properties(isolate);
4794 function->initialize_elements();
4795 function->set_shared(*sfi_, mode);
4796 function->set_context(*context_, kReleaseStore, mode);
4797 function->set_raw_feedback_cell(*feedback_cell, mode);
4798
4799#ifdef V8_ENABLE_LEAPTIERING
4800 if (!many_closures_cell) {
4801 // TODO(olivf, 42204201): Here we are explicitly not updating (only
4802 // potentially initializing) the code. Worst case the dispatch handle
4803 // still contains bytecode or CompileLazy and we'll tier on the next call.
4804 // Otoh, if we would UpdateCode we would risk tiering down already
4805 // existing closures with optimized code installed.
4806 DCHECK_NE(*feedback_cell, *isolate->factory()->many_closures_cell());
4807 DCHECK_NE(feedback_cell->dispatch_handle(), kNullJSDispatchHandle);
4808
4809 JSDispatchHandle dispatch_handle = feedback_cell->dispatch_handle();
4810 JSDispatchTable* jdt = IsolateGroup::current()->js_dispatch_table();
4811 Tagged<Code> old_code = jdt->GetCode(dispatch_handle);
4812
4813 // A write barrier is needed when settings code, because the update can
4814 // race with marking which could leave the dispatch slot unmarked.
4815 // TODO(olivf): This should be fixed by using a more traditional WB
4816 // for dispatch handles (i.e. have a marking queue with dispatch handles
4817 // instead of marking through the handle).
4818 constexpr WriteBarrierMode mode_if_setting_code =
4820
4821 // TODO(olivf): We should go through the cases where this is still
4822 // needed and maybe find some alternative to initialize it correctly
4823 // from the beginning.
4824 if (old_code->is_builtin()) {
4825 jdt->SetCodeNoWriteBarrier(dispatch_handle, *code);
4826 function->set_dispatch_handle(dispatch_handle, mode_if_setting_code);
4827 } else {
4828 // On a transition of a feedback cell from one closure to many, make
4829 // sure that the code on the feedback cell isn't native context
4830 // specialized, and if it was, eagerly re-optimize.
4831 if (cell_transition == FeedbackCell::kOneToMany &&
4832 old_code->is_context_specialized()) {
4833 jdt->SetCodeNoWriteBarrier(dispatch_handle, *code);
4834 function->set_dispatch_handle(dispatch_handle, mode_if_setting_code);
4835 DCHECK(old_code->kind() == CodeKind::MAGLEV ||
4836 old_code->kind() == CodeKind::TURBOFAN_JS);
4837 if (!old_code->marked_for_deoptimization()) {
4838 function->RequestOptimization(isolate, old_code->kind());
4839 }
4840 } else {
4841 function->set_dispatch_handle(dispatch_handle, mode);
4842 }
4843 }
4844 }
4845#else
4846 USE(cell_transition, many_closures_cell);
4847 function->UpdateCode(*code, mode);
4848#endif // V8_ENABLE_LEAPTIERING
4849
4850 if (function->has_prototype_slot()) {
4851 function->set_prototype_or_initial_map(
4852 ReadOnlyRoots(isolate).the_hole_value(), kReleaseStore,
4854 }
4855
4856 // Potentially body initialization.
4857 factory->InitializeJSObjectBody(
4858 function, *map, JSFunction::GetHeaderSize(map->has_prototype_slot()));
4859
4860 function_handle = handle(function, isolate_);
4861 }
4862
4863#ifdef V8_ENABLE_LEAPTIERING
4864 // If the FeedbackCell doesn't have a dispatch handle, we need to allocate a
4865 // dispatch entry now. This should only be the case for functions using the
4866 // generic many_closures_cell (for example builtin functions), and only for
4867 // functions using certain kinds of code.
4868 if (many_closures_cell) {
4869 // We currently only expect to see these kinds of Code here. For BASELINE
4870 // code, we will allocate a FeedbackCell after building the JSFunction. See
4871 // JSFunctionBuilder::Build.
4872 DCHECK(code->kind() == CodeKind::BUILTIN ||
4873 code->kind() == CodeKind::JS_TO_WASM_FUNCTION ||
4874 code->kind() == CodeKind::BASELINE);
4875 // TODO(saelo): in the future, we probably want to use
4876 // code->parameter_count() here instead, but not all Code objects know
4877 // their parameter count yet.
4878 function_handle->clear_dispatch_handle();
4880 function_handle, JSFunction::kDispatchHandleOffset, isolate,
4881 sfi_->internal_formal_parameter_count_with_receiver(), code);
4882 } else {
4883 DCHECK_NE(function_handle->dispatch_handle(), kNullJSDispatchHandle);
4884 }
4885#endif
4886
4887 return function_handle;
4888}
4889
4890} // namespace internal
4891} // namespace v8
#define INTERCEPTOR_INFO_CALLBACK_LIST(V)
Isolate * isolate_
#define DEFINE_ERROR(NAME, name)
Definition api.cc:11109
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype)
friend Zone
Definition asm-types.cc:195
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
Builtins::Kind kind
Definition builtins.cc:40
#define BUILTIN_CODE(isolate, name)
Definition builtins.h:45
#define SLOW_DCHECK(condition)
Definition checks.h:21
static const int kEmbedderFieldCount
static constexpr int kEmbedderFieldCount
Definition v8-promise.h:118
virtual size_t length() const =0
bool IsOneByte() const
Definition api.cc:5620
static constexpr U kMax
Definition bit-field.h:44
static constexpr U encode(T value)
Definition bit-field.h:55
int length() const
Definition vector.h:64
constexpr T * begin() const
Definition vector.h:96
constexpr T * data() const
Definition vector.h:100
static Vector< T > cast(Vector< S > input)
Definition vector.h:157
static bool CanTrack(InstanceType type)
static V8_EXPORT_PRIVATE DirectHandle< ArrayList > Add(Isolate *isolate, DirectHandle< ArrayList > array, Tagged< Smi > obj, AllocationType allocation=AllocationType::kYoung)
static DirectHandle< ArrayList > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
static std::unique_ptr< BackingStore > TryAllocateAndPartiallyCommitMemory(Isolate *isolate, size_t byte_length, size_t max_byte_length, size_t page_size, size_t initial_pages, size_t maximum_pages, WasmMemoryFlag wasm_memory, SharedFlag shared, bool has_guard_regions=false)
static std::unique_ptr< BackingStore > Allocate(Isolate *isolate, size_t byte_length, SharedFlag shared, InitializedFlag initialized)
static bool IsIsolateIndependentBuiltin(Tagged< Code > code)
Definition builtins.cc:372
static constexpr bool IsBuiltinId(Builtin builtin)
Definition builtins.h:128
static constexpr int SizeFor(int length)
static constexpr BytecodeOffset None()
Definition utils.h:675
static const int kMaxArguments
Definition code.h:463
static void PostInstantiation(Isolate *isolate, DirectHandle< JSFunction > function, IsCompiledScope *is_compiled_scope)
Definition compiler.cc:4550
static V8_INLINE constexpr int SizeFor(int length)
Definition contexts.h:503
static const int kTodoHeaderSize
Definition contexts.h:497
static const int kNoDebuggingId
static V8_EXPORT_PRIVATE Tagged< DependentCode > empty_dependent_code(const ReadOnlyRoots &roots)
static Descriptor DataField(Isolate *isolate, DirectHandle< Name > key, int field_index, PropertyAttributes attributes, Representation representation)
Definition property.cc:81
static Descriptor AccessorConstant(DirectHandle< Name > key, DirectHandle< Object > foreign, PropertyAttributes attributes)
Definition property.cc:118
V8_INLINE bool is_null() const
Definition handles.h:693
static constexpr int SizeFor(int length)
V8_INLINE void Initialize(Tagged< Object > initial_value)
static Handle< JSObject > MakeGenericError(Isolate *isolate, DirectHandle< JSFunction > constructor, MessageTemplate index, base::Vector< const DirectHandle< Object > > args, FrameSkipMode mode)
Definition messages.cc:730
static MaybeDirectHandle< JSObject > Construct(Isolate *isolate, DirectHandle< JSFunction > target, DirectHandle< Object > new_target, DirectHandle< Object > message, DirectHandle< Object > options)
Definition messages.cc:528
static DirectHandle< JSObject > ShadowRealmConstructTypeErrorCopy(Isolate *isolate, DirectHandle< Object > original, MessageTemplate index, base::Vector< const DirectHandle< Object > > args)
Definition messages.cc:755
Handle< Boolean > ToBoolean(bool value)
Tagged< HeapObject > AllocateRawWithImmortalMap(int size, AllocationType allocation, Tagged< Map > map, AllocationAlignment alignment=kTaggedAligned)
Tagged< HeapObject > AllocateRawFixedArray(int length, AllocationType allocation)
Handle< SharedFunctionInfo > NewSharedFunctionInfo(AllocationType allocation)
Handle< WeakFixedArray > NewWeakFixedArrayWithMap(Tagged< Map > map, int length, AllocationType allocation=AllocationType::kYoung)
DirectHandle< RegExpDataWrapper > NewRegExpDataWrapper()
Handle< String > MakeOrFindTwoCharacterString(uint16_t c1, uint16_t c2)
Handle< String > NewStringFromAsciiChecked(const char *str, AllocationType allocation=AllocationType::kYoung)
V8_WARN_UNUSED_RESULT Handle< String > SmiToString(Tagged< Smi > number, NumberCacheMode mode=NumberCacheMode::kBoth)
Handle< Code > NewCode(const NewCodeOptions &options)
Handle< String > LookupSingleCharacterStringFromCode(uint16_t code)
V8_WARN_UNUSED_RESULT MaybeHandle< SeqOneByteString > NewRawOneByteString(int length, AllocationType allocation=AllocationType::kYoung)
Handle< SwissNameDictionary > NewSwissNameDictionary(int at_least_space_for=kSwissNameDictionaryInitialCapacity, AllocationType allocation=AllocationType::kYoung)
V8_WARN_UNUSED_RESULT Handle< String > HeapNumberToString(DirectHandle< HeapNumber > number, double value, NumberCacheMode mode=NumberCacheMode::kBoth)
Handle< ByteArray > NewByteArray(int length, AllocationType allocation=AllocationType::kYoung)
Tagged< HeapObject > AllocateRawWeakArrayList(int length, AllocationType allocation)
DirectHandle< BytecodeWrapper > NewBytecodeWrapper(AllocationType allocation=AllocationType::kOld)
MaybeDirectHandle< Map > GetInPlaceInternalizedStringMap(Tagged< Map > from_string_map)
Handle< SeqOneByteString > AllocateRawOneByteInternalizedString(int length, uint32_t raw_hash_field)
Handle< FixedArray > NewFixedArrayWithHoles(int length, AllocationType allocation=AllocationType::kYoung)
static constexpr int kNumberToStringBufferSize
Tagged< StructType > NewStructInternal(InstanceType type, AllocationType allocation)
Handle< FixedArrayBase > NewFixedDoubleArray(int length, AllocationType allocation=AllocationType::kYoung)
V8_WARN_UNUSED_RESULT MaybeHandle< SeqTwoByteString > NewRawTwoByteString(int length, AllocationType allocation=AllocationType::kYoung)
Handle< Struct > NewStruct(InstanceType type, AllocationType allocation=AllocationType::kYoung)
Handle< FixedArray > NewFixedArray(int length, AllocationType allocation=AllocationType::kYoung)
Handle< SeqTwoByteString > AllocateRawTwoByteInternalizedString(int length, uint32_t raw_hash_field)
Handle< TrustedByteArray > NewTrustedByteArray(int length, AllocationType allocation_type=AllocationType::kTrusted)
Handle< String > InternalizeStringWithKey(StringTableKey *key)
Handle< HeapNumber > NewHeapNumber()
DirectHandle< TrustedByteArray > NewTrustedByteArray(int length)
Definition factory.cc:117
CodeBuilder(Isolate *isolate, const CodeDesc &desc, CodeKind kind)
Definition factory.cc:103
Tagged< HeapObject > AllocateUninitializedInstructionStream(bool retry_allocation_or_fail)
Definition factory.cc:262
V8_WARN_UNUSED_RESULT Handle< Code > Build()
Definition factory.cc:288
Handle< Code > NewCode(const NewCodeOptions &options)
Definition factory.cc:122
MaybeHandle< Code > BuildInternal(bool retry_allocation_or_fail)
Definition factory.cc:126
V8_WARN_UNUSED_RESULT MaybeHandle< Code > TryBuild()
Definition factory.cc:284
V8_WARN_UNUSED_RESULT Handle< JSFunction > BuildRaw(DirectHandle< Code > code)
Definition factory.cc:4749
JSFunctionBuilder(Isolate *isolate, DirectHandle< SharedFunctionInfo > sfi, DirectHandle< Context > context)
Definition factory.cc:4727
V8_WARN_UNUSED_RESULT Handle< JSFunction > Build()
Definition factory.cc:4732
Handle< JSGlobalProxy > NewUninitializedJSGlobalProxy(int size)
Definition factory.cc:3793
Handle< FixedArray > CopyFixedArray(Handle< FixedArray > array)
Definition factory.cc:2761
DirectHandle< Map > NewMapWithMetaMap(DirectHandle< Map > meta_map, InstanceType type, int instance_size, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, int inobject_properties=0, AllocationType allocation_type=AllocationType::kMap)
Definition factory.cc:2401
Handle< Map > NewContextlessMap(InstanceType type, int instance_size, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, int inobject_properties=0, AllocationType allocation_type=AllocationType::kMap)
Definition factory.cc:2470
ReadOnlyRoots read_only_roots() const
Handle< JSArrayBufferView > NewJSArrayBufferView(DirectHandle< Map > map, DirectHandle< FixedArrayBase > elements, DirectHandle< JSArrayBuffer > buffer, size_t byte_offset, size_t byte_length)
Definition factory.cc:3628
DirectHandle< HeapObject > NewFillerObject(int size, AllocationAlignment alignment, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime)
Definition factory.cc:352
DirectHandle< Object > GlobalConstantFor(DirectHandle< Name > name)
Definition factory.cc:4275
DirectHandle< String > ToPrimitiveHintString(ToPrimitiveHint hint)
Definition factory.cc:4284
DirectHandle< StringClass > InternalizeExternalString(DirectHandle< String > string)
Definition factory.cc:985
V8_WARN_UNUSED_RESULT MaybeHandle< FixedArray > TryNewFixedArray(int length, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:428
Isolate * isolate() const
Definition factory.h:1281
DirectHandle< DictionaryTemplateInfo > NewDictionaryTemplateInfo(DirectHandle< FixedArray > property_names)
Definition factory.cc:4704
bool CanAllocateInReadOnlySpace()
Definition factory.cc:4533
static bool IsFunctionModeWithName(FunctionMode function_mode)
Definition factory.h:1008
Handle< Symbol > NewSymbol(AllocationType allocation=AllocationType::kOld)
Definition factory.cc:1234
void InitializeAllocationMemento(Tagged< AllocationMemento > memento, Tagged< AllocationSite > allocation_site)
Definition factory.cc:326
Handle< JSGlobalObject > NewJSGlobalObject(DirectHandle< JSFunction > constructor)
Definition factory.cc:3012
Handle< JSWeakMap > NewJSWeakMap()
Definition factory.cc:3338
Handle< SharedFunctionInfo > NewSharedFunctionInfoForBuiltin(MaybeDirectHandle< String > name, Builtin builtin, int len, AdaptArguments adapt, FunctionKind kind=FunctionKind::kNormalFunction)
Definition factory.cc:3904
static bool IsFunctionModeWithWritablePrototype(FunctionMode function_mode)
Definition factory.h:1004
DirectHandle< WeakArrayList > NewWeakArrayList(int capacity, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2669
Handle< T > AllocateSmallOrderedHashTable(DirectHandle< Map > map, int capacity, AllocationType allocation)
Definition factory.cc:511
Handle< SharedFunctionInfo > NewSharedFunctionInfoForApiFunction(MaybeDirectHandle< String > maybe_name, DirectHandle< FunctionTemplateInfo > function_template_info, FunctionKind kind)
Definition factory.cc:3895
DirectHandle< RegExpData > NewIrRegExpData(DirectHandle< String > source, JSRegExp::Flags flags, int capture_count, uint32_t backtrack_limit)
Definition factory.cc:4209
Handle< JSArray > NewJSArray(ElementsKind elements_kind, int length, int capacity, ArrayStorageAllocationMode mode=ArrayStorageAllocationMode::DONT_INITIALIZE_ARRAY_ELEMENTS, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:3211
DirectHandle< JSSharedArray > NewJSSharedArray(DirectHandle< JSFunction > constructor, int length)
Definition factory.cc:4590
DirectHandle< Context > NewScriptContext(DirectHandle< NativeContext > outer, DirectHandle< ScopeInfo > scope_info)
Definition factory.cc:1335
DirectHandle< Map > CreateStrictFunctionMap(FunctionMode function_mode, DirectHandle< JSFunction > empty_function)
Definition factory.cc:4390
Handle< JSObject > NewSlowJSObjectWithNullProto()
Definition factory.cc:2998
static void TypeAndSizeForElementsKind(ElementsKind kind, ExternalArrayType *array_type, size_t *element_size)
Definition factory.cc:3610
Handle< Symbol > NewPrivateSymbol(AllocationType allocation=AllocationType::kOld)
Definition factory.cc:1238
DirectHandle< InterceptorInfo > NewInterceptorInfo(AllocationType allocation=AllocationType::kOld)
Definition factory.cc:1530
Handle< JSObject > NewJSObjectWithNullProto()
Definition factory.cc:3004
Tagged< HeapObject > AllocateRawWithAllocationSite(DirectHandle< Map > map, AllocationType allocation, DirectHandle< AllocationSite > allocation_site)
Definition factory.cc:298
void SetRegExpAtomData(DirectHandle< JSRegExp > regexp, DirectHandle< String > source, JSRegExp::Flags flags, DirectHandle< String > match_pattern)
Definition factory.cc:4162
DirectHandle< PromiseResolveThenableJobTask > NewPromiseResolveThenableJobTask(DirectHandle< JSPromise > promise_to_resolve, DirectHandle< JSReceiver > thenable, DirectHandle< JSReceiver > then, DirectHandle< Context > context)
Definition factory.cc:1646
void InitializeCppHeapWrapper(Tagged< JSObject > obj)
Definition factory.cc:3077
Handle< JSTypedArray > NewJSTypedArray(ExternalArrayType type, DirectHandle< JSArrayBuffer > buffer, size_t byte_offset, size_t length, bool is_length_tracking=false)
Definition factory.cc:3656
Handle< T > CopyArrayAndGrow(DirectHandle< T > src, int grow_by, AllocationType allocation)
Definition factory.cc:2624
DirectHandle< SwissNameDictionary > CreateCanonicalEmptySwissNameDictionary()
Definition factory.cc:586
Handle< FixedArray > CopyFixedArrayWithMap(DirectHandle< FixedArray > array, DirectHandle< Map > map, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2647
DirectHandle< JSGeneratorObject > NewJSGeneratorObject(DirectHandle< JSFunction > function)
Definition factory.cc:3386
DirectHandle< FunctionTemplateInfo > NewFunctionTemplateInfo(int length, bool do_not_cache)
Definition factory.cc:4645
DirectHandle< JSSharedStruct > NewJSSharedStruct(DirectHandle< JSFunction > constructor, MaybeDirectHandle< NumberDictionary > maybe_elements_template)
Definition factory.cc:4555
DirectHandle< TransitionArray > NewTransitionArray(int number_of_transitions, int slack=0)
Definition factory.cc:2257
V8_INLINE Handle< Map > NewMapImpl(MetaMapProviderFunc &&meta_map_provider, InstanceType type, int instance_size, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, int inobject_properties=0, AllocationType allocation_type=AllocationType::kMap)
Handle< JSObject > CopyJSObject(DirectHandle< JSObject > object)
Definition factory.cc:2489
V8_WARN_UNUSED_RESULT MaybeHandle< String > NewStringFromUtf8SubString(Handle< SeqOneByteString > str, int begin, int end, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:828
DirectHandle< Context > NewFunctionContext(DirectHandle< Context > outer, DirectHandle< ScopeInfo > scope_info)
Definition factory.cc:1381
DirectHandle< Map > NewContextfulMap(DirectHandle< JSReceiver > creation_context_holder, InstanceType type, int instance_size, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, int inobject_properties=0, AllocationType allocation_type=AllocationType::kMap)
Definition factory.cc:2418
DirectHandle< ContextSidePropertyCell > NewContextSidePropertyCell(ContextSidePropertyCell::Property property, AllocationType allocation=AllocationType::kOld)
Definition factory.cc:2237
Handle< FixedDoubleArray > CopyFixedDoubleArray(Handle< FixedDoubleArray > array)
Definition factory.cc:2767
DirectHandle< PropertyCell > NewProtector()
Definition factory.cc:2251
DirectHandle< PrototypeInfo > NewPrototypeInfo()
Definition factory.cc:364
DirectHandle< JSWrappedFunction > NewJSWrappedFunction(DirectHandle< NativeContext > creation_context, DirectHandle< Object > target)
Definition factory.cc:3365
Handle< TrustedForeign > NewTrustedForeign(Address addr)
Definition factory.cc:4715
Handle< Cell > NewCell()
Definition factory.cc:2166
MaybeHandle< JSArrayBuffer > NewJSArrayBufferAndBackingStore(size_t byte_length, InitializedFlag initialized, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:3508
Handle< LoadHandler > NewLoadHandler(int data_count, AllocationType allocation=AllocationType::kOld)
Definition factory.cc:4122
DirectHandle< AccessorInfo > NewAccessorInfo()
Definition factory.cc:1512
DirectHandle< JSObject > NewFunctionPrototype(DirectHandle< JSFunction > function)
Definition factory.cc:2867
DirectHandle< Tuple2 > NewTuple2(DirectHandle< Object > value1, DirectHandle< Object > value2, AllocationType allocation)
Definition factory.cc:396
Handle< JSObject > NewJSObject(DirectHandle< JSFunction > constructor, AllocationType allocation=AllocationType::kYoung, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
Definition factory.cc:2985
DirectHandle< Context > NewModuleContext(DirectHandle< SourceTextModule > module, DirectHandle< NativeContext > outer, DirectHandle< ScopeInfo > scope_info)
Definition factory.cc:1364
DirectHandle< SourceTextModule > NewSourceTextModule(DirectHandle< SharedFunctionInfo > code)
Definition factory.cc:3423
DirectHandle< JSStringIterator > NewJSStringIterator(Handle< String > string)
Definition factory.cc:1193
Handle< JSArrayBuffer > NewJSSharedArrayBuffer(std::shared_ptr< BackingStore > backing_store)
Definition factory.cc:3553
Handle< Map > NewContextfulMapForCurrentContext(InstanceType type, int instance_size, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, int inobject_properties=0, AllocationType allocation_type=AllocationType::kMap)
Definition factory.cc:2455
DirectHandle< Context > NewBlockContext(DirectHandle< Context > previous, DirectHandle< ScopeInfo > scope_info)
Definition factory.cc:1475
Handle< CallSiteInfo > NewCallSiteInfo(DirectHandle< JSAny > receiver_or_instance, DirectHandle< UnionOf< Smi, JSFunction > > function, DirectHandle< HeapObject > code_object, int code_offset_or_source_position, int flags, DirectHandle< FixedArray > parameters)
Definition factory.cc:4014
DirectHandle< Hole > NewHole()
Definition factory.cc:406
Tagged< Map > InitializeMap(Tagged< Map > map, InstanceType type, int instance_size, ElementsKind elements_kind, int inobject_properties, ReadOnlyRoots roots)
Definition factory.cc:2331
DirectHandle< FeedbackCell > NewManyClosuresCell(AllocationType allocation=AllocationType::kOld)
Definition factory.cc:2204
DirectHandle< AliasedArgumentsEntry > NewAliasedArgumentsEntry(int aliased_context_slot)
Definition factory.cc:1504
void ReinitializeJSGlobalProxy(DirectHandle< JSGlobalProxy > global, DirectHandle< JSFunction > constructor)
Definition factory.cc:3814
DirectHandle< FeedbackCell > NewNoClosuresCell()
Definition factory.cc:2175
DirectHandle< NameDictionary > NewNameDictionary(int at_least_space_for)
Definition factory.cc:568
DirectHandle< CallbackTask > NewCallbackTask(DirectHandle< Foreign > callback, DirectHandle< Foreign > data)
Definition factory.cc:1630
Handle< WeakArrayList > CopyWeakArrayListAndGrow(DirectHandle< WeakArrayList > array, int grow_by, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2695
V8_WARN_UNUSED_RESULT MaybeHandle< String > NewExternalStringFromTwoByte(const v8::String::ExternalStringResource *resource)
Definition factory.cc:1169
DirectHandle< WeakFixedArray > CopyWeakFixedArrayAndGrow(DirectHandle< WeakFixedArray > array, int grow_by)
Definition factory.cc:2689
DirectHandle< JSObject > NewSuppressedErrorAtDisposal(Isolate *isolate, DirectHandle< Object > error, DirectHandle< Object > suppressed_error)
Definition factory.cc:2831
Handle< SmallOrderedNameDictionary > NewSmallOrderedNameDictionary(int capacity=kSmallOrderedHashMapMinCapacity, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:547
DirectHandle< MegaDomHandler > NewMegaDomHandler(MaybeObjectDirectHandle accessor, MaybeObjectDirectHandle context)
Definition factory.cc:4111
void SetRegExpIrregexpData(DirectHandle< JSRegExp > regexp, DirectHandle< String > source, JSRegExp::Flags flags, int capture_count, uint32_t backtrack_limit)
Definition factory.cc:4171
Handle< PropertyCell > NewPropertyCell(DirectHandle< Name > name, PropertyDetails details, DirectHandle< Object > value, AllocationType allocation=AllocationType::kOld)
Definition factory.cc:2216
DirectHandle< StackFrameInfo > NewStackFrameInfo(DirectHandle< UnionOf< SharedFunctionInfo, Script > > shared_or_script, int bytecode_offset_or_source_position, DirectHandle< String > function_name, bool is_constructor)
Definition factory.cc:4031
DirectHandle< WeakArrayList > CompactWeakArrayList(DirectHandle< WeakArrayList > array, int new_capacity, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2714
DirectHandle< Object > NewInvalidStringLengthError()
Definition factory.cc:2820
V8_WARN_UNUSED_RESULT MaybeHandle< String > NewExternalStringFromOneByte(const v8::String::ExternalOneByteStringResource *resource)
Definition factory.cc:1145
DirectHandle< JSArray > NewJSArrayForTemplateLiteralArray(DirectHandle< FixedArray > cooked_strings, DirectHandle< FixedArray > raw_strings, int function_literal_id, int slot_id)
Definition factory.cc:3264
DirectHandle< FeedbackCell > NewOneClosureCell(DirectHandle< ClosureFeedbackCellArray > value)
Definition factory.cc:2189
Handle< Script > CloneScript(DirectHandle< Script > script, DirectHandle< String > source)
Definition factory.cc:1577
V8_WARN_UNUSED_RESULT MaybeHandle< String > NewStringFromUtf8(base::Vector< const char > str, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:753
DirectHandle< JSSet > NewJSSet()
Definition factory.cc:3603
DirectHandle< CallableTask > NewCallableTask(DirectHandle< JSReceiver > callable, DirectHandle< Context > context)
Definition factory.cc:1614
DirectHandle< Context > NewBuiltinContext(DirectHandle< NativeContext > native_context, int length)
Definition factory.cc:1490
DirectHandle< Code > NewCodeObjectForEmbeddedBuiltin(DirectHandle< Code > code, Address off_heap_entry)
Definition factory.cc:2910
DirectHandle< RegExpData > NewAtomRegExpData(DirectHandle< String > source, JSRegExp::Flags flags, DirectHandle< String > pattern)
Definition factory.cc:4189
DirectHandle< BytecodeArray > CopyBytecodeArray(DirectHandle< BytecodeArray >)
Definition factory.cc:2956
Handle< NativeContext > NewNativeContext()
Definition factory.cc:1295
Handle< SyntheticModule > NewSyntheticModule(DirectHandle< String > module_name, DirectHandle< FixedArray > export_names, v8::Module::SyntheticModuleEvaluationSteps evaluation_steps)
Definition factory.cc:3465
Handle< String > NewProperSubString(DirectHandle< String > str, uint32_t begin, uint32_t end)
Definition factory.cc:1090
DirectHandle< JSModuleNamespace > NewJSModuleNamespace()
Definition factory.cc:3352
Handle< BreakPoint > NewBreakPoint(int id, DirectHandle< String > condition)
Definition factory.cc:4004
Handle< FixedArray > CopyFixedArrayAndGrow(DirectHandle< FixedArray > array, int grow_by, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2678
void InitializeJSObjectBody(Tagged< JSObject > obj, Tagged< Map > map, int start_offset)
Definition factory.cc:3111
Handle< JSDataViewOrRabGsabDataView > NewJSDataViewOrRabGsabDataView(DirectHandle< JSArrayBuffer > buffer, size_t byte_offset, size_t byte_length, bool is_length_tracking=false)
Definition factory.cc:3700
Handle< SmallOrderedHashMap > NewSmallOrderedHashMap(int capacity=kSmallOrderedHashMapMinCapacity, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:541
Handle< FeedbackVector > NewFeedbackVector(DirectHandle< SharedFunctionInfo > shared, DirectHandle< ClosureFeedbackCellArray > closure_feedback_cell_array, DirectHandle< FeedbackCell > parent_feedback_cell)
Definition factory.cc:453
DirectHandle< Map > CreateClassFunctionMap(DirectHandle< JSFunction > empty_function)
Definition factory.cc:4470
Handle< Foreign > NewForeign(Address addr, AllocationType allocation_type=AllocationType::kYoung)
Handle< JSProxy > NewJSProxy(DirectHandle< JSReceiver > target, DirectHandle< JSReceiver > handler)
Definition factory.cc:3776
DirectHandle< String > NewInternalizedStringImpl(DirectHandle< String > string, int len, uint32_t hash_field)
Definition factory.cc:932
Handle< String > NewCopiedSubstring(DirectHandle< String > str, uint32_t begin, uint32_t length)
Definition factory.cc:1059
Handle< OrderedHashSet > NewOrderedHashSet()
Definition factory.cc:556
Handle< T > CopyArrayWithMap(DirectHandle< T > src, DirectHandle< Map > map, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2609
Handle< AllocationSite > NewAllocationSite(bool with_weak_next)
Definition factory.cc:2279
V8_WARN_UNUSED_RESULT MaybeHandle< String > NewStringFromTwoByte(base::Vector< const base::uc16 > str, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:906
DirectHandle< JSMap > NewJSMap()
Definition factory.cc:3596
Tagged< HeapObject > AllocateRaw(int size, AllocationType allocation, AllocationAlignment alignment=kTaggedAligned)
Definition factory.cc:292
V8_INLINE HeapAllocator * allocator() const
DirectHandle< EnumCache > NewEnumCache(DirectHandle< FixedArray > keys, DirectHandle< FixedArray > indices, AllocationType allocation=AllocationType::kOld)
Definition factory.cc:375
MaybeDirectHandle< JSBoundFunction > NewJSBoundFunction(DirectHandle< JSReceiver > target_function, DirectHandle< JSAny > bound_this, base::Vector< DirectHandle< Object > > bound_args, DirectHandle< JSPrototype > prototype)
Definition factory.cc:3727
Handle< ScriptContextTable > NewScriptContextTable()
Definition factory.cc:1359
DirectHandle< Map > CreateSloppyFunctionMap(FunctionMode function_mode, MaybeDirectHandle< JSFunction > maybe_empty_function)
Definition factory.cc:4296
Tagged< Context > NewContextInternal(DirectHandle< Map > map, int size, int variadic_part_length, AllocationType allocation)
Definition factory.cc:1254
DirectHandle< PropertyDescriptorObject > NewPropertyDescriptorObject()
Definition factory.cc:573
Tagged< HeapObject > New(DirectHandle< Map > map, AllocationType allocation)
Definition factory.cc:337
Handle< JSObject > NewExternal(void *value, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2902
Handle< JSObject > CopyJSObjectWithAllocationSite(DirectHandle< JSObject > object, DirectHandle< AllocationSite > site)
Definition factory.cc:2493
Handle< String > InternalizeSubString(HandleType< SeqString >, uint32_t from, uint32_t length, bool convert_encoding=false)
Definition factory.cc:628
DirectHandle< EmbedderDataArray > NewEmbedderDataArray(int length)
Definition factory.cc:483
DirectHandle< JSObject > ShadowRealmNewTypeErrorCopy(DirectHandle< Object > original, MessageTemplate template_index, base::Vector< const DirectHandle< Object > > args)
Definition factory.cc:2813
Handle< OrderedHashMap > NewOrderedHashMap()
Definition factory.cc:562
DirectHandle< InterpreterData > NewInterpreterData(DirectHandle< BytecodeArray > bytecode_array, DirectHandle< Code > code)
Definition factory.cc:3911
DirectHandle< PropertyArray > CopyPropertyArrayAndGrow(DirectHandle< PropertyArray > array, int grow_by)
Definition factory.cc:2738
DirectHandle< Context > NewCatchContext(DirectHandle< Context > previous, DirectHandle< ScopeInfo > scope_info, DirectHandle< Object > thrown_object)
Definition factory.cc:1415
Handle< StoreHandler > NewStoreHandler(int data_count)
Definition factory.cc:4141
Handle< StackTraceInfo > NewStackTraceInfo(DirectHandle< FixedArray > frames)
Definition factory.cc:4048
void SetRegExpExperimentalData(DirectHandle< JSRegExp > regexp, DirectHandle< String > source, JSRegExp::Flags flags, int capture_count)
Definition factory.cc:4180
AllocationType AllocationTypeForInPlaceInternalizableString()
Definition factory.cc:4541
DirectHandle< ErrorStackData > NewErrorStackData(DirectHandle< UnionOf< JSAny, FixedArray > > call_site_infos_or_formatted_stack, DirectHandle< StackTraceInfo > stack_trace)
Definition factory.cc:1549
Handle< JSMessageObject > NewJSMessageObject(MessageTemplate message, DirectHandle< Object > argument, int start_position, int end_position, DirectHandle< SharedFunctionInfo > shared_info, int bytecode_offset, DirectHandle< Script > script, DirectHandle< StackTraceInfo > stack_trace=DirectHandle< StackTraceInfo >::null())
Definition factory.cc:3851
DirectHandle< String > NewSurrogatePairString(uint16_t lead, uint16_t trail)
Definition factory.cc:1043
DirectHandle< Tuple2 > NewTuple2Uninitialized(AllocationType allocation)
Definition factory.cc:390
V8_WARN_UNUSED_RESULT StringTransitionStrategy ComputeInternalizationStrategyForString(DirectHandle< String > string, MaybeDirectHandle< Map > *internalized_map)
Definition factory.cc:949
V8_WARN_UNUSED_RESULT StringTransitionStrategy ComputeSharingStrategyForString(DirectHandle< String > string, MaybeDirectHandle< Map > *shared_map)
Definition factory.cc:1006
DirectHandle< JSAsyncFromSyncIterator > NewJSAsyncFromSyncIterator(DirectHandle< JSReceiver > sync_iterator, DirectHandle< Object > next)
Definition factory.cc:3582
DirectHandle< Symbol > NewPrivateNameSymbol(DirectHandle< String > name)
Definition factory.cc:1246
Handle< Context > NewWithContext(DirectHandle< Context > previous, DirectHandle< ScopeInfo > scope_info, DirectHandle< JSReceiver > extension)
Definition factory.cc:1458
DirectHandle< JSDisposableStackBase > NewJSDisposableStackBase()
Definition factory.cc:3398
Handle< JSArray > NewJSArrayWithElements(DirectHandle< FixedArrayBase > elements, ElementsKind elements_kind, int length, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:3228
DirectHandle< PropertyArray > NewPropertyArray(int length, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:413
DirectHandle< WeakFixedArray > CopyWeakFixedArray(DirectHandle< WeakFixedArray > array)
Definition factory.cc:2683
Handle< SmallOrderedHashSet > NewSmallOrderedHashSet(int capacity=kSmallOrderedHashSetMinCapacity, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:535
Handle< JSFunction > NewFunctionForTesting(DirectHandle< String > name)
Definition factory.cc:4547
void NewJSArrayStorage(DirectHandle< JSArray > array, int length, int capacity, ArrayStorageAllocationMode mode=ArrayStorageAllocationMode::DONT_INITIALIZE_ARRAY_ELEMENTS)
Definition factory.cc:3290
Handle< JSPromise > NewJSPromise()
Definition factory.cc:4526
Handle< Map > ObjectLiteralMapFromCache(DirectHandle< NativeContext > native_context, int number_of_properties)
Definition factory.cc:4083
Handle< Context > NewDebugEvaluateContext(DirectHandle< Context > previous, DirectHandle< ScopeInfo > scope_info, DirectHandle< JSReceiver > extension, DirectHandle< Context > wrapped)
Definition factory.cc:1434
DirectHandle< FixedArrayBase > NewFixedDoubleArrayWithHoles(int size)
Definition factory.cc:501
DirectHandle< JSObject > NewSlowJSObjectWithPropertiesAndElements(DirectHandle< JSPrototype > prototype, DirectHandle< HeapObject > properties, DirectHandle< FixedArrayBase > elements)
Definition factory.cc:3186
int NumberToStringCacheHash(Tagged< Smi > number)
Definition factory.cc:3924
DirectHandle< RegExpData > NewExperimentalRegExpData(DirectHandle< String > source, JSRegExp::Flags flags, int capture_count)
Definition factory.cc:4241
Handle< JSObject > NewJSObjectFromMap(DirectHandle< Map > map, AllocationType allocation=AllocationType::kYoung, DirectHandle< AllocationSite > allocation_site=DirectHandle< AllocationSite >::null(), NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
Definition factory.cc:3135
Handle< Map > NewMap(DirectHandle< HeapObject > meta_map_holder, InstanceType type, int instance_size, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, int inobject_properties=0, AllocationType allocation_type=AllocationType::kMap)
Definition factory.cc:2385
Handle< JSArrayBuffer > NewJSArrayBuffer(std::shared_ptr< BackingStore > backing_store, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:3491
Handle< HeapNumber > NewHeapNumberForCodeAssembler(double value)
Definition factory.cc:2780
DirectHandle< BreakPointInfo > NewBreakPointInfo(int source_position)
Definition factory.cc:3994
Handle< JSObject > NewError(DirectHandle< JSFunction > constructor, DirectHandle< String > message, DirectHandle< Object > options={})
Definition factory.cc:2799
Handle< JSAtomicsCondition > NewJSAtomicsCondition()
Definition factory.cc:4616
DirectHandle< JSSyncDisposableStack > NewJSSyncDisposableStack(DirectHandle< Map > map)
Definition factory.cc:3407
Handle< JSAtomicsMutex > NewJSAtomicsMutex()
Definition factory.cc:4605
Handle< JSObject > NewSlowJSObjectFromMap(DirectHandle< Map > map, int number_of_slow_properties, AllocationType allocation=AllocationType::kYoung, DirectHandle< AllocationSite > allocation_site=DirectHandle< AllocationSite >::null(), NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
Definition factory.cc:3165
void ProcessNewScript(DirectHandle< Script > shared, ScriptEventType script_event_type)
Definition factory.cc:1561
Handle< FixedArray > CopyFixedArrayUpTo(DirectHandle< FixedArray > array, int new_len, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2743
DirectHandle< JSIteratorResult > NewJSIteratorResult(DirectHandle< Object > value, bool done)
Definition factory.cc:3569
static bool IsFunctionModeWithPrototype(FunctionMode function_mode)
Definition factory.h:1000
bool EmptyStringRootIsInitialized()
Definition factory.cc:4537
DirectHandle< JSAsyncDisposableStack > NewJSAsyncDisposableStack(DirectHandle< Map > map)
Definition factory.cc:3415
Handle< JSArray > NewJSArrayWithUnverifiedElements(DirectHandle< FixedArrayBase > elements, ElementsKind elements_kind, int length, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:3239
Handle< JSPromise > NewJSPromiseWithoutHook()
Definition factory.cc:4513
DirectHandle< ObjectTemplateInfo > NewObjectTemplateInfo(DirectHandle< FunctionTemplateInfo > constructor, bool do_not_cache)
Definition factory.cc:4682
HandleType< String > NewSubString(HandleType< T > str, uint32_t begin, uint32_t end)
Definition factory-inl.h:88
Handle< String > InternalizeUtf8String(base::Vector< const char > str)
Definition factory.cc:608
void InitializeJSObjectFromMap(Tagged< JSObject > obj, Tagged< Object > properties, Tagged< Map > map, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
Definition factory.cc:3086
Handle< String > SizeToString(size_t value, bool check_cache=true)
Definition factory.cc:3935
Handle< WeakArrayList > NewUninitializedWeakArrayList(int capacity, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:2653
Tagged< Symbol > NewSymbolInternal(AllocationType allocation=AllocationType::kOld)
Definition factory.cc:1208
Handle< DebugInfo > NewDebugInfo(DirectHandle< SharedFunctionInfo > shared)
Definition factory.cc:3975
Handle< JSObject > NewArgumentsObject(DirectHandle< JSFunction > callee, int length)
Definition factory.cc:4058
static const int kAlignedSize
static FieldIndex ForDescriptor(Tagged< Map > map, InternalIndex descriptor_index)
static constexpr int kMaxLength
V8_INLINE Address address() const
Definition handles.h:73
HandleType< T > CloseAndEscape(HandleType< T > handle_value)
void PatchValue(Tagged< T > new_value)
Definition handles.h:213
V8_INLINE bool CanAllocateInReadOnlySpace() const
V8_WARN_UNUSED_RESULT V8_INLINE Tagged< HeapObject > AllocateRawWith(int size, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
static V8_INLINE bool InYoungGeneration(Tagged< Object > object)
static V8_INLINE bool InAnySharedSpace(Tagged< HeapObject > object)
static JSDispatchHandle AllocateAndInstallJSDispatchHandle(ObjectType host, size_t offset, Isolate *isolate, uint16_t parameter_count, DirectHandle< Code > code, WriteBarrierMode mode=WriteBarrierMode::UPDATE_WRITE_BARRIER)
void set_allocation_sites_list(Tagged< UnionOf< Smi, Undefined, AllocationSiteWithWeakNext > > object)
Definition heap.h:466
void RegisterExternalString(Tagged< String > string)
Definition heap-inl.h:209
AllocationType allocation_type_for_in_place_internalizable_strings() const
Definition heap.h:2057
V8_EXPORT_PRIVATE void CopyRange(Tagged< HeapObject > dst_object, TSlot dst_slot, TSlot src_slot, int len, WriteBarrierMode mode)
static void Initialize(Isolate *isolate, DirectHandle< Hole > hole, DirectHandle< HeapNumber > numeric_value)
Definition hole-inl.h:31
static NEVER_READ_ONLY_SPACE constexpr bool kOnHeapBodyIsContiguous
static constexpr int SizeFor(int body_size)
static V8_INLINE Tagged< InstructionStream > Initialize(Tagged< HeapObject > self, Tagged< Map > map, uint32_t body_size, int constant_pool_offset, Tagged< TrustedByteArray > reloc_info)
static IsolateGroup * current()
Counters * counters()
Definition isolate.h:1180
int GenerateIdentityHash(uint32_t mask)
Definition isolate.cc:6343
Tagged< NativeContext > raw_native_context()
Definition isolate-inl.h:53
void RunAllPromiseHooks(PromiseHookType type, DirectHandle< JSPromise > promise, DirectHandle< Object > parent)
Definition isolate.cc:6861
Handle< NativeContext > native_context()
Definition isolate-inl.h:48
v8::internal::Factory * factory()
Definition isolate.h:1527
RootsTable & roots_table()
Definition isolate.h:1250
static Maybe< bool > GetResizableBackingStorePageConfiguration(Isolate *isolate, size_t byte_length, size_t max_byte_length, ShouldThrow should_throw, size_t *page_size, size_t *initial_pages, size_t *max_pages)
static constexpr uint32_t kMaxArrayIndex
Definition js-array.h:131
static constexpr StateT kUnlockedUncontended
static constexpr int kSizeWithPrototype
static V8_EXPORT_PRIVATE void EnsureFeedbackVector(Isolate *isolate, DirectHandle< JSFunction > function, IsCompiledScope *compiled_scope)
FeedbackVector eventually. Generally this shouldn't be used to get the.
static constexpr int kSizeWithoutPrototype
static V8_EXPORT_PRIVATE void EnsureHasInitialMap(DirectHandle< JSFunction > function)
static int GetHeaderSize(bool function_has_prototype_slot)
static void Initialize(DirectHandle< JSMap > map, Isolate *isolate)
Definition objects.cc:6289
static V8_EXPORT_PRIVATE void AddProperty(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static void ValidateElements(Tagged< JSObject > object)
static const int kMapCacheSize
Definition js-objects.h:949
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > V8_EXPORT_PRIVATE SetOwnPropertyIgnoreAttributes(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static void NotifyMapChange(DirectHandle< Map > old_map, DirectHandle< Map > new_map, Isolate *isolate)
static V8_EXPORT_PRIVATE void MigrateToMap(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Map > new_map, int expected_additional_properties=0)
static DirectHandle< Map > GetElementsTransitionMap(DirectHandle< JSObject > object, ElementsKind to_kind)
static constexpr int kUninitializedValue
Definition js-regexp.h:130
static void Initialize(DirectHandle< JSSet > set, Isolate *isolate)
Definition objects.cc:6271
static constexpr size_t kMaxByteLength
static void ForFixedTypedArray(ExternalArrayType array_type, size_t *element_size, ElementsKind *element_kind)
static void Initialize(DirectHandle< JSWeakCollection > collection, Isolate *isolate)
Definition objects.cc:6307
static V8_INLINE LargePageMetadata * FromHeapObject(Tagged< HeapObject > o)
static V8_EXPORT_PRIVATE Handle< Map > Create(Isolate *isolate, int inobject_properties)
Definition map.cc:1824
static V8_EXPORT_PRIVATE void EnsureDescriptorSlack(Isolate *isolate, DirectHandle< Map > map, int slack)
Definition map.cc:850
static constexpr Tagged< Smi > kPrototypeChainValidSmi
Definition map.h:519
static const int kNoSlackTracking
Definition map.h:349
static Handle< Map > CopyDropDescriptors(Isolate *isolate, DirectHandle< Map > map)
Definition map.cc:1480
static Handle< Map > Copy(Isolate *isolate, DirectHandle< Map > map, const char *reason, TransitionKindFlag kind=SPECIAL_TRANSITION)
Definition map.cc:1811
bool CanHaveFastTransitionableElementsKind() const
Definition map-inl.h:169
static V8_EXPORT_PRIVATE Handle< Map > TransitionRootMapToPrototypeForNewObject(Isolate *isolate, DirectHandle< Map > map, DirectHandle< JSPrototype > prototype)
Definition map.cc:2492
static V8_EXPORT_PRIVATE void SetPrototype(Isolate *isolate, DirectHandle< Map > map, DirectHandle< JSPrototype > prototype, bool enable_prototype_setup_mode=true)
Definition map.cc:2467
static V8_EXPORT_PRIVATE VisitorId GetVisitorId(Tagged< Map > map)
Definition map.cc:65
V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(DirectHandle< S > *out) const
V8_INLINE bool is_null() const
static MaybeObjectDirectHandle Weak(Tagged< Object > object, Isolate *isolate)
MarkingProgressTracker & marking_progress_tracker()
static V8_WARN_UNUSED_RESULT Handle< NameDictionary > New(IsolateT *isolate, int at_least_space_for, AllocationType allocation=AllocationType::kYoung, MinimumCapacity capacity_option=USE_DEFAULT_MINIMUM_CAPACITY)
static const int kInitialCapacity
Definition dictionary.h:250
static uint32_t CreateHashFieldValue(uint32_t hash, HashFieldType type)
Definition name-inl.h:132
static constexpr int kEmptyHashField
Definition name.h:133
bool Equals(Tagged< Name > other)
Definition name-inl.h:76
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > SetProperty(LookupIterator *it, DirectHandle< Object > value, StoreOrigin store_origin, Maybe< ShouldThrow > should_throw=Nothing< ShouldThrow >())
Definition objects.cc:2439
static MaybeHandle< OrderedHashMap > Allocate(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
static MaybeHandle< OrderedHashSet > Allocate(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
static const int kNoHashSentinel
PropertyAttributes attributes() const
static constexpr PropertyDetails Empty(PropertyCellType cell_type=PropertyCellType::kNoCell)
Tagged< Smi > AsSmi() const
Definition objects-inl.h:79
static const int kProtectorValid
Definition protectors.h:15
static V8_EXPORT_PRIVATE bool Contains(Address address)
static constexpr Representation Tagged()
IndirectHandle< HeapNumber > FindHeapNumber(double value)
Definition roots.cc:38
static Handle< ScriptContextTable > New(Isolate *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
Definition contexts.cc:28
static void InitLineEnds(Isolate *isolate, DirectHandle< Script > script)
Definition script-inl.h:201
static constexpr int kTemporaryScriptId
Definition script.h:42
static const uint32_t kMinLength
Definition string.h:1130
static constexpr Tagged< Smi > FromEnum(E value)
Definition smi.h:58
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
static constexpr Tagged< Smi > zero()
Definition smi.h:99
static constexpr int kMaxValue
Definition smi.h:101
static V8_INLINE uint32_t MakeArrayIndexHash(uint32_t value, uint32_t length)
base::Vector< const base::uc16 > ToUC16Vector() const
Definition string.h:145
static void WriteToFlat(Tagged< String > source, SinkCharT *sink, uint32_t start, uint32_t length)
Definition string.cc:772
static const uint32_t kMaxLength
Definition string.h:511
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
static constexpr int kMetaTableEnumerationDataStartIndex
static constexpr int SizeFor(int capacity)
static DirectHandle< SwissNameDictionary > ShallowCopy(Isolate *isolate, DirectHandle< SwissNameDictionary > table)
static void store(Tagged< HeapObject > host, PtrType value)
V8_INLINE constexpr StorageType ptr() const
constexpr bool IsCleared() const
V8_INLINE constexpr bool is_null() const
Definition tagged.h:502
static const int kUninitializedSerialNumber
Definition templates.h:41
static constexpr ThreadId Invalid()
Definition thread-id.h:35
static const int kSideStepTransitionsIndex
static int LengthFor(int number_of_transitions)
static const int kTransitionLengthIndex
static const int kPrototypeTransitionsIndex
static DirectHandle< TrustedManaged< CppType > > From(Isolate *isolate, size_t estimated_size, std::shared_ptr< CppType > shared_ptr)
Definition managed-inl.h:52
void Decode(Char *out, base::Vector< const uint8_t > data)
static V8_INLINE Tagged_t CompressObject(Address tagged)
static int SizeFor(Tagged< Map > map, int length)
static constexpr int MaxLength(uint32_t element_size_bytes)
static int DecodeElementSizeFromMap(Tagged< Map > map)
static constexpr size_t kCapacityOffset
static constexpr int kMaxLength
static constexpr int SizeFor(int length)
static constexpr size_t kLengthOffset
static int Size(const wasm::StructType *type)
static constexpr std::array< uint16_t, kTaggedFieldsCount > kTaggedFieldOffsets
static V8_WARN_UNUSED_RESULT DirectHandle< WeakArrayList > Append(Isolate *isolate, DirectHandle< WeakArrayList > array, MaybeObjectDirectHandle value, AllocationType allocation=AllocationType::kYoung)
static void ForRange(Heap *heap, Tagged< HeapObject > object, TSlot start, TSlot end)
V8_EXPORT_PRIVATE const CanonicalSig * LookupFunctionSignature(CanonicalTypeIndex index) const
Handle< Code > code
#define V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL
Definition globals.h:242
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
const PropertyKind kind_
int start
Handle< SharedFunctionInfo > info
int end
Handle< Context > context_
LineAndColumn previous
#define TYPED_ARRAYS(V)
#define RAB_GSAB_TYPED_ARRAYS_WITH_TYPED_ARRAY_TYPE(V)
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:291
#define THROW_NEW_ERROR(isolate, call)
Definition isolate.h:307
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
#define DCHECK_NEWLY_ALLOCATED_OBJECT_IS_YOUNG(isolate, object)
Definition factory.cc:1411
#define INIT_CALLBACK_FIELD(Name, name)
#define V8_ALLOCATION_SITE_TRACKING_BOOL
int32_t offset
std::string extension
TNode< Context > context
SharedFunctionInfoRef shared
TNode< Object > callback
std::map< const std::string, const std::string > map
std::string pattern
ZoneVector< RpoNumber > & result
#define LOG(isolate, Call)
Definition log.h:78
uint32_t const mask
LocalIsolate * local_isolate_
base::Mutex mutex
InstructionOperand source
const int length_
Definition mul-fft.cc:473
Utf8Variant
Definition unicode.h:145
unsigned short uint16_t
Definition unicode.cc:39
V8_BASE_EXPORT constexpr uint32_t RoundUpToPowerOfTwo32(uint32_t value)
Definition bits.h:219
V8_INLINE Dest bit_cast(Source const &source)
Definition macros.h:95
uint16_t uc16
Definition strings.h:18
bool MayHaveMapCheckFastCase(InstanceType type)
V8_INLINE constexpr bool IsInternalizedString(InstanceType instance_type)
V8_INLINE constexpr bool IsNativeContextSpecific(InstanceType instance_type)
V8_INLINE constexpr bool IsMaybeReadOnlyJSObject(InstanceType instance_type)
Node::Uses::const_iterator begin(const Node::Uses &uses)
Definition node.h:708
V8_EXPORT_PRIVATE WasmCodePointerTable * GetProcessWideWasmCodePointerTable()
constexpr uint32_t kMinimumSupertypeArraySize
std::optional< MessageTemplate > InitializeElementSegment(Zone *zone, Isolate *isolate, DirectHandle< WasmTrustedInstanceData > trusted_instance_data, DirectHandle< WasmTrustedInstanceData > shared_trusted_instance_data, uint32_t segment_index)
TypeCanonicalizer * GetTypeCanonicalizer()
constexpr WasmCodePointer kInvalidWasmCodePointer
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
constexpr int kFunctionEntryBytecodeOffset
Definition globals.h:854
constexpr int kTaggedSize
Definition globals.h:542
constexpr double kMaxSafeInteger
Definition globals.h:1985
constexpr int kMaxRegularHeapObjectSize
Definition globals.h:680
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
@ SKIP_WRITE_BARRIER
Definition objects.h:52
@ UPDATE_WRITE_BARRIER
Definition objects.h:55
SlotTraits::TObjectSlot ObjectSlot
Definition globals.h:1243
bool IsRabGsabTypedArrayElementsKind(ElementsKind kind)
Tagged(T object) -> Tagged< T >
kWasmInternalFunctionIndirectPointerTag instance_data
bool IsResumableFunction(FunctionKind kind)
constexpr intptr_t kCodeAlignment
Definition globals.h:964
kInterpreterTrampolineOffset Tagged< HeapObject >
void MemsetTagged(Tagged_t *start, Tagged< MaybeObject > value, size_t counter)
Definition slots-inl.h:486
@ TERMINAL_FAST_ELEMENTS_KIND
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
Definition flags.cc:2086
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
const int kVariableSizeSentinel
Definition objects.h:84
StringTransitionStrategy
Definition globals.h:2864
Handle< To > UncheckedCast(Handle< From > value)
Definition handles-inl.h:55
bool IsSmiOrObjectElementsKind(ElementsKind kind)
static const int kInvalidEnumCacheSentinel
bool IsAsyncGeneratorFunction(FunctionKind kind)
constexpr JSDispatchHandle kNullJSDispatchHandle(0)
bool IsShared(Tagged< Object > obj)
constexpr AdaptArguments kDontAdapt
Definition globals.h:2776
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
bool IsTerminalElementsKind(ElementsKind kind)
@ UNCACHED_EXTERNAL_TWO_BYTE_STRING_TYPE
@ UNCACHED_EXTERNAL_ONE_BYTE_STRING_TYPE
@ EXTERNAL_TWO_BYTE_STRING_TYPE
@ EXTERNAL_ONE_BYTE_STRING_TYPE
Tagged< MaybeWeak< T > > MakeWeak(Tagged< T > value)
Definition tagged.h:893
bool IsSharedArrayElementsKind(ElementsKind kind)
void CopyChars(DstType *dst, const SrcType *src, size_t count) V8_NONNULL(1
Map::Bits1::HasPrototypeSlotBit Map::Bits1::HasNamedInterceptorBit Map::Bits1::IsUndetectableBit Map::Bits1::IsConstructorBit Map::Bits2::IsImmutablePrototypeBit Map::Bits3::IsDeprecatedBit Map::Bits3::IsPrototypeMapBit bit_field3
Definition map-inl.h:137
bool is_strict(LanguageMode language_mode)
Definition globals.h:777
bool IsDictionaryElementsKind(ElementsKind kind)
Tagged< ClearedWeakValue > ClearedValue(PtrComprCageBase cage_base)
V8_EXPORT_PRIVATE FlagValues v8_flags
bool IsUniqueName(Tagged< Name > obj)
return value
Definition map-inl.h:893
bool IsJSApiWrapperObject(Tagged< Map > map)
static constexpr Address kNullAddress
Definition v8-internal.h:53
constexpr int kMaxInt
Definition globals.h:374
constexpr bool IsDoubleElementsKind(ElementsKind kind)
void MemCopy(void *dest, const void *src, size_t size)
Definition memcopy.h:124
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
Definition map-inl.h:70
ArrayStorageAllocationMode
Definition factory.h:134
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset prototype
Definition map-inl.h:69
template const char * string
kInterpreterTrampolineOffset script
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
v8_inspector::String16 String
Definition string-util.h:26
static constexpr ReleaseStoreTag kReleaseStore
Definition globals.h:2910
Local< T > Handle
static constexpr RelaxedStoreTag kRelaxedStore
Definition globals.h:2911
static constexpr AcquireLoadTag kAcquireLoad
Definition globals.h:2908
Maybe< T > Just(const T &t)
Definition v8-maybe.h:117
base::Vector< const char > contents
#define FATAL(...)
Definition logging.h:47
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define CHECK_IMPLIES(lhs, rhs)
#define CHECK(condition)
Definition logging.h:124
#define CHECK_LE(lhs, rhs)
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define CHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define CHECK_NE(lhs, rhs)
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define DCHECK_GT(v1, v2)
Definition logging.h:487
#define USE(...)
Definition macros.h:293
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403
#define arraysize(array)
Definition macros.h:67
#define V8_UNLIKELY(condition)
Definition v8config.h:660
SourcePositionTable * source_position_table_
#define ZONE_NAME
Definition zone.h:22