v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bootstrapper.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
6
8#include "src/api/api-inl.h"
10#include "src/base/hashmap.h"
11#include "src/base/ieee754.h"
14#include "src/common/globals.h"
15#include "src/debug/debug.h"
29#include "src/objects/objects.h"
30#include "src/sandbox/testing.h"
31#ifdef ENABLE_VTUNE_TRACEMARK
33#endif // ENABLE_VTUNE_TRACEMARK
34#include "src/heap/heap-inl.h"
36#include "src/logging/log.h"
42#ifdef V8_INTL_SUPPORT
44#endif // V8_INTL_SUPPORT
50#ifdef V8_INTL_SUPPORT
60#endif // V8_INTL_SUPPORT
64#ifdef V8_INTL_SUPPORT
69#endif // V8_INTL_SUPPORT
84
85#ifdef V8_FUZZILLI
87#endif
88
89#if V8_ENABLE_WEBASSEMBLY
90#include "src/wasm/wasm-js.h"
91#endif // V8_ENABLE_WEBASSEMBLY
92
93namespace v8 {
94namespace internal {
95
96void SourceCodeCache::Initialize(Isolate* isolate, bool create_heap_objects) {
97 cache_ = create_heap_objects ? ReadOnlyRoots(isolate).empty_fixed_array()
99}
100
102 v->VisitRootPointer(Root::kExtensions, nullptr, FullObjectSlot(&cache_));
103}
104
107 for (int i = 0; i < cache_->length(); i += 2) {
109 if (str->IsOneByteEqualTo(name)) {
110 *handle =
111 direct_handle(Cast<SharedFunctionInfo>(cache_->get(i + 1)), isolate);
112 return true;
113 }
114 }
115 return false;
116}
117
120 Factory* factory = isolate->factory();
121 HandleScope scope(isolate);
122 int length = cache_->length();
123 DirectHandle<FixedArray> new_array =
124 factory->NewFixedArray(length + 2, AllocationType::kOld);
125 FixedArray::CopyElements(isolate, *new_array, 0, cache_, 0, cache_->length());
126 cache_ = *new_array;
128 factory
131 .ToHandleChecked();
132 DCHECK(!str.is_null());
133 cache_->set(length, *str);
134 cache_->set(length + 1, *shared);
135 Cast<Script>(shared->script())->set_type(type_);
136}
137
139 : isolate_(isolate),
140 nesting_(0),
141 extensions_cache_(Script::Type::kExtension) {}
142
143void Bootstrapper::Initialize(bool create_heap_objects) {
144 extensions_cache_.Initialize(isolate_, create_heap_objects);
145}
146
147static const char* GCFunctionName() {
148 bool flag_given =
149 v8_flags.expose_gc_as != nullptr && strlen(v8_flags.expose_gc_as) != 0;
150 return flag_given ? v8_flags.expose_gc_as : "gc";
151}
152
154 return v8_flags.expose_cputracemark_as != nullptr &&
155 strlen(v8_flags.expose_cputracemark_as) != 0;
156}
157
159 v8::RegisterExtension(std::make_unique<GCExtension>(GCFunctionName()));
160#ifdef V8_FUZZILLI
161 v8::RegisterExtension(std::make_unique<FuzzilliExtension>("fuzzilli"));
162#endif
163 v8::RegisterExtension(std::make_unique<ExternalizeStringExtension>());
164 v8::RegisterExtension(std::make_unique<StatisticsExtension>());
165 v8::RegisterExtension(std::make_unique<TriggerFailureExtension>());
166 v8::RegisterExtension(std::make_unique<IgnitionStatisticsExtension>());
168 v8::RegisterExtension(std::make_unique<CpuTraceMarkExtension>(
169 v8_flags.expose_cputracemark_as));
170 }
171#ifdef ENABLE_VTUNE_TRACEMARK
173 std::make_unique<VTuneDomainSupportExtension>("vtunedomainmark"));
174#endif // ENABLE_VTUNE_TRACEMARK
175}
176
178 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
179}
180
181class Genesis {
182 public:
183 Genesis(Isolate* isolate, MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
184 v8::Local<v8::ObjectTemplate> global_proxy_template,
185 size_t context_snapshot_index,
186 DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
188 Genesis(Isolate* isolate, MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
189 v8::Local<v8::ObjectTemplate> global_proxy_template);
190 ~Genesis() = default;
191
192 Isolate* isolate() const { return isolate_; }
193 Factory* factory() const { return isolate_->factory(); }
194 Builtins* builtins() const { return isolate_->builtins(); }
195 Heap* heap() const { return isolate_->heap(); }
196
198
200
201 private:
203
204 // Creates some basic objects. Used for creating a context from scratch.
205 void CreateRoots();
206 // Creates the empty function. Used for creating a context from scratch.
208 // Returns the %ThrowTypeError% intrinsic function.
209 // See ES#sec-%throwtypeerror% for details.
211
218 void CreateJSProxyMaps();
219
220 // Make the "arguments" and "caller" properties throw a TypeError on access.
222
223 // Creates the global objects using the global proxy and the template passed
224 // in through the API. We call this regardless of whether we are building a
225 // context from scratch or using a deserialized one from the context snapshot
226 // but in the latter case we don't use the objects it produces directly, as
227 // we have to use the deserialized ones that are linked together with the
228 // rest of the context snapshot. At the end we link the global proxy and the
229 // context to each other.
231 v8::Local<v8::ObjectTemplate> global_proxy_template,
233 // Similarly, we want to use the global that has been created by the templates
234 // passed through the API. The global from the snapshot is detached from the
235 // other objects in the snapshot.
237 // Hooks the given global proxy into the context in the case we do not
238 // replace the global object from the deserialized native context.
240 // The native context has a ScriptContextTable that store declarative bindings
241 // made in script scopes. Add a "this" binding to that table pointing to the
242 // global proxy.
244 // New context initialization. Used for creating a context from scratch.
246 DirectHandle<JSFunction> empty_function);
250 void InitializeConsole(DirectHandle<JSObject> extras_binding);
251
252#define DECLARE_FEATURE_INITIALIZATION(id, descr) void InitializeGlobal_##id();
253
260#undef DECLARE_FEATURE_INITIALIZATION
263#if V8_ENABLE_WEBASSEMBLY
264 void InitializeWasmJSPI();
265#endif
266
269 ArrayBufferKind array_buffer_kind);
270
273
275 ElementsKind elements_kind,
276 InstanceType constructor_type,
277 int rab_gsab_initial_map_index);
278 void InitializeMapCaches();
279
281
294
295 // Used both for deserialized and from-scratch contexts to add the extensions
296 // provided.
297 static bool InstallExtensions(Isolate* isolate,
299 v8::ExtensionConfiguration* extensions);
300 static bool InstallAutoExtensions(Isolate* isolate,
301 ExtensionStates* extension_states);
302 static bool InstallRequestedExtensions(Isolate* isolate,
303 v8::ExtensionConfiguration* extensions,
304 ExtensionStates* extension_states);
305 static bool InstallExtension(Isolate* isolate, const char* name,
306 ExtensionStates* extension_states);
307 static bool InstallExtension(Isolate* isolate,
309 ExtensionStates* extension_states);
310 static bool InstallSpecialObjects(Isolate* isolate,
313 DirectHandle<ObjectTemplateInfo> object_template);
315 v8::Local<v8::ObjectTemplate> global_proxy_template);
316
317 // Migrates all properties from the 'from' object to the 'to'
318 // object and overrides the prototype in 'to' with the one from
319 // 'from'.
325
327 int inobject_properties);
328
329 static bool CompileExtension(Isolate* isolate, v8::Extension* extension);
330
335
336 // %ThrowTypeError%. See ES#sec-%throwtypeerror% for details.
338
340 friend class Bootstrapper;
341};
342
345 v->Synchronize(VisitorSynchronization::kExtensions);
346}
347
349 MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
350 v8::Local<v8::ObjectTemplate> global_proxy_template,
351 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
352 DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
354 HandleScope scope(isolate_);
356 {
357 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template,
358 context_snapshot_index, embedder_fields_deserializer,
360 env = genesis.result();
361 if (env.is_null() || !InstallExtensions(env, extensions)) {
362 return {};
363 }
364 }
365 LogAllMaps();
367 return scope.CloseAndEscape(env);
368}
369
371 MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
372 v8::Local<v8::ObjectTemplate> global_proxy_template) {
373 HandleScope scope(isolate_);
374 DirectHandle<JSGlobalProxy> global_proxy;
375 {
376 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template);
377 global_proxy = genesis.global_proxy();
378 if (global_proxy.is_null()) return {};
379 }
380 LogAllMaps();
381 return scope.CloseAndEscape(global_proxy);
382}
383
385 if (!v8_flags.log_maps || isolate_->initialized_from_snapshot()) return;
386 // Log all created Map objects that are on the heap. For snapshots the Map
387 // logging happens during deserialization in order to avoid printing Maps
388 // multiple times during partial deserialization.
390}
391
392namespace {
393
394#ifdef DEBUG
395bool IsFunctionMapOrSpecialBuiltin(DirectHandle<Map> map, Builtin builtin,
396 DirectHandle<Context> context) {
397 // During bootstrapping some of these maps could be not created yet.
398 return ((*map == context->get(Context::STRICT_FUNCTION_MAP_INDEX)) ||
399 (*map == context->get(
400 Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX)) ||
401 (*map ==
402 context->get(
403 Context::STRICT_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX)) ||
404 // Check if it's a creation of an empty or Proxy function during
405 // bootstrapping.
406 (builtin == Builtin::kEmptyFunction ||
407 builtin == Builtin::kProxyConstructor));
408}
409#endif // DEBUG
410
411DirectHandle<SharedFunctionInfo> CreateSharedFunctionInfoForBuiltin(
412 Isolate* isolate, DirectHandle<String> name, Builtin builtin, int len,
413 AdaptArguments adapt) {
414 DirectHandle<SharedFunctionInfo> info =
415 isolate->factory()->NewSharedFunctionInfoForBuiltin(name, builtin, len,
416 adapt);
417 info->set_language_mode(LanguageMode::kStrict);
418
419#ifdef DEBUG
420 Tagged<Code> code = info->GetCode(isolate);
421 if (code->parameter_count() != kDontAdaptArgumentsSentinel) {
422 DCHECK_EQ(info->internal_formal_parameter_count_with_receiver(),
423 code->parameter_count());
424 }
425#endif
426
427 return info;
428}
429
430V8_NOINLINE DirectHandle<JSFunction> CreateFunctionForBuiltin(
431 Isolate* isolate, DirectHandle<String> name, DirectHandle<Map> map,
432 Builtin builtin, int len, AdaptArguments adapt) {
433 DirectHandle<NativeContext> context(isolate->native_context());
434 DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin, context));
435
436 DirectHandle<SharedFunctionInfo> info =
437 CreateSharedFunctionInfoForBuiltin(isolate, name, builtin, len, adapt);
438
439 return Factory::JSFunctionBuilder{isolate, info, context}
440 .set_map(map)
441 .Build();
442}
443
444V8_NOINLINE DirectHandle<JSFunction> CreateFunctionForBuiltinWithPrototype(
445 Isolate* isolate, DirectHandle<String> name, Builtin builtin,
446 DirectHandle<UnionOf<JSPrototype, Hole>> prototype, InstanceType type,
447 int instance_size, int inobject_properties,
448 MutableMode prototype_mutability, int len, AdaptArguments adapt) {
449 Factory* factory = isolate->factory();
450 DirectHandle<NativeContext> context(isolate->native_context());
451 DirectHandle<Map> map =
452 prototype_mutability == MUTABLE
453 ? isolate->strict_function_map()
454 : isolate->strict_function_with_readonly_prototype_map();
455 DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin, context));
456
457 DirectHandle<SharedFunctionInfo> info =
458 CreateSharedFunctionInfoForBuiltin(isolate, name, builtin, len, adapt);
459 info->set_expected_nof_properties(inobject_properties);
460
461 DirectHandle<JSFunction> result =
462 Factory::JSFunctionBuilder{isolate, info, context}.set_map(map).Build();
463
464 ElementsKind elements_kind;
465 switch (type) {
466 case JS_ARRAY_TYPE:
467 elements_kind = PACKED_SMI_ELEMENTS;
468 break;
469 case JS_ARGUMENTS_OBJECT_TYPE:
470 elements_kind = PACKED_ELEMENTS;
471 break;
472 default:
473 elements_kind = TERMINAL_FAST_ELEMENTS_KIND;
474 break;
475 }
476 DirectHandle<Map> initial_map = factory->NewContextfulMapForCurrentContext(
477 type, instance_size, elements_kind, inobject_properties);
478 initial_map->SetConstructor(*result);
479 if (type == JS_FUNCTION_TYPE) {
481 // Since we are creating an initial map for JSFunction objects with
482 // prototype slot, set the respective bit.
483 initial_map->set_has_prototype_slot(true);
484 }
485 // TODO(littledan): Why do we have this is_generator test when
486 // NewFunctionPrototype already handles finding an appropriately
487 // shared prototype?
488 if (!IsResumableFunction(info->kind()) && IsTheHole(*prototype, isolate)) {
489 prototype = factory->NewFunctionPrototype(result);
490 }
491 JSFunction::SetInitialMap(isolate, result, initial_map,
492 Cast<JSPrototype>(prototype));
493
494 return result;
495}
496
497V8_NOINLINE Handle<JSFunction> CreateFunctionForBuiltinWithoutPrototype(
498 Isolate* isolate, DirectHandle<String> name, Builtin builtin, int len,
499 AdaptArguments adapt) {
500 DirectHandle<NativeContext> context(isolate->native_context());
501 DirectHandle<Map> map = isolate->strict_function_without_prototype_map();
502 DCHECK(IsFunctionMapOrSpecialBuiltin(map, builtin, context));
503
504 DirectHandle<SharedFunctionInfo> info =
505 CreateSharedFunctionInfoForBuiltin(isolate, name, builtin, len, adapt);
506
507 return Factory::JSFunctionBuilder{isolate, info, context}
508 .set_map(map)
509 .Build();
510}
511
512V8_NOINLINE DirectHandle<JSFunction> CreateFunction(
513 Isolate* isolate, DirectHandle<String> name, InstanceType type,
514 int instance_size, int inobject_properties,
515 DirectHandle<UnionOf<JSPrototype, Hole>> prototype, Builtin builtin,
516 int len, AdaptArguments adapt) {
518
519 DirectHandle<JSFunction> result = CreateFunctionForBuiltinWithPrototype(
520 isolate, name, builtin, prototype, type, instance_size,
521 inobject_properties, IMMUTABLE, len, adapt);
522
523 // Make the JSFunction's prototype object fast.
525 kStartAtReceiver, isolate);
526
527 // Make the resulting JSFunction object fast.
529 result->shared()->set_native(true);
530 return result;
531}
532
533V8_NOINLINE DirectHandle<JSFunction> CreateFunction(
534 Isolate* isolate, const char* name, InstanceType type, int instance_size,
535 int inobject_properties, DirectHandle<UnionOf<JSPrototype, Hole>> prototype,
536 Builtin builtin, int len, AdaptArguments adapt) {
537 return CreateFunction(
538 isolate, isolate->factory()->InternalizeUtf8String(name), type,
539 instance_size, inobject_properties, prototype, builtin, len, adapt);
540}
541
542V8_NOINLINE DirectHandle<JSFunction> InstallFunction(
543 Isolate* isolate, DirectHandle<JSObject> target, DirectHandle<String> name,
544 InstanceType type, int instance_size, int inobject_properties,
545 DirectHandle<UnionOf<JSPrototype, Hole>> prototype, Builtin call, int len,
546 AdaptArguments adapt) {
548 DirectHandle<JSFunction> function =
549 CreateFunction(isolate, name, type, instance_size, inobject_properties,
550 prototype, call, len, adapt);
551 JSObject::AddProperty(isolate, target, name, function, DONT_ENUM);
552 return function;
553}
554
555V8_NOINLINE DirectHandle<JSFunction> InstallFunction(
556 Isolate* isolate, DirectHandle<JSObject> target, const char* name,
557 InstanceType type, int instance_size, int inobject_properties,
558 DirectHandle<UnionOf<JSPrototype, Hole>> prototype, Builtin call, int len,
559 AdaptArguments adapt) {
560 return InstallFunction(
561 isolate, target, isolate->factory()->InternalizeUtf8String(name), type,
562 instance_size, inobject_properties, prototype, call, len, adapt);
563}
564
565// This sets a constructor instance type on the constructor map which will be
566// used in IsXxxConstructor() predicates. Having such predicates helps figuring
567// out if a protector cell should be invalidated. If there are no protector
568// cell checks required for constructor, this function must not be used.
569// Note, this function doesn't create a copy of the constructor's map. So it's
570// better to set constructor instance type after all the properties are added
571// to the constructor and thus the map is already guaranteed to be unique.
572V8_NOINLINE void SetConstructorInstanceType(
573 Isolate* isolate, DirectHandle<JSFunction> constructor,
574 InstanceType constructor_type) {
575 DCHECK(InstanceTypeChecker::IsJSFunction(constructor_type));
576 DCHECK_NE(constructor_type, JS_FUNCTION_TYPE);
577
578 Tagged<Map> map = constructor->map();
579
580 // Check we don't accidentally change one of the existing maps.
581 DCHECK_NE(map, *isolate->strict_function_map());
582 DCHECK_NE(map, *isolate->strict_function_with_readonly_prototype_map());
583 // Constructor function map is always a root map, and thus we don't have to
584 // deal with updating the whole transition tree.
585 DCHECK(IsUndefined(map->GetBackPointer(), isolate));
586 DCHECK_EQ(JS_FUNCTION_TYPE, map->instance_type());
587
588 map->set_instance_type(constructor_type);
589}
590
591V8_NOINLINE Handle<JSFunction> SimpleCreateFunction(Isolate* isolate,
592 DirectHandle<String> name,
593 Builtin call, int len,
594 AdaptArguments adapt) {
596 name = String::Flatten(isolate, name, AllocationType::kOld);
598 CreateFunctionForBuiltinWithoutPrototype(isolate, name, call, len, adapt);
599 // Make the resulting JSFunction object fast.
601 fun->shared()->set_native(true);
602 return fun;
603}
604
605V8_NOINLINE Handle<JSFunction> InstallFunctionWithBuiltinId(
606 Isolate* isolate, DirectHandle<JSObject> base, const char* name,
607 Builtin call, int len, AdaptArguments adapt) {
608 DirectHandle<String> internalized_name =
609 isolate->factory()->InternalizeUtf8String(name);
611 SimpleCreateFunction(isolate, internalized_name, call, len, adapt);
612 JSObject::AddProperty(isolate, base, internalized_name, fun, DONT_ENUM);
613 return fun;
614}
615
616V8_NOINLINE Handle<JSFunction> InstallFunctionAtSymbol(
617 Isolate* isolate, DirectHandle<JSObject> base, DirectHandle<Symbol> symbol,
618 const char* symbol_string, Builtin call, int len, AdaptArguments adapt,
620 DirectHandle<String> internalized_symbol =
621 isolate->factory()->InternalizeUtf8String(symbol_string);
623 SimpleCreateFunction(isolate, internalized_symbol, call, len, adapt);
624 JSObject::AddProperty(isolate, base, symbol, fun, attrs);
625 return fun;
626}
627
628V8_NOINLINE DirectHandle<JSFunction> CreateSharedObjectConstructor(
629 Isolate* isolate, DirectHandle<String> name, DirectHandle<Map> instance_map,
630 Builtin builtin, int len, AdaptArguments adapt) {
631 Factory* factory = isolate->factory();
632 DirectHandle<SharedFunctionInfo> info =
633 factory->NewSharedFunctionInfoForBuiltin(name, builtin, len, adapt);
634 info->set_language_mode(LanguageMode::kStrict);
635 DirectHandle<JSFunction> constructor =
636 Factory::JSFunctionBuilder{isolate, info, isolate->native_context()}
637 .set_map(isolate->strict_function_with_readonly_prototype_map())
638 .Build();
639 constructor->set_prototype_or_initial_map(*instance_map, kReleaseStore);
640
642 isolate, constructor, factory->has_instance_symbol(),
644 isolate->native_context()->shared_space_js_object_has_instance(),
645 isolate),
647 return constructor;
648}
649
650V8_NOINLINE void SimpleInstallGetterSetter(Isolate* isolate,
651 DirectHandle<JSObject> base,
652 DirectHandle<Name> name,
653 Builtin call_getter,
654 Builtin call_setter) {
655 DirectHandle<String> getter_name =
656 Name::ToFunctionName(isolate, name, isolate->factory()->get_string())
657 .ToHandleChecked();
658 DirectHandle<JSFunction> getter =
659 SimpleCreateFunction(isolate, getter_name, call_getter, 0, kAdapt);
660
661 DirectHandle<String> setter_name =
662 Name::ToFunctionName(isolate, name, isolate->factory()->set_string())
663 .ToHandleChecked();
664 DirectHandle<JSFunction> setter =
665 SimpleCreateFunction(isolate, setter_name, call_setter, 1, kAdapt);
666
668 DONT_ENUM)
669 .Check();
670}
671
672void SimpleInstallGetterSetter(Isolate* isolate, DirectHandle<JSObject> base,
673 const char* name, Builtin call_getter,
674 Builtin call_setter) {
675 SimpleInstallGetterSetter(isolate, base,
676 isolate->factory()->InternalizeUtf8String(name),
677 call_getter, call_setter);
678}
679
680V8_NOINLINE Handle<JSFunction> SimpleInstallGetter(
681 Isolate* isolate, DirectHandle<JSObject> base, DirectHandle<Name> name,
682 DirectHandle<Name> property_name, Builtin call, AdaptArguments adapt) {
683 DirectHandle<String> getter_name =
684 Name::ToFunctionName(isolate, name, isolate->factory()->get_string())
685 .ToHandleChecked();
687 SimpleCreateFunction(isolate, getter_name, call, 0, adapt);
688
689 DirectHandle<Object> setter = isolate->factory()->undefined_value();
690
693 .Check();
694
695 return getter;
696}
697
698V8_NOINLINE Handle<JSFunction> SimpleInstallGetter(Isolate* isolate,
699 DirectHandle<JSObject> base,
700 DirectHandle<Name> name,
701 Builtin call,
702 AdaptArguments adapt) {
703 return SimpleInstallGetter(isolate, base, name, name, call, adapt);
704}
705
706V8_NOINLINE void InstallConstant(Isolate* isolate,
707 DirectHandle<JSObject> holder,
708 const char* name, DirectHandle<Object> value) {
710 isolate, holder, isolate->factory()->InternalizeUtf8String(name), value,
712}
713
714V8_NOINLINE void InstallTrueValuedProperty(Isolate* isolate,
715 DirectHandle<JSObject> holder,
716 const char* name) {
717 JSObject::AddProperty(isolate, holder,
718 isolate->factory()->InternalizeUtf8String(name),
719 isolate->factory()->true_value(), NONE);
720}
721
722V8_NOINLINE void InstallSpeciesGetter(Isolate* isolate,
723 DirectHandle<JSFunction> constructor) {
724 Factory* factory = isolate->factory();
725 // TODO(adamk): We should be able to share a SharedFunctionInfo
726 // between all these JSFunctions.
727 SimpleInstallGetter(isolate, constructor, factory->symbol_species_string(),
728 factory->species_symbol(), Builtin::kReturnReceiver,
729 kAdapt);
730}
731
732V8_NOINLINE void InstallToStringTag(Isolate* isolate,
733 DirectHandle<JSObject> holder,
734 DirectHandle<String> value) {
735 JSObject::AddProperty(isolate, holder,
736 isolate->factory()->to_string_tag_symbol(), value,
737 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
738}
739
740void InstallToStringTag(Isolate* isolate, DirectHandle<JSObject> holder,
741 const char* value) {
742 InstallToStringTag(isolate, holder,
743 isolate->factory()->InternalizeUtf8String(value));
744}
745
746// Create a map for result objects returned from builtins in such a way that
747// it's exactly the same map as the one produced by object literals. E.g.,
748// iterator result objects have the same map as literals in the form `{value,
749// done}`.
750//
751// This way we have better sharing of maps (i.e. less polymorphism) and also
752// make it possible to hit the fast-paths in various builtins (i.e. promises and
753// collections) with user defined iterators.
754template <size_t N>
755DirectHandle<Map> CreateLiteralObjectMapFromCache(
756 Isolate* isolate, const std::array<DirectHandle<Name>, N>& properties) {
757 Factory* factory = isolate->factory();
758 DirectHandle<NativeContext> native_context = isolate->native_context();
759 DirectHandle<Map> map = factory->ObjectLiteralMapFromCache(native_context, N);
760 for (DirectHandle<Name> name : properties) {
761 map = Map::CopyWithField(isolate, map, name, FieldType::Any(isolate), NONE,
764 .ToHandleChecked();
765 }
766 return map;
767}
768
769} // namespace
770
772 // Allocate the function map first and then patch the prototype later.
773 DirectHandle<Map> empty_function_map =
775 empty_function_map->set_is_prototype_map(true);
776 DCHECK(!empty_function_map->is_dictionary_map());
777
778 // Allocate the empty function as the prototype for function according to
779 // ES#sec-properties-of-the-function-prototype-object
780 DirectHandle<JSFunction> empty_function = CreateFunctionForBuiltin(
781 isolate(), factory()->empty_string(), empty_function_map,
782 Builtin::kEmptyFunction, 0, kDontAdapt);
783 empty_function_map->SetConstructor(*empty_function);
784 native_context()->set_empty_function(*empty_function);
785
786 // --- E m p t y ---
788 DirectHandle<Script> script = factory()->NewScript(source);
789 script->set_type(Script::Type::kNative);
791 script->set_infos(*infos);
792 ReadOnlyRoots roots{isolate()};
793 Tagged<SharedFunctionInfo> sfi = empty_function->shared();
794 sfi->set_raw_scope_info(roots.empty_function_scope_info());
795 sfi->SetScript(isolate(), roots, *script, 1);
796 sfi->UpdateFunctionMapIndex();
797
798 return empty_function;
799}
800
804
805 //
806 // Allocate maps for sloppy functions without prototype.
807 //
809 native_context()->set_sloppy_function_without_prototype_map(*map);
810
811 //
812 // Allocate maps for sloppy functions with readonly prototype.
813 //
814 map =
816 native_context()->set_sloppy_function_with_readonly_prototype_map(*map);
817
818 //
819 // Allocate maps for sloppy functions with writable prototype.
820 //
822 empty);
823 native_context()->set_sloppy_function_map(*map);
824
827 native_context()->set_sloppy_function_with_name_map(*map);
828}
829
831 if (!restricted_properties_thrower_.is_null()) {
833 }
834 DirectHandle<String> name = factory()->empty_string();
835 DirectHandle<JSFunction> function = CreateFunctionForBuiltinWithoutPrototype(
836 isolate(), name, Builtin::kStrictPoisonPillThrower, 0, kAdapt);
837
838 // %ThrowTypeError% must have a name property with an empty string value. Per
839 // spec, ThrowTypeError's name is non-configurable, unlike ordinary functions'
840 // name property. To redefine it to be non-configurable, use
841 // SetOwnPropertyIgnoreAttributes.
843 function, factory()->name_string(), factory()->empty_string(),
845 .Assert();
846
847 // length needs to be non configurable.
848 DirectHandle<Object> value(Smi::FromInt(function->length()), isolate());
850 function, factory()->length_string(), value,
852 .Assert();
853
855 .IsNothing()) {
856 DCHECK(false);
857 }
858
859 JSObject::MigrateSlowToFast(function, 0, "Bootstrapping");
860
862 return function;
863}
864
868
869 //
870 // Allocate maps for strict functions without prototype.
871 //
873 native_context()->set_strict_function_without_prototype_map(*map);
874
876 native_context()->set_method_with_name_map(*map);
877
878 //
879 // Allocate maps for strict functions with writable prototype.
880 //
882 empty);
883 native_context()->set_strict_function_map(*map);
884
887 native_context()->set_strict_function_with_name_map(*map);
888
889 //
890 // Allocate maps for strict functions with readonly prototype.
891 //
892 map =
894 native_context()->set_strict_function_with_readonly_prototype_map(*map);
895
896 //
897 // Allocate map for class functions.
898 //
899 map = factory->CreateClassFunctionMap(empty);
900 native_context()->set_class_function_map(*map);
901
902 // Now that the strict mode function map is available, set up the
903 // restricted "arguments" and "caller" getters.
905}
906
909
910 // --- O b j e c t ---
912 int instance_size = JSObject::kHeaderSize + kTaggedSize * inobject_properties;
913
914 DirectHandle<JSFunction> object_fun =
915 CreateFunction(isolate_, factory->Object_string(), JS_OBJECT_TYPE,
916 instance_size, inobject_properties, factory->null_value(),
917 Builtin::kObjectConstructor, 1, kDontAdapt);
918 native_context()->set_object_function(*object_fun);
919
920 {
921 // Finish setting up Object function's initial map.
922 Tagged<Map> initial_map = object_fun->initial_map();
923 initial_map->set_elements_kind(HOLEY_ELEMENTS);
924 }
925
926 // Allocate a new prototype for the object function.
927 DirectHandle<JSObject> object_function_prototype =
928 factory->NewFunctionPrototype(object_fun);
929
930 {
932 isolate(), direct_handle(object_function_prototype->map(), isolate()),
933 "EmptyObjectPrototype");
934 map->set_is_prototype_map(true);
935 // Ban re-setting Object.prototype.__proto__ to prevent Proxy security bug
936 map->set_is_immutable_proto(true);
937 object_function_prototype->set_map(isolate(), *map);
938 }
939
940 // Complete setting up empty function.
941 {
942 DirectHandle<Map> empty_function_map(empty_function->map(), isolate_);
943 Map::SetPrototype(isolate(), empty_function_map, object_function_prototype);
944 }
945
946 native_context()->set_initial_object_prototype(*object_function_prototype);
947 JSFunction::SetPrototype(object_fun, object_function_prototype);
948 object_function_prototype->map()->set_instance_type(JS_OBJECT_PROTOTYPE_TYPE);
949 {
950 // Set up slow map for Object.create(null) instances without in-object
951 // properties.
952 DirectHandle<Map> map(object_fun->initial_map(), isolate_);
954 Map::SetPrototype(isolate(), map, factory->null_value());
955 native_context()->set_slow_object_with_null_prototype_map(*map);
956
957 // Set up slow map for literals with too many properties.
958 map = Map::Copy(isolate(), map, "slow_object_with_object_prototype_map");
959 Map::SetPrototype(isolate(), map, object_function_prototype);
960 native_context()->set_slow_object_with_object_prototype_map(*map);
961 }
962}
963
964namespace {
965
966DirectHandle<Map> CreateNonConstructorMap(Isolate* isolate,
967 DirectHandle<Map> source_map,
968 DirectHandle<JSObject> prototype,
969 const char* reason) {
970 DirectHandle<Map> map = Map::Copy(isolate, source_map, reason);
971 // Ensure the resulting map has prototype slot (it is necessary for storing
972 // initial map even when the prototype property is not required).
973 if (!map->has_prototype_slot()) {
974 // Re-set the unused property fields after changing the instance size.
975 int unused_property_fields = map->UnusedPropertyFields();
976 map->set_instance_size(map->instance_size() + kTaggedSize);
977 // The prototype slot shifts the in-object properties area by one slot.
978 map->SetInObjectPropertiesStartInWords(
979 map->GetInObjectPropertiesStartInWords() + 1);
980 map->set_has_prototype_slot(true);
981 map->SetInObjectUnusedPropertyFields(unused_property_fields);
982 }
983 map->set_is_constructor(false);
984 Map::SetPrototype(isolate, map, prototype);
985 return map;
986}
987
988} // namespace
989
992 const char* name, Builtin call,
993 int len, AdaptArguments adapt,
994 PropertyAttributes attrs) {
995 // Although function name does not have to be internalized the property name
996 // will be internalized during property addition anyway, so do it here now.
997 DirectHandle<String> internalized_name =
998 isolate->factory()->InternalizeUtf8String(name);
1000 SimpleCreateFunction(isolate, internalized_name, call, len, adapt);
1001 JSObject::AddProperty(isolate, base, internalized_name, fun, attrs);
1002 return fun;
1003}
1004
1006 // Create iterator-related meta-objects.
1007 DirectHandle<JSObject> iterator_prototype = factory()->NewJSObject(
1008 isolate()->object_function(), AllocationType::kOld);
1009
1010 InstallFunctionAtSymbol(isolate(), iterator_prototype,
1011 factory()->iterator_symbol(), "[Symbol.iterator]",
1012 Builtin::kReturnReceiver, 0, kAdapt);
1013 native_context()->set_initial_iterator_prototype(*iterator_prototype);
1014 CHECK_NE(iterator_prototype->map().ptr(),
1015 isolate_->initial_object_prototype()->map().ptr());
1016 iterator_prototype->map()->set_instance_type(JS_ITERATOR_PROTOTYPE_TYPE);
1017
1018 DirectHandle<JSObject> generator_object_prototype = factory()->NewJSObject(
1019 isolate()->object_function(), AllocationType::kOld);
1020 native_context()->set_initial_generator_prototype(
1021 *generator_object_prototype);
1022 JSObject::ForceSetPrototype(isolate(), generator_object_prototype,
1023 iterator_prototype);
1024 DirectHandle<JSObject> generator_function_prototype = factory()->NewJSObject(
1025 isolate()->object_function(), AllocationType::kOld);
1026 JSObject::ForceSetPrototype(isolate(), generator_function_prototype, empty);
1027
1028 InstallToStringTag(isolate(), generator_function_prototype,
1029 "GeneratorFunction");
1030 JSObject::AddProperty(isolate(), generator_function_prototype,
1031 factory()->prototype_string(),
1032 generator_object_prototype,
1033 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
1034
1035 JSObject::AddProperty(isolate(), generator_object_prototype,
1036 factory()->constructor_string(),
1037 generator_function_prototype,
1038 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
1039 InstallToStringTag(isolate(), generator_object_prototype, "Generator");
1040 SimpleInstallFunction(isolate(), generator_object_prototype, "next",
1041 Builtin::kGeneratorPrototypeNext, 1, kDontAdapt);
1042 SimpleInstallFunction(isolate(), generator_object_prototype, "return",
1043 Builtin::kGeneratorPrototypeReturn, 1, kDontAdapt);
1044 SimpleInstallFunction(isolate(), generator_object_prototype, "throw",
1045 Builtin::kGeneratorPrototypeThrow, 1, kDontAdapt);
1046
1047 // Internal version of generator_prototype_next, flagged as non-native such
1048 // that it doesn't show up in Error traces.
1049 DirectHandle<JSFunction> generator_next_internal =
1050 SimpleCreateFunction(isolate(), factory()->next_string(),
1051 Builtin::kGeneratorPrototypeNext, 1, kDontAdapt);
1052 generator_next_internal->shared()->set_native(false);
1053 native_context()->set_generator_next_internal(*generator_next_internal);
1054
1055 // Internal version of async module functions, flagged as non-native such
1056 // that they don't show up in Error traces.
1057 {
1058 DirectHandle<JSFunction> async_module_evaluate_internal =
1059 SimpleCreateFunction(isolate(), factory()->next_string(),
1060 Builtin::kAsyncModuleEvaluate, 1, kDontAdapt);
1061 async_module_evaluate_internal->shared()->set_native(false);
1062 native_context()->set_async_module_evaluate_internal(
1063 *async_module_evaluate_internal);
1064 }
1065
1066 // Create maps for generator functions and their prototypes. Store those
1067 // maps in the native context. The "prototype" property descriptor is
1068 // writable, non-enumerable, and non-configurable (as per ES6 draft
1069 // 04-14-15, section 25.2.4.3).
1070 // Generator functions do not have "caller" or "arguments" accessors.
1072 map = CreateNonConstructorMap(isolate(), isolate()->strict_function_map(),
1073 generator_function_prototype,
1074 "GeneratorFunction");
1075 native_context()->set_generator_function_map(*map);
1076
1077 map = CreateNonConstructorMap(
1078 isolate(), isolate()->strict_function_with_name_map(),
1079 generator_function_prototype, "GeneratorFunction with name");
1080 native_context()->set_generator_function_with_name_map(*map);
1081
1082 DirectHandle<JSFunction> object_function(native_context()->object_function(),
1083 isolate());
1084 DirectHandle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
1085 Map::SetPrototype(isolate(), generator_object_prototype_map,
1086 generator_object_prototype);
1087 native_context()->set_generator_object_prototype_map(
1088 *generator_object_prototype_map);
1089}
1090
1092 // %AsyncIteratorPrototype%
1093 // proposal-async-iteration/#sec-asynciteratorprototype
1094 DirectHandle<JSObject> async_iterator_prototype = factory()->NewJSObject(
1095 isolate()->object_function(), AllocationType::kOld);
1096
1097 InstallFunctionAtSymbol(
1098 isolate(), async_iterator_prototype, factory()->async_iterator_symbol(),
1099 "[Symbol.asyncIterator]", Builtin::kReturnReceiver, 0, kAdapt);
1100 native_context()->set_initial_async_iterator_prototype(
1101 *async_iterator_prototype);
1102
1103 // %AsyncFromSyncIteratorPrototype%
1104 // proposal-async-iteration/#sec-%asyncfromsynciteratorprototype%-object
1105 DirectHandle<JSObject> async_from_sync_iterator_prototype =
1106 factory()->NewJSObject(isolate()->object_function(),
1108 SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype, "next",
1109 Builtin::kAsyncFromSyncIteratorPrototypeNext, 1,
1110 kDontAdapt);
1111 SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype, "return",
1112 Builtin::kAsyncFromSyncIteratorPrototypeReturn, 1,
1113 kDontAdapt);
1114 SimpleInstallFunction(isolate(), async_from_sync_iterator_prototype, "throw",
1115 Builtin::kAsyncFromSyncIteratorPrototypeThrow, 1,
1116 kDontAdapt);
1117
1118 InstallToStringTag(isolate(), async_from_sync_iterator_prototype,
1119 "Async-from-Sync Iterator");
1120
1121 JSObject::ForceSetPrototype(isolate(), async_from_sync_iterator_prototype,
1122 async_iterator_prototype);
1123
1124 DirectHandle<Map> async_from_sync_iterator_map =
1126 JS_ASYNC_FROM_SYNC_ITERATOR_TYPE,
1127 JSAsyncFromSyncIterator::kHeaderSize);
1128 Map::SetPrototype(isolate(), async_from_sync_iterator_map,
1129 async_from_sync_iterator_prototype);
1130 native_context()->set_async_from_sync_iterator_map(
1131 *async_from_sync_iterator_map);
1132
1133 // Async Generators
1134 DirectHandle<JSObject> async_generator_object_prototype =
1135 factory()->NewJSObject(isolate()->object_function(),
1137 DirectHandle<JSObject> async_generator_function_prototype =
1138 factory()->NewJSObject(isolate()->object_function(),
1140
1141 // %AsyncGenerator% / %AsyncGeneratorFunction%.prototype
1142 JSObject::ForceSetPrototype(isolate(), async_generator_function_prototype,
1143 empty);
1144
1145 // The value of AsyncGeneratorFunction.prototype.prototype is the
1146 // %AsyncGeneratorPrototype% intrinsic object.
1147 // This property has the attributes
1148 // { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
1149 JSObject::AddProperty(isolate(), async_generator_function_prototype,
1150 factory()->prototype_string(),
1151 async_generator_object_prototype,
1152 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
1153 JSObject::AddProperty(isolate(), async_generator_object_prototype,
1154 factory()->constructor_string(),
1155 async_generator_function_prototype,
1156 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
1157 InstallToStringTag(isolate(), async_generator_function_prototype,
1158 "AsyncGeneratorFunction");
1159
1160 // %AsyncGeneratorPrototype%
1161 JSObject::ForceSetPrototype(isolate(), async_generator_object_prototype,
1162 async_iterator_prototype);
1163 native_context()->set_initial_async_generator_prototype(
1164 *async_generator_object_prototype);
1165
1166 InstallToStringTag(isolate(), async_generator_object_prototype,
1167 "AsyncGenerator");
1168 SimpleInstallFunction(isolate(), async_generator_object_prototype, "next",
1169 Builtin::kAsyncGeneratorPrototypeNext, 1, kDontAdapt);
1170 SimpleInstallFunction(isolate(), async_generator_object_prototype, "return",
1171 Builtin::kAsyncGeneratorPrototypeReturn, 1, kDontAdapt);
1172 SimpleInstallFunction(isolate(), async_generator_object_prototype, "throw",
1173 Builtin::kAsyncGeneratorPrototypeThrow, 1, kDontAdapt);
1174
1175 // Create maps for generator functions and their prototypes. Store those
1176 // maps in the native context. The "prototype" property descriptor is
1177 // writable, non-enumerable, and non-configurable (as per ES6 draft
1178 // 04-14-15, section 25.2.4.3).
1179 // Async Generator functions do not have "caller" or "arguments" accessors.
1181 map = CreateNonConstructorMap(isolate(), isolate()->strict_function_map(),
1182 async_generator_function_prototype,
1183 "AsyncGeneratorFunction");
1184 native_context()->set_async_generator_function_map(*map);
1185
1186 map = CreateNonConstructorMap(
1187 isolate(), isolate()->strict_function_with_name_map(),
1188 async_generator_function_prototype, "AsyncGeneratorFunction with name");
1189 native_context()->set_async_generator_function_with_name_map(*map);
1190
1191 DirectHandle<JSFunction> object_function(native_context()->object_function(),
1192 isolate());
1193 DirectHandle<Map> async_generator_object_prototype_map =
1194 Map::Create(isolate(), 0);
1195 Map::SetPrototype(isolate(), async_generator_object_prototype_map,
1196 async_generator_object_prototype);
1197 native_context()->set_async_generator_object_prototype_map(
1198 *async_generator_object_prototype_map);
1199}
1200
1202 // %AsyncFunctionPrototype% intrinsic
1203 DirectHandle<JSObject> async_function_prototype = factory()->NewJSObject(
1204 isolate()->object_function(), AllocationType::kOld);
1205 JSObject::ForceSetPrototype(isolate(), async_function_prototype, empty);
1206
1207 InstallToStringTag(isolate(), async_function_prototype, "AsyncFunction");
1208
1209 DirectHandle<Map> map =
1210 Map::Copy(isolate(), isolate()->strict_function_without_prototype_map(),
1211 "AsyncFunction");
1212 Map::SetPrototype(isolate(), map, async_function_prototype);
1213 native_context()->set_async_function_map(*map);
1214
1215 map = Map::Copy(isolate(), isolate()->method_with_name_map(),
1216 "AsyncFunction with name");
1217 Map::SetPrototype(isolate(), map, async_function_prototype);
1218 native_context()->set_async_function_with_name_map(*map);
1219}
1220
1222 // Allocate maps for all Proxy types.
1223 // Next to the default proxy, we need maps indicating callable and
1224 // constructable proxies.
1226 JS_PROXY_TYPE, JSProxy::kSize, TERMINAL_FAST_ELEMENTS_KIND);
1227 proxy_map->set_is_dictionary_map(true);
1228 proxy_map->set_may_have_interesting_properties(true);
1229 native_context()->set_proxy_map(*proxy_map);
1230 proxy_map->SetConstructor(native_context()->object_function());
1231
1232 DirectHandle<Map> proxy_callable_map =
1233 Map::Copy(isolate_, proxy_map, "callable Proxy");
1234 proxy_callable_map->set_is_callable(true);
1235 native_context()->set_proxy_callable_map(*proxy_callable_map);
1236 proxy_callable_map->SetConstructor(native_context()->function_function());
1237
1238 DirectHandle<Map> proxy_constructor_map =
1239 Map::Copy(isolate_, proxy_callable_map, "constructor Proxy");
1240 proxy_constructor_map->set_is_constructor(true);
1241 native_context()->set_proxy_constructor_map(*proxy_constructor_map);
1242
1243 {
1245 JS_OBJECT_TYPE, JSProxyRevocableResult::kSize,
1248
1249 { // proxy
1250 Descriptor d = Descriptor::DataField(isolate(), factory()->proxy_string(),
1253 map->AppendDescriptor(isolate(), &d);
1254 }
1255 { // revoke
1257 isolate(), factory()->revoke_string(),
1259 map->AppendDescriptor(isolate(), &d);
1260 }
1261
1262 Map::SetPrototype(isolate(), map, isolate()->initial_object_prototype());
1263 map->SetConstructor(native_context()->object_function());
1264
1265 native_context()->set_proxy_revocable_result_map(*map);
1266 }
1267}
1268
1269namespace {
1270void ReplaceAccessors(Isolate* isolate, DirectHandle<Map> map,
1272 DirectHandle<AccessorPair> accessor_pair) {
1273 Tagged<DescriptorArray> descriptors = map->instance_descriptors(isolate);
1274 InternalIndex entry = descriptors->SearchWithCache(isolate, *name, *map);
1275 Descriptor d = Descriptor::AccessorConstant(name, accessor_pair, attributes);
1276 descriptors->Replace(entry, &d);
1277}
1278
1279void InitializeJSArrayMaps(Isolate* isolate,
1280 DirectHandle<Context> native_context,
1281 DirectHandle<Map> initial_map) {
1282 // Replace all of the cached initial array maps in the native context with
1283 // the appropriate transitioned elements kind maps.
1284 DirectHandle<Map> current_map = initial_map;
1285 ElementsKind kind = current_map->elements_kind();
1289 Context::JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX);
1290 native_context->set(Context::ArrayMapIndex(kind), *current_map,
1293 i < kFastElementsKindCount; ++i) {
1294 DirectHandle<Map> new_map;
1296 Tagged<Map> maybe_elements_transition = current_map->ElementsTransitionMap(
1298 if (!maybe_elements_transition.is_null()) {
1299 new_map = direct_handle(maybe_elements_transition, isolate);
1300 } else {
1301 new_map = Map::CopyAsElementsKind(isolate, current_map, next_kind,
1303 }
1304 DCHECK_EQ(next_kind, new_map->elements_kind());
1305 native_context->set(Context::ArrayMapIndex(next_kind), *new_map,
1307 current_map = new_map;
1308 }
1309}
1310} // namespace
1311
1313 PropertyAttributes rw_attribs = static_cast<PropertyAttributes>(DONT_ENUM);
1316 accessors->set_getter(*thrower);
1317 accessors->set_setter(*thrower);
1318
1319 DirectHandle<Map> map(empty->map(), isolate());
1320 ReplaceAccessors(isolate(), map, factory()->arguments_string(), rw_attribs,
1321 accessors);
1322 ReplaceAccessors(isolate(), map, factory()->caller_string(), rw_attribs,
1323 accessors);
1324}
1325
1327 Tagged<Context> context) {
1328 DCHECK(IsNativeContext(context));
1329 Heap* heap = isolate->heap();
1330#ifdef DEBUG
1331 {
1332 DCHECK(IsUndefined(context->next_context_link(), isolate));
1333 // Check that context is not in the list yet.
1334 for (Tagged<Object> current = heap->native_contexts_list();
1335 !IsUndefined(current, isolate);
1336 current = Cast<Context>(current)->next_context_link()) {
1337 DCHECK(current != context);
1338 }
1339 }
1340#endif
1341 context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list(),
1343 heap->set_native_contexts_list(context);
1344}
1345
1347 // Allocate the native context FixedArray first and then patch the
1348 // closure and extension object later (we need the empty function
1349 // and the global object, but in order to create those, we need the
1350 // native context).
1352
1355}
1356
1358 DirectHandle<ScopeInfo> scope_info =
1359 isolate()->factory()->global_this_binding_scope_info();
1360 DirectHandle<Context> context =
1361 factory()->NewScriptContext(native_context(), scope_info);
1362
1363 // Go ahead and hook it up while we're at it.
1364 int slot = scope_info->ReceiverContextSlotIndex();
1366 context->set(slot, native_context()->global_proxy());
1367
1368 Handle<ScriptContextTable> script_contexts(
1369 native_context()->script_context_table(), isolate());
1370 DirectHandle<ScriptContextTable> new_script_contexts =
1371 ScriptContextTable::Add(isolate(), script_contexts, context, false);
1372 native_context()->set_script_context_table(*new_script_contexts);
1373}
1374
1376 v8::Local<v8::ObjectTemplate> global_proxy_template,
1377 DirectHandle<JSGlobalProxy> global_proxy) {
1378 // The argument global_proxy_template aka data is an ObjectTemplateInfo.
1379 // It has a constructor pointer that points at global_constructor which is a
1380 // FunctionTemplateInfo.
1381 // The global_proxy_constructor is used to (re)initialize the
1382 // global_proxy. The global_proxy_constructor also has a prototype_template
1383 // pointer that points at js_global_object_template which is an
1384 // ObjectTemplateInfo.
1385 // That in turn has a constructor pointer that points at
1386 // js_global_object_constructor which is a FunctionTemplateInfo.
1387 // js_global_object_constructor is used to make js_global_object_function
1388 // js_global_object_function is used to make the new global_object.
1389 //
1390 // --- G l o b a l ---
1391 // Step 1: Create a fresh JSGlobalObject.
1392 DirectHandle<JSFunction> js_global_object_function;
1393 DirectHandle<ObjectTemplateInfo> js_global_object_template;
1394 if (!global_proxy_template.IsEmpty()) {
1395 // Get prototype template of the global_proxy_template.
1397 v8::Utils::OpenDirectHandle(*global_proxy_template);
1398 DirectHandle<FunctionTemplateInfo> global_constructor(
1399 Cast<FunctionTemplateInfo>(data->constructor()), isolate());
1400 DirectHandle<Object> proto_template(
1401 global_constructor->GetPrototypeTemplate(), isolate());
1402 if (!IsUndefined(*proto_template, isolate())) {
1403 js_global_object_template = Cast<ObjectTemplateInfo>(proto_template);
1404 }
1405 }
1406
1407 if (js_global_object_template.is_null()) {
1408 DirectHandle<String> name = factory()->empty_string();
1409 DirectHandle<JSObject> prototype =
1410 factory()->NewFunctionPrototype(isolate()->object_function());
1411 js_global_object_function = CreateFunctionForBuiltinWithPrototype(
1412 isolate(), name, Builtin::kIllegal, prototype, JS_GLOBAL_OBJECT_TYPE,
1413 JSGlobalObject::kHeaderSize, 0, MUTABLE, 0, kDontAdapt);
1414#ifdef DEBUG
1415 LookupIterator it(isolate(), prototype, factory()->constructor_string(),
1417 DirectHandle<Object> value = Object::GetProperty(&it).ToHandleChecked();
1418 DCHECK(it.IsFound());
1419 DCHECK_EQ(*isolate()->object_function(), *value);
1420#endif
1421 } else {
1422 DirectHandle<FunctionTemplateInfo> js_global_object_constructor(
1423 Cast<FunctionTemplateInfo>(js_global_object_template->constructor()),
1424 isolate());
1425 js_global_object_function = ApiNatives::CreateApiFunction(
1426 isolate(), isolate()->native_context(), js_global_object_constructor,
1427 factory()->the_hole_value(), JS_GLOBAL_OBJECT_TYPE);
1428 }
1429
1430 js_global_object_function->initial_map()->set_is_prototype_map(true);
1431 js_global_object_function->initial_map()->set_is_dictionary_map(true);
1432 js_global_object_function->initial_map()->set_may_have_interesting_properties(
1433 true);
1434 DirectHandle<JSGlobalObject> global_object =
1435 factory()->NewJSGlobalObject(js_global_object_function);
1436
1437 // Step 2: (re)initialize the global proxy object.
1438 DirectHandle<JSFunction> global_proxy_function;
1439 if (global_proxy_template.IsEmpty()) {
1440 DirectHandle<String> name = factory()->empty_string();
1441 global_proxy_function = CreateFunctionForBuiltinWithPrototype(
1442 isolate(), name, Builtin::kIllegal, factory()->the_hole_value(),
1443 JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::SizeWithEmbedderFields(0), 0,
1444 MUTABLE, 0, kDontAdapt);
1445 } else {
1447 v8::Utils::OpenDirectHandle(*global_proxy_template);
1448 DirectHandle<FunctionTemplateInfo> global_constructor(
1449 Cast<FunctionTemplateInfo>(data->constructor()), isolate());
1450 global_proxy_function = ApiNatives::CreateApiFunction(
1451 isolate(), isolate()->native_context(), global_constructor,
1452 factory()->the_hole_value(), JS_GLOBAL_PROXY_TYPE);
1453 }
1454 global_proxy_function->initial_map()->set_is_access_check_needed(true);
1455 global_proxy_function->initial_map()->set_may_have_interesting_properties(
1456 true);
1457 native_context()->set_global_proxy_function(*global_proxy_function);
1458
1459 // Set the global object as the (hidden) __proto__ of the global proxy after
1460 // ConfigureGlobalObject
1461 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
1462
1463 // Set up the pointer back from the global object to the global proxy.
1464 global_object->set_global_proxy(*global_proxy);
1465 // Set the native context of the global proxy.
1466 global_proxy->map()->set_map(isolate(), native_context()->meta_map());
1467 // Set the global proxy of the native context. If the native context has been
1468 // deserialized, the global proxy is already correctly set up by the
1469 // deserializer. Otherwise it's undefined.
1470 DCHECK(IsUndefined(native_context()->get(Context::GLOBAL_PROXY_INDEX),
1471 isolate()) ||
1472 native_context()->global_proxy_object() == *global_proxy);
1473 native_context()->set_global_proxy_object(*global_proxy);
1474
1475 return global_object;
1476}
1477
1479 // Re-initialize the global proxy with the global proxy function from the
1480 // snapshot, and then set up the link to the native context.
1481 DirectHandle<JSFunction> global_proxy_function(
1482 native_context()->global_proxy_function(), isolate());
1483 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
1484 DirectHandle<JSObject> global_object(
1485 Cast<JSObject>(native_context()->global_object()), isolate());
1487 global_proxy->map()->set_map(isolate(), native_context()->meta_map());
1489}
1490
1492 DirectHandle<JSGlobalObject> global_object_from_snapshot(
1494 native_context()->set_extension(*global_object);
1495 native_context()->set_security_token(*global_object);
1496
1497 TransferNamedProperties(global_object_from_snapshot, global_object);
1498 if (global_object_from_snapshot->HasDictionaryElements()) {
1499 JSObject::NormalizeElements(global_object);
1500 }
1501 DCHECK_EQ(global_object_from_snapshot->GetElementsKind(),
1502 global_object->GetElementsKind());
1503 TransferIndexedProperties(global_object_from_snapshot, global_object);
1504}
1505
1506// See https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor for details
1507// about intrinsicDefaultProto concept. In short it's about using proper
1508// prototype object from constructor's realm when the constructor has
1509// non-instance prototype.
1511 DirectHandle<JSFunction> function,
1512 int context_index) {
1513 DirectHandle<Smi> index(Smi::FromInt(context_index), isolate);
1514 JSObject::AddProperty(isolate, function,
1515 isolate->factory()->native_context_index_symbol(),
1516 index, NONE);
1517 isolate->native_context()->set(context_index, *function, UPDATE_WRITE_BARRIER,
1519}
1520
1522 DirectHandle<String> name, int context_index,
1523 Builtin error_constructor, int error_function_length) {
1524 Factory* factory = isolate->factory();
1525
1526 // Most Error objects consist of a message, a stack trace, and possibly a
1527 // cause. Reserve three in-object properties for these.
1528 const int in_object_properties = 3;
1529 const int kErrorObjectSize =
1530 JSObject::kHeaderSize + in_object_properties * kTaggedSize;
1531 DirectHandle<JSFunction> error_fun =
1532 InstallFunction(isolate, global, name, JS_ERROR_TYPE, kErrorObjectSize,
1533 in_object_properties, factory->the_hole_value(),
1534 error_constructor, error_function_length, kDontAdapt);
1535
1536 if (context_index == Context::ERROR_FUNCTION_INDEX) {
1537 SimpleInstallFunction(isolate, error_fun, "captureStackTrace",
1538 Builtin::kErrorCaptureStackTrace, 2, kDontAdapt);
1539 }
1540
1541 InstallWithIntrinsicDefaultProto(isolate, error_fun, context_index);
1542
1543 {
1544 // Setup %XXXErrorPrototype%.
1546 Cast<JSObject>(error_fun->instance_prototype()), isolate);
1547
1548 JSObject::AddProperty(isolate, prototype, factory->name_string(), name,
1549 DONT_ENUM);
1550 JSObject::AddProperty(isolate, prototype, factory->message_string(),
1551 factory->empty_string(), DONT_ENUM);
1552
1553 if (context_index == Context::ERROR_FUNCTION_INDEX) {
1554 DirectHandle<JSFunction> to_string_fun =
1555 SimpleInstallFunction(isolate, prototype, "toString",
1556 Builtin::kErrorPrototypeToString, 0, kAdapt);
1557 isolate->native_context()->set_error_to_string(*to_string_fun);
1558 isolate->native_context()->set_initial_error_prototype(*prototype);
1559 } else {
1560 DirectHandle<JSFunction> global_error = isolate->error_function();
1561 CHECK(JSReceiver::SetPrototype(isolate, error_fun, global_error, false,
1563 .FromMaybe(false));
1565 isolate, prototype,
1566 direct_handle(global_error->prototype(), isolate), false,
1568 .FromMaybe(false));
1569 }
1570 }
1571
1572 DirectHandle<Map> initial_map(error_fun->initial_map(), isolate);
1573 Map::EnsureDescriptorSlack(isolate, initial_map, 3);
1574 const int kJSErrorErrorStackSymbolIndex = 0;
1575 const int kJSErrorErrorMessageSymbolIndex = 1;
1576
1577 { // error_stack_symbol
1578 Descriptor d = Descriptor::DataField(isolate, factory->error_stack_symbol(),
1579 kJSErrorErrorStackSymbolIndex,
1581 initial_map->AppendDescriptor(isolate, &d);
1582 }
1583 {
1584 // error_message_symbol
1586 isolate, factory->error_message_symbol(),
1587 kJSErrorErrorMessageSymbolIndex, DONT_ENUM, Representation::Tagged());
1588 initial_map->AppendDescriptor(isolate, &d);
1589 }
1590 { // stack
1591 DirectHandle<AccessorPair> new_pair = factory->NewAccessorPair();
1592 new_pair->set_getter(*factory->error_stack_getter_fun_template());
1593 new_pair->set_setter(*factory->error_stack_setter_fun_template());
1594
1595 Descriptor d = Descriptor::AccessorConstant(factory->stack_string(),
1596 new_pair, DONT_ENUM);
1597 initial_map->AppendDescriptor(isolate, &d);
1598 }
1599}
1600
1601namespace {
1602
1603Handle<JSObject> InitializeTemporal(Isolate* isolate) {
1604 DirectHandle<NativeContext> native_context = isolate->native_context();
1605
1606 // Already initialized?
1607 Handle<HeapObject> maybe_temporal(native_context->temporal_object(), isolate);
1608 if (IsJSObject(*maybe_temporal)) {
1609 return Cast<JSObject>(maybe_temporal);
1610 }
1611
1612 isolate->CountUsage(v8::Isolate::kTemporalObject);
1613
1614 // -- T e m p o r a l
1615 // #sec-temporal-objects
1616 Handle<JSObject> temporal = isolate->factory()->NewJSObject(
1617 isolate->object_function(), AllocationType::kOld);
1618
1619 // The initial value of the @@toStringTag property is the string value
1620 // *"Temporal"*.
1621 // https://github.com/tc39/proposal-temporal/issues/1539
1622 InstallToStringTag(isolate, temporal, "Temporal");
1623
1624 { // -- N o w
1625 // #sec-temporal-now-object
1626 DirectHandle<JSObject> now = isolate->factory()->NewJSObject(
1627 isolate->object_function(), AllocationType::kOld);
1628 JSObject::AddProperty(isolate, temporal, "Now", now, DONT_ENUM);
1629 InstallToStringTag(isolate, now, "Temporal.Now");
1630
1631 // Note: There are NO Temporal.Now.plainTime
1632 // See https://github.com/tc39/proposal-temporal/issues/1540
1633#define NOW_LIST(V) \
1634 V(timeZone, TimeZone, 0) \
1635 V(instant, Instant, 0) \
1636 V(plainDateTime, PlainDateTime, 1) \
1637 V(plainDateTimeISO, PlainDateTimeISO, 0) \
1638 V(zonedDateTime, ZonedDateTime, 1) \
1639 V(zonedDateTimeISO, ZonedDateTimeISO, 0) \
1640 V(plainDate, PlainDate, 1) \
1641 V(plainDateISO, PlainDateISO, 0) \
1642 V(plainTimeISO, PlainTimeISO, 0)
1643
1644#define INSTALL_NOW_FUNC(p, N, n) \
1645 SimpleInstallFunction(isolate, now, #p, Builtin::kTemporalNow##N, n, \
1646 kDontAdapt);
1647
1649#undef INSTALL_NOW_FUNC
1650#undef NOW_LIST
1651 }
1652#define INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(N, U, NUM_ARGS) \
1653 DirectHandle<JSFunction> obj_func = InstallFunction( \
1654 isolate, temporal, #N, JS_TEMPORAL_##U##_TYPE, \
1655 JSTemporal##N::kHeaderSize, 0, isolate->factory()->the_hole_value(), \
1656 Builtin::kTemporal##N##Constructor, NUM_ARGS, kDontAdapt); \
1657 InstallWithIntrinsicDefaultProto(isolate, obj_func, \
1658 Context::JS_TEMPORAL_##U##_FUNCTION_INDEX); \
1659 DirectHandle<JSObject> prototype( \
1660 Cast<JSObject>(obj_func->instance_prototype()), isolate); \
1661 InstallToStringTag(isolate, prototype, "Temporal." #N);
1662
1663#define INSTALL_TEMPORAL_FUNC(T, name, N, arg) \
1664 SimpleInstallFunction(isolate, obj_func, #name, Builtin::kTemporal##T##N, \
1665 arg, kDontAdapt);
1666
1667 { // -- P l a i n D a t e
1668 // #sec-temporal-plaindate-objects
1669 // #sec-temporal.plaindate
1670 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainDate, PLAIN_DATE, 3)
1671 INSTALL_TEMPORAL_FUNC(PlainDate, from, From, 1)
1672 INSTALL_TEMPORAL_FUNC(PlainDate, compare, Compare, 2)
1673
1674#ifdef V8_INTL_SUPPORT
1675#define PLAIN_DATE_GETTER_LIST_INTL(V) \
1676 V(era, Era) \
1677 V(eraYear, EraYear)
1678#else
1679#define PLAIN_DATE_GETTER_LIST_INTL(V)
1680#endif // V8_INTL_SUPPORT
1681
1682#define PLAIN_DATE_GETTER_LIST(V) \
1683 PLAIN_DATE_GETTER_LIST_INTL(V) \
1684 V(calendar, Calendar) \
1685 V(year, Year) \
1686 V(month, Month) \
1687 V(monthCode, MonthCode) \
1688 V(day, Day) \
1689 V(dayOfWeek, DayOfWeek) \
1690 V(dayOfYear, DayOfYear) \
1691 V(weekOfYear, WeekOfYear) \
1692 V(daysInWeek, DaysInWeek) \
1693 V(daysInMonth, DaysInMonth) \
1694 V(daysInYear, DaysInYear) \
1695 V(monthsInYear, MonthsInYear) \
1696 V(inLeapYear, InLeapYear)
1697
1698#define INSTALL_PLAIN_DATE_GETTER_FUNC(p, N) \
1699 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
1700 Builtin::kTemporalPlainDatePrototype##N, kAdapt);
1701
1703#undef PLAIN_DATE_GETTER_LIST
1704#undef PLAIN_DATE_GETTER_LIST_INTL
1705#undef INSTALL_PLAIN_DATE_GETTER_FUNC
1706
1707#define PLAIN_DATE_FUNC_LIST(V) \
1708 V(toPlainYearMonth, ToPlainYearMonth, 0) \
1709 V(toPlainMonthDay, ToPlainMonthDay, 0) \
1710 V(getISOFiels, GetISOFields, 0) \
1711 V(add, Add, 1) \
1712 V(subtract, Subtract, 1) \
1713 V(with, With, 1) \
1714 V(withCalendar, WithCalendar, 1) \
1715 V(until, Until, 1) \
1716 V(since, Since, 1) \
1717 V(equals, Equals, 1) \
1718 V(getISOFields, GetISOFields, 0) \
1719 V(toLocaleString, ToLocaleString, 0) \
1720 V(toPlainDateTime, ToPlainDateTime, 0) \
1721 V(toZonedDateTime, ToZonedDateTime, 1) \
1722 V(toString, ToString, 0) \
1723 V(toJSON, ToJSON, 0) \
1724 V(valueOf, ValueOf, 0)
1725
1726#define INSTALL_PLAIN_DATE_FUNC(p, N, min) \
1727 SimpleInstallFunction(isolate, prototype, #p, \
1728 Builtin::kTemporalPlainDatePrototype##N, min, \
1729 kDontAdapt);
1731#undef PLAIN_DATE_FUNC_LIST
1732#undef INSTALL_PLAIN_DATE_FUNC
1733 }
1734 { // -- P l a i n T i m e
1735 // #sec-temporal-plaintime-objects
1736 // #sec-temporal.plaintime
1737 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainTime, PLAIN_TIME, 0)
1738 INSTALL_TEMPORAL_FUNC(PlainTime, from, From, 1)
1739 INSTALL_TEMPORAL_FUNC(PlainTime, compare, Compare, 2)
1740
1741#define PLAIN_TIME_GETTER_LIST(V) \
1742 V(calendar, Calendar) \
1743 V(hour, Hour) \
1744 V(minute, Minute) \
1745 V(second, Second) \
1746 V(millisecond, Millisecond) \
1747 V(microsecond, Microsecond) \
1748 V(nanosecond, Nanosecond)
1749
1750#define INSTALL_PLAIN_TIME_GETTER_FUNC(p, N) \
1751 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
1752 Builtin::kTemporalPlainTimePrototype##N, kAdapt);
1753
1755#undef PLAIN_TIME_GETTER_LIST
1756#undef INSTALL_PLAIN_TIME_GETTER_FUNC
1757
1758#define PLAIN_TIME_FUNC_LIST(V) \
1759 V(add, Add, 1) \
1760 V(subtract, Subtract, 1) \
1761 V(with, With, 1) \
1762 V(until, Until, 1) \
1763 V(since, Since, 1) \
1764 V(round, Round, 1) \
1765 V(equals, Equals, 1) \
1766 V(toPlainDateTime, ToPlainDateTime, 1) \
1767 V(toZonedDateTime, ToZonedDateTime, 1) \
1768 V(getISOFields, GetISOFields, 0) \
1769 V(toLocaleString, ToLocaleString, 0) \
1770 V(toString, ToString, 0) \
1771 V(toJSON, ToJSON, 0) \
1772 V(valueOf, ValueOf, 0)
1773
1774#define INSTALL_PLAIN_TIME_FUNC(p, N, min) \
1775 SimpleInstallFunction(isolate, prototype, #p, \
1776 Builtin::kTemporalPlainTimePrototype##N, min, \
1777 kDontAdapt);
1779#undef PLAIN_TIME_FUNC_LIST
1780#undef INSTALL_PLAIN_TIME_FUNC
1781 }
1782 { // -- P l a i n D a t e T i m e
1783 // #sec-temporal-plaindatetime-objects
1784 // #sec-temporal.plaindatetime
1785 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainDateTime, PLAIN_DATE_TIME, 3)
1786 INSTALL_TEMPORAL_FUNC(PlainDateTime, from, From, 1)
1787 INSTALL_TEMPORAL_FUNC(PlainDateTime, compare, Compare, 2)
1788
1789#ifdef V8_INTL_SUPPORT
1790#define PLAIN_DATE_TIME_GETTER_LIST_INTL(V) \
1791 V(era, Era) \
1792 V(eraYear, EraYear)
1793#else
1794#define PLAIN_DATE_TIME_GETTER_LIST_INTL(V)
1795#endif // V8_INTL_SUPPORT
1796
1797#define PLAIN_DATE_TIME_GETTER_LIST(V) \
1798 PLAIN_DATE_TIME_GETTER_LIST_INTL(V) \
1799 V(calendar, Calendar) \
1800 V(year, Year) \
1801 V(month, Month) \
1802 V(monthCode, MonthCode) \
1803 V(day, Day) \
1804 V(hour, Hour) \
1805 V(minute, Minute) \
1806 V(second, Second) \
1807 V(millisecond, Millisecond) \
1808 V(microsecond, Microsecond) \
1809 V(nanosecond, Nanosecond) \
1810 V(dayOfWeek, DayOfWeek) \
1811 V(dayOfYear, DayOfYear) \
1812 V(weekOfYear, WeekOfYear) \
1813 V(daysInWeek, DaysInWeek) \
1814 V(daysInMonth, DaysInMonth) \
1815 V(daysInYear, DaysInYear) \
1816 V(monthsInYear, MonthsInYear) \
1817 V(inLeapYear, InLeapYear)
1818
1819#define INSTALL_PLAIN_DATE_TIME_GETTER_FUNC(p, N) \
1820 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
1821 Builtin::kTemporalPlainDateTimePrototype##N, kAdapt);
1822
1824#undef PLAIN_DATE_TIME_GETTER_LIST
1825#undef PLAIN_DATE_TIME_GETTER_LIST_INTL
1826#undef INSTALL_PLAIN_DATE_TIME_GETTER_FUNC
1827
1828#define PLAIN_DATE_TIME_FUNC_LIST(V) \
1829 V(with, With, 1) \
1830 V(withPlainTime, WithPlainTime, 0) \
1831 V(withPlainDate, WithPlainDate, 1) \
1832 V(withCalendar, WithCalendar, 1) \
1833 V(add, Add, 1) \
1834 V(subtract, Subtract, 1) \
1835 V(until, Until, 1) \
1836 V(since, Since, 1) \
1837 V(round, Round, 1) \
1838 V(equals, Equals, 1) \
1839 V(toLocaleString, ToLocaleString, 0) \
1840 V(toJSON, ToJSON, 0) \
1841 V(toString, ToString, 0) \
1842 V(valueOf, ValueOf, 0) \
1843 V(toZonedDateTime, ToZonedDateTime, 1) \
1844 V(toPlainDate, ToPlainDate, 0) \
1845 V(toPlainYearMonth, ToPlainYearMonth, 0) \
1846 V(toPlainMonthDay, ToPlainMonthDay, 0) \
1847 V(toPlainTime, ToPlainTime, 0) \
1848 V(getISOFields, GetISOFields, 0)
1849
1850#define INSTALL_PLAIN_DATE_TIME_FUNC(p, N, min) \
1851 SimpleInstallFunction(isolate, prototype, #p, \
1852 Builtin::kTemporalPlainDateTimePrototype##N, min, \
1853 kDontAdapt);
1855#undef PLAIN_DATE_TIME_FUNC_LIST
1856#undef INSTALL_PLAIN_DATE_TIME_FUNC
1857 }
1858 { // -- Z o n e d D a t e T i m e
1859 // #sec-temporal-zoneddatetime-objects
1860 // #sec-temporal.zoneddatetime
1861 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(ZonedDateTime, ZONED_DATE_TIME, 2)
1862 INSTALL_TEMPORAL_FUNC(ZonedDateTime, from, From, 1)
1863 INSTALL_TEMPORAL_FUNC(ZonedDateTime, compare, Compare, 2)
1864
1865#ifdef V8_INTL_SUPPORT
1866#define ZONED_DATE_TIME_GETTER_LIST_INTL(V) \
1867 V(era, Era) \
1868 V(eraYear, EraYear)
1869#else
1870#define ZONED_DATE_TIME_GETTER_LIST_INTL(V)
1871#endif // V8_INTL_SUPPORT
1872
1873#define ZONED_DATE_TIME_GETTER_LIST(V) \
1874 ZONED_DATE_TIME_GETTER_LIST_INTL(V) \
1875 V(calendar, Calendar) \
1876 V(timeZone, TimeZone) \
1877 V(year, Year) \
1878 V(month, Month) \
1879 V(monthCode, MonthCode) \
1880 V(day, Day) \
1881 V(hour, Hour) \
1882 V(minute, Minute) \
1883 V(second, Second) \
1884 V(millisecond, Millisecond) \
1885 V(microsecond, Microsecond) \
1886 V(nanosecond, Nanosecond) \
1887 V(epochSeconds, EpochSeconds) \
1888 V(epochMilliseconds, EpochMilliseconds) \
1889 V(epochMicroseconds, EpochMicroseconds) \
1890 V(epochNanoseconds, EpochNanoseconds) \
1891 V(dayOfWeek, DayOfWeek) \
1892 V(dayOfYear, DayOfYear) \
1893 V(weekOfYear, WeekOfYear) \
1894 V(hoursInDay, HoursInDay) \
1895 V(daysInWeek, DaysInWeek) \
1896 V(daysInMonth, DaysInMonth) \
1897 V(daysInYear, DaysInYear) \
1898 V(monthsInYear, MonthsInYear) \
1899 V(inLeapYear, InLeapYear) \
1900 V(offsetNanoseconds, OffsetNanoseconds) \
1901 V(offset, Offset)
1902
1903#define INSTALL_ZONED_DATE_TIME_GETTER_FUNC(p, N) \
1904 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
1905 Builtin::kTemporalZonedDateTimePrototype##N, kAdapt);
1906
1908#undef ZONED_DATE_TIME_GETTER_LIST
1909#undef ZONED_DATE_TIME_GETTER_LIST_INTL
1910#undef INSTALL_ZONED_DATE_TIME_GETTER_FUNC
1911
1912#define ZONED_DATE_TIME_FUNC_LIST(V) \
1913 V(with, With, 1) \
1914 V(withPlainTime, WithPlainTime, 0) \
1915 V(withPlainDate, WithPlainDate, 1) \
1916 V(withTimeZone, WithTimeZone, 1) \
1917 V(withCalendar, WithCalendar, 1) \
1918 V(add, Add, 1) \
1919 V(subtract, Subtract, 1) \
1920 V(until, Until, 1) \
1921 V(since, Since, 1) \
1922 V(round, Round, 1) \
1923 V(equals, Equals, 1) \
1924 V(toLocaleString, ToLocaleString, 0) \
1925 V(toString, ToString, 0) \
1926 V(toJSON, ToJSON, 0) \
1927 V(valueOf, ValueOf, 0) \
1928 V(startOfDay, StartOfDay, 0) \
1929 V(toInstant, ToInstant, 0) \
1930 V(toPlainDate, ToPlainDate, 0) \
1931 V(toPlainTime, ToPlainTime, 0) \
1932 V(toPlainDateTime, ToPlainDateTime, 0) \
1933 V(toPlainYearMonth, ToPlainYearMonth, 0) \
1934 V(toPlainMonthDay, ToPlainMonthDay, 0) \
1935 V(getISOFields, GetISOFields, 0)
1936
1937#define INSTALL_ZONED_DATE_TIME_FUNC(p, N, min) \
1938 SimpleInstallFunction(isolate, prototype, #p, \
1939 Builtin::kTemporalZonedDateTimePrototype##N, min, \
1940 kDontAdapt);
1942#undef ZONED_DATE_TIME_FUNC_LIST
1943#undef INSTALL_ZONED_DATE_TIME_FUNC
1944 }
1945 { // -- D u r a t i o n
1946 // #sec-temporal-duration-objects
1947 // #sec-temporal.duration
1948 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(Duration, DURATION, 0)
1949 INSTALL_TEMPORAL_FUNC(Duration, from, From, 1)
1951
1952#define DURATION_GETTER_LIST(V) \
1953 V(years, Years) \
1954 V(months, Months) \
1955 V(weeks, Weeks) \
1956 V(days, Days) \
1957 V(hours, Hours) \
1958 V(minutes, Minutes) \
1959 V(seconds, Seconds) \
1960 V(milliseconds, Milliseconds) \
1961 V(microseconds, Microseconds) \
1962 V(nanoseconds, Nanoseconds) \
1963 V(sign, Sign) \
1964 V(blank, Blank)
1965
1966#define INSTALL_DURATION_GETTER_FUNC(p, N) \
1967 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
1968 Builtin::kTemporalDurationPrototype##N, kAdapt);
1969
1971#undef DURATION_GETTER_LIST
1972#undef INSTALL_DURATION_GETTER_FUNC
1973
1974#define DURATION_FUNC_LIST(V) \
1975 V(with, With, 1) \
1976 V(negated, Negated, 0) \
1977 V(abs, Abs, 0) \
1978 V(add, Add, 1) \
1979 V(subtract, Subtract, 1) \
1980 V(round, Round, 1) \
1981 V(total, Total, 1) \
1982 V(toLocaleString, ToLocaleString, 0) \
1983 V(toString, ToString, 0) \
1984 V(toJSON, ToJSON, 0) \
1985 V(valueOf, ValueOf, 0)
1986
1987#define INSTALL_DURATION_FUNC(p, N, min) \
1988 SimpleInstallFunction(isolate, prototype, #p, \
1989 Builtin::kTemporalDurationPrototype##N, min, \
1990 kDontAdapt);
1992#undef DURATION_FUNC_LIST
1993#undef INSTALL_DURATION_FUNC
1994 }
1995 { // -- I n s t a n t
1996 // #sec-temporal-instant-objects
1997 // #sec-temporal.instant
1998 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(Instant, INSTANT, 1)
1999 INSTALL_TEMPORAL_FUNC(Instant, from, From, 1)
2001 INSTALL_TEMPORAL_FUNC(Instant, fromEpochSeconds, FromEpochSeconds, 1)
2002 INSTALL_TEMPORAL_FUNC(Instant, fromEpochMilliseconds, FromEpochMilliseconds,
2003 1)
2004 INSTALL_TEMPORAL_FUNC(Instant, fromEpochMicroseconds, FromEpochMicroseconds,
2005 1)
2006 INSTALL_TEMPORAL_FUNC(Instant, fromEpochNanoseconds, FromEpochNanoseconds,
2007 1)
2008
2009#define INSTANT_GETTER_LIST(V) \
2010 V(epochSeconds, EpochSeconds) \
2011 V(epochMilliseconds, EpochMilliseconds) \
2012 V(epochMicroseconds, EpochMicroseconds) \
2013 V(epochNanoseconds, EpochNanoseconds)
2014
2015#define INSTALL_INSTANT_GETTER_FUNC(p, N) \
2016 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
2017 Builtin::kTemporalInstantPrototype##N, kAdapt);
2018
2020#undef INSTANT_GETTER_LIST
2021#undef INSTALL_INSTANT_GETTER_FUNC
2022
2023#define INSTANT_FUNC_LIST(V) \
2024 V(add, Add, 1) \
2025 V(subtract, Subtract, 1) \
2026 V(until, Until, 1) \
2027 V(since, Since, 1) \
2028 V(round, Round, 1) \
2029 V(equals, Equals, 1) \
2030 V(toLocaleString, ToLocaleString, 0) \
2031 V(toString, ToString, 0) \
2032 V(toJSON, ToJSON, 0) \
2033 V(valueOf, ValueOf, 0) \
2034 V(toZonedDateTime, ToZonedDateTime, 1) \
2035 V(toZonedDateTimeISO, ToZonedDateTimeISO, 1)
2036
2037#define INSTALL_INSTANT_FUNC(p, N, min) \
2038 SimpleInstallFunction(isolate, prototype, #p, \
2039 Builtin::kTemporalInstantPrototype##N, min, \
2040 kDontAdapt);
2042#undef INSTANT_FUNC_LIST
2043#undef INSTALL_INSTANT_FUNC
2044 }
2045 { // -- P l a i n Y e a r M o n t h
2046 // #sec-temporal-plainyearmonth-objects
2047 // #sec-temporal.plainyearmonth
2048 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainYearMonth, PLAIN_YEAR_MONTH, 2)
2049 INSTALL_TEMPORAL_FUNC(PlainYearMonth, from, From, 1)
2050 INSTALL_TEMPORAL_FUNC(PlainYearMonth, compare, Compare, 2)
2051
2052#ifdef V8_INTL_SUPPORT
2053#define PLAIN_YEAR_MONTH_GETTER_LIST_INTL(V) \
2054 V(era, Era) \
2055 V(eraYear, EraYear)
2056#else
2057#define PLAIN_YEAR_MONTH_GETTER_LIST_INTL(V)
2058#endif // V8_INTL_SUPPORT
2059
2060#define PLAIN_YEAR_MONTH_GETTER_LIST(V) \
2061 PLAIN_YEAR_MONTH_GETTER_LIST_INTL(V) \
2062 V(calendar, Calendar) \
2063 V(year, Year) \
2064 V(month, Month) \
2065 V(monthCode, MonthCode) \
2066 V(daysInYear, DaysInYear) \
2067 V(daysInMonth, DaysInMonth) \
2068 V(monthsInYear, MonthsInYear) \
2069 V(inLeapYear, InLeapYear)
2070
2071#define INSTALL_PLAIN_YEAR_MONTH_GETTER_FUNC(p, N) \
2072 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
2073 Builtin::kTemporalPlainYearMonthPrototype##N, kAdapt);
2074
2076#undef PLAIN_YEAR_MONTH_GETTER_LIST
2077#undef PLAIN_YEAR_MONTH_GETTER_LIST_INTL
2078#undef INSTALL_PLAIN_YEAR_MONTH_GETTER_FUNC
2079
2080#define PLAIN_YEAR_MONTH_FUNC_LIST(V) \
2081 V(with, With, 1) \
2082 V(add, Add, 1) \
2083 V(subtract, Subtract, 1) \
2084 V(until, Until, 1) \
2085 V(since, Since, 1) \
2086 V(equals, Equals, 1) \
2087 V(toLocaleString, ToLocaleString, 0) \
2088 V(toString, ToString, 0) \
2089 V(toJSON, ToJSON, 0) \
2090 V(valueOf, ValueOf, 0) \
2091 V(toPlainDate, ToPlainDate, 1) \
2092 V(getISOFields, GetISOFields, 0)
2093
2094#define INSTALL_PLAIN_YEAR_MONTH_FUNC(p, N, min) \
2095 SimpleInstallFunction(isolate, prototype, #p, \
2096 Builtin::kTemporalPlainYearMonthPrototype##N, min, \
2097 kDontAdapt);
2099#undef PLAIN_YEAR_MONTH_FUNC_LIST
2100#undef INSTALL_PLAIN_YEAR_MONTH_FUNC
2101 }
2102 { // -- P l a i n M o n t h D a y
2103 // #sec-temporal-plainmonthday-objects
2104 // #sec-temporal.plainmonthday
2105 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(PlainMonthDay, PLAIN_MONTH_DAY, 2)
2106 INSTALL_TEMPORAL_FUNC(PlainMonthDay, from, From, 1)
2107 // Notice there are no Temporal.PlainMonthDay.compare in the spec.
2108
2109#define PLAIN_MONTH_DAY_GETTER_LIST(V) \
2110 V(calendar, Calendar) \
2111 V(monthCode, MonthCode) \
2112 V(day, Day)
2113
2114#define INSTALL_PLAIN_MONTH_DAY_GETTER_FUNC(p, N) \
2115 SimpleInstallGetter(isolate, prototype, isolate->factory()->p##_string(), \
2116 Builtin::kTemporalPlainMonthDayPrototype##N, kAdapt);
2117
2119#undef PLAIN_MONTH_DAY_GETTER_LIST
2120#undef INSTALL_PLAIN_MONTH_DAY_GETTER_FUNC
2121
2122#define PLAIN_MONTH_DAY_FUNC_LIST(V) \
2123 V(with, With, 1) \
2124 V(equals, Equals, 1) \
2125 V(toLocaleString, ToLocaleString, 0) \
2126 V(toString, ToString, 0) \
2127 V(toJSON, ToJSON, 0) \
2128 V(valueOf, ValueOf, 0) \
2129 V(toPlainDate, ToPlainDate, 1) \
2130 V(getISOFields, GetISOFields, 0)
2131
2132#define INSTALL_PLAIN_MONTH_DAY_FUNC(p, N, min) \
2133 SimpleInstallFunction(isolate, prototype, #p, \
2134 Builtin::kTemporalPlainMonthDayPrototype##N, min, \
2135 kDontAdapt);
2137#undef PLAIN_MONTH_DAY_FUNC_LIST
2138#undef INSTALL_PLAIN_MONTH_DAY_FUNC
2139 }
2140 { // -- T i m e Z o n e
2141 // #sec-temporal-timezone-objects
2142 // #sec-temporal.timezone
2143 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(TimeZone, TIME_ZONE, 1)
2144 INSTALL_TEMPORAL_FUNC(TimeZone, from, From, 1)
2145
2146 // #sec-get-temporal.timezone.prototype.id
2147 SimpleInstallGetter(isolate, prototype, isolate->factory()->id_string(),
2148 Builtin::kTemporalTimeZonePrototypeId, kAdapt);
2149
2150#define TIME_ZONE_FUNC_LIST(V) \
2151 V(getOffsetNanosecondsFor, GetOffsetNanosecondsFor, 1) \
2152 V(getOffsetStringFor, GetOffsetStringFor, 1) \
2153 V(getPlainDateTimeFor, GetPlainDateTimeFor, 1) \
2154 V(getInstantFor, GetInstantFor, 1) \
2155 V(getPossibleInstantsFor, GetPossibleInstantsFor, 1) \
2156 V(getNextTransition, GetNextTransition, 1) \
2157 V(getPreviousTransition, GetPreviousTransition, 1) \
2158 V(toString, ToString, 0) \
2159 V(toJSON, ToJSON, 0)
2160
2161#define INSTALL_TIME_ZONE_FUNC(p, N, min) \
2162 SimpleInstallFunction(isolate, prototype, #p, \
2163 Builtin::kTemporalTimeZonePrototype##N, min, \
2164 kDontAdapt);
2166#undef TIME_ZONE_FUNC_LIST
2167#undef INSTALL_TIME_ZONE_FUNC
2168 }
2169 { // -- C a l e n d a r
2170 // #sec-temporal-calendar-objects
2171 // #sec-temporal.calendar
2172 INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(Calendar, CALENDAR, 1)
2173 INSTALL_TEMPORAL_FUNC(Calendar, from, From, 1)
2174
2175 // #sec-get-temporal.calendar.prototype.id
2176 SimpleInstallGetter(isolate, prototype, isolate->factory()->id_string(),
2177 Builtin::kTemporalCalendarPrototypeId, kAdapt);
2178
2179#ifdef V8_INTL_SUPPORT
2180#define CALENDAR_FUNC_LIST_INTL(V) \
2181 V(era, Era, 1, kDontAdapt) \
2182 V(eraYear, EraYear, 1, kDontAdapt)
2183#else
2184#define CALENDAR_FUNC_LIST_INTL(V)
2185#endif // V8_INTL_SUPPORT
2186
2187#define CALENDAR_FUNC_LIST(V) \
2188 CALENDAR_FUNC_LIST_INTL(V) \
2189 V(dateFromFields, DateFromFields, 1, kDontAdapt) \
2190 V(yearMonthFromFields, YearMonthFromFields, 1, kDontAdapt) \
2191 V(monthDayFromFields, MonthDayFromFields, 1, kDontAdapt) \
2192 V(dateAdd, DateAdd, 2, kDontAdapt) \
2193 V(dateUntil, DateUntil, 2, kDontAdapt) \
2194 V(year, Year, 1, kDontAdapt) \
2195 V(month, Month, 1, kDontAdapt) \
2196 V(monthCode, MonthCode, 1, kDontAdapt) \
2197 V(day, Day, 1, kDontAdapt) \
2198 V(dayOfWeek, DayOfWeek, 1, kDontAdapt) \
2199 V(dayOfYear, DayOfYear, 1, kDontAdapt) \
2200 V(weekOfYear, WeekOfYear, 1, kDontAdapt) \
2201 V(daysInWeek, DaysInWeek, 1, kDontAdapt) \
2202 V(daysInMonth, DaysInMonth, 1, kDontAdapt) \
2203 V(daysInYear, DaysInYear, 1, kDontAdapt) \
2204 V(monthsInYear, MonthsInYear, 1, kDontAdapt) \
2205 V(inLeapYear, InLeapYear, 1, kDontAdapt) \
2206 V(fields, Fields, 1, kAdapt) \
2207 V(mergeFields, MergeFields, 2, kDontAdapt) \
2208 V(toString, ToString, 0, kDontAdapt) \
2209 V(toJSON, ToJSON, 0, kDontAdapt)
2210
2211#define INSTALL_CALENDAR_FUNC(p, N, min, adapt) \
2212 SimpleInstallFunction(isolate, prototype, #p, \
2213 Builtin::kTemporalCalendarPrototype##N, min, adapt);
2215#undef CALENDAR_FUNC_LIST
2216#undef CALENDAR_FUNC_LIST_INTL
2217#undef INSTALL_CALENDAE_FUNC
2218 }
2219#undef INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE
2220#undef INSTALL_TEMPORAL_FUNC
2221
2222 // The StringListFromIterable functions is created but not
2223 // exposed, as it is used internally by CalendarFields.
2224 {
2225 DirectHandle<JSFunction> func =
2226 SimpleCreateFunction(isolate,
2227 isolate->factory()->InternalizeUtf8String(
2228 "StringFixedArrayFromIterable"),
2229 Builtin::kStringFixedArrayFromIterable, 1, kAdapt);
2230 native_context->set_string_fixed_array_from_iterable(*func);
2231 }
2232 // The TemporalInsantFixedArrayFromIterable functions is created but not
2233 // exposed, as it is used internally by GetPossibleInstantsFor.
2234 {
2235 DirectHandle<JSFunction> func = SimpleCreateFunction(
2236 isolate,
2237 isolate->factory()->InternalizeUtf8String(
2238 "TemporalInstantFixedArrayFromIterable"),
2239 Builtin::kTemporalInstantFixedArrayFromIterable, 1, kAdapt);
2240 native_context->set_temporal_instant_fixed_array_from_iterable(*func);
2241 }
2242
2243 native_context->set_temporal_object(*temporal);
2244 return temporal;
2245}
2246
2247void LazyInitializeDateToTemporalInstant(
2249 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
2250 InitializeTemporal(isolate);
2251 DirectHandle<JSFunction> function = SimpleCreateFunction(
2252 isolate, isolate->factory()->InternalizeUtf8String("toTemporalInstant"),
2253 Builtin::kDatePrototypeToTemporalInstant, 0, kDontAdapt);
2254 info.GetReturnValue().Set(v8::Utils::ToLocal(function));
2255}
2256
2257void LazyInitializeGlobalThisTemporal(
2259 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
2260 DirectHandle<JSObject> temporal = InitializeTemporal(isolate);
2261 info.GetReturnValue().Set(v8::Utils::ToLocal(temporal));
2262}
2263
2264} // namespace
2265
2266// This is only called if we are not using snapshots. The equivalent
2267// work in the snapshot case is done in HookUpGlobalObject.
2269 DirectHandle<JSFunction> empty_function) {
2270 // --- N a t i v e C o n t e x t ---
2271 // Set extension and global object.
2272 native_context()->set_extension(*global_object);
2273 // Security setup: Set the security token of the native context to the global
2274 // object. This makes the security check between two different contexts fail
2275 // by default even in case of global object reinitialization.
2276 native_context()->set_security_token(*global_object);
2277
2279
2280 { // -- C o n t e x t
2281 DirectHandle<Map> meta_map(native_context()->meta_map(), isolate());
2282
2284 meta_map, FUNCTION_CONTEXT_TYPE, kVariableSizeSentinel);
2285 map->set_native_context(*native_context());
2286 native_context()->set_function_context_map(*map);
2287
2288 map = factory->NewMapWithMetaMap(meta_map, CATCH_CONTEXT_TYPE,
2290 map->set_native_context(*native_context());
2291 native_context()->set_catch_context_map(*map);
2292
2293 map = factory->NewMapWithMetaMap(meta_map, WITH_CONTEXT_TYPE,
2295 map->set_native_context(*native_context());
2296 native_context()->set_with_context_map(*map);
2297
2298 map = factory->NewMapWithMetaMap(meta_map, DEBUG_EVALUATE_CONTEXT_TYPE,
2300 map->set_native_context(*native_context());
2301 native_context()->set_debug_evaluate_context_map(*map);
2302
2303 map = factory->NewMapWithMetaMap(meta_map, BLOCK_CONTEXT_TYPE,
2305 map->set_native_context(*native_context());
2306 native_context()->set_block_context_map(*map);
2307
2308 map = factory->NewMapWithMetaMap(meta_map, MODULE_CONTEXT_TYPE,
2310 map->set_native_context(*native_context());
2311 native_context()->set_module_context_map(*map);
2312
2313 map = factory->NewMapWithMetaMap(meta_map, AWAIT_CONTEXT_TYPE,
2315 map->set_native_context(*native_context());
2316 native_context()->set_await_context_map(*map);
2317
2318 map = factory->NewMapWithMetaMap(meta_map, SCRIPT_CONTEXT_TYPE,
2320 map->set_native_context(*native_context());
2321 native_context()->set_script_context_map(*map);
2322
2323 map = factory->NewMapWithMetaMap(meta_map, EVAL_CONTEXT_TYPE,
2325 map->set_native_context(*native_context());
2326 native_context()->set_eval_context_map(*map);
2327
2328 DirectHandle<ScriptContextTable> script_context_table =
2330 native_context()->set_script_context_table(*script_context_table);
2332 }
2333
2334 { // --- O b j e c t ---
2335 DirectHandle<String> object_name = factory->Object_string();
2336 DirectHandle<JSFunction> object_function = isolate_->object_function();
2337 JSObject::AddProperty(isolate_, global_object, object_name, object_function,
2338 DONT_ENUM);
2339
2340 SimpleInstallFunction(isolate_, object_function, "assign",
2341 Builtin::kObjectAssign, 2, kDontAdapt);
2342 SimpleInstallFunction(isolate_, object_function, "getOwnPropertyDescriptor",
2343 Builtin::kObjectGetOwnPropertyDescriptor, 2,
2344 kDontAdapt);
2346 isolate_, object_function, "getOwnPropertyDescriptors",
2347 Builtin::kObjectGetOwnPropertyDescriptors, 1, kDontAdapt);
2348 SimpleInstallFunction(isolate_, object_function, "getOwnPropertyNames",
2349 Builtin::kObjectGetOwnPropertyNames, 1, kAdapt);
2350 SimpleInstallFunction(isolate_, object_function, "getOwnPropertySymbols",
2351 Builtin::kObjectGetOwnPropertySymbols, 1, kDontAdapt);
2352 SimpleInstallFunction(isolate_, object_function, "hasOwn",
2353 Builtin::kObjectHasOwn, 2, kAdapt);
2354 SimpleInstallFunction(isolate_, object_function, "is", Builtin::kObjectIs,
2355 2, kAdapt);
2356 SimpleInstallFunction(isolate_, object_function, "preventExtensions",
2357 Builtin::kObjectPreventExtensions, 1, kAdapt);
2358 SimpleInstallFunction(isolate_, object_function, "seal",
2359 Builtin::kObjectSeal, 1, kDontAdapt);
2360
2361 SimpleInstallFunction(isolate_, object_function, "create",
2362 Builtin::kObjectCreate, 2, kDontAdapt);
2363
2364 SimpleInstallFunction(isolate_, object_function, "defineProperties",
2365 Builtin::kObjectDefineProperties, 2, kAdapt);
2366
2367 SimpleInstallFunction(isolate_, object_function, "defineProperty",
2368 Builtin::kObjectDefineProperty, 3, kAdapt);
2369
2370 SimpleInstallFunction(isolate_, object_function, "freeze",
2371 Builtin::kObjectFreeze, 1, kDontAdapt);
2372
2373 SimpleInstallFunction(isolate_, object_function, "getPrototypeOf",
2374 Builtin::kObjectGetPrototypeOf, 1, kAdapt);
2375 SimpleInstallFunction(isolate_, object_function, "setPrototypeOf",
2376 Builtin::kObjectSetPrototypeOf, 2, kAdapt);
2377
2378 SimpleInstallFunction(isolate_, object_function, "isExtensible",
2379 Builtin::kObjectIsExtensible, 1, kAdapt);
2380 SimpleInstallFunction(isolate_, object_function, "isFrozen",
2381 Builtin::kObjectIsFrozen, 1, kDontAdapt);
2382
2383 SimpleInstallFunction(isolate_, object_function, "isSealed",
2384 Builtin::kObjectIsSealed, 1, kDontAdapt);
2385
2386 SimpleInstallFunction(isolate_, object_function, "keys",
2387 Builtin::kObjectKeys, 1, kAdapt);
2388 SimpleInstallFunction(isolate_, object_function, "entries",
2389 Builtin::kObjectEntries, 1, kAdapt);
2390 SimpleInstallFunction(isolate_, object_function, "fromEntries",
2391 Builtin::kObjectFromEntries, 1, kDontAdapt);
2392 SimpleInstallFunction(isolate_, object_function, "values",
2393 Builtin::kObjectValues, 1, kAdapt);
2394
2395 SimpleInstallFunction(isolate_, object_function, "groupBy",
2396 Builtin::kObjectGroupBy, 2, kAdapt);
2397
2398 SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
2399 "__defineGetter__", Builtin::kObjectDefineGetter, 2,
2400 kAdapt);
2401 SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
2402 "__defineSetter__", Builtin::kObjectDefineSetter, 2,
2403 kAdapt);
2404 SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
2405 "hasOwnProperty",
2406 Builtin::kObjectPrototypeHasOwnProperty, 1, kAdapt);
2407 SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
2408 "__lookupGetter__", Builtin::kObjectLookupGetter, 1,
2409 kAdapt);
2410 SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
2411 "__lookupSetter__", Builtin::kObjectLookupSetter, 1,
2412 kAdapt);
2413 SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
2414 "isPrototypeOf",
2415 Builtin::kObjectPrototypeIsPrototypeOf, 1, kAdapt);
2417 isolate_, isolate_->initial_object_prototype(), "propertyIsEnumerable",
2418 Builtin::kObjectPrototypePropertyIsEnumerable, 1, kDontAdapt);
2420 isolate_, isolate_->initial_object_prototype(), "toString",
2421 Builtin::kObjectPrototypeToString, 0, kAdapt);
2422 native_context()->set_object_to_string(*object_to_string);
2424 isolate_, isolate_->initial_object_prototype(), "valueOf",
2425 Builtin::kObjectPrototypeValueOf, 0, kAdapt);
2426 native_context()->set_object_value_of_function(*object_value_of);
2427
2428 SimpleInstallGetterSetter(
2429 isolate_, isolate_->initial_object_prototype(), factory->proto_string(),
2430 Builtin::kObjectPrototypeGetProto, Builtin::kObjectPrototypeSetProto);
2431
2432 SimpleInstallFunction(isolate_, isolate_->initial_object_prototype(),
2433 "toLocaleString",
2434 Builtin::kObjectPrototypeToLocaleString, 0, kAdapt);
2435 }
2436
2437 DirectHandle<JSObject> global(native_context()->global_object(), isolate());
2438
2439 { // --- F u n c t i o n ---
2440 DirectHandle<JSFunction> prototype = empty_function;
2441 DirectHandle<JSFunction> function_fun =
2442 InstallFunction(isolate_, global, "Function", JS_FUNCTION_TYPE,
2443 JSFunction::kSizeWithPrototype, 0, prototype,
2444 Builtin::kFunctionConstructor, 1, kDontAdapt);
2445 // Function instances are sloppy by default.
2446 function_fun->set_prototype_or_initial_map(*isolate_->sloppy_function_map(),
2449 Context::FUNCTION_FUNCTION_INDEX);
2450 native_context()->set_function_prototype(*prototype);
2451
2452 // Setup the methods on the %FunctionPrototype%.
2453 JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
2454 function_fun, DONT_ENUM);
2455 DirectHandle<JSFunction> function_prototype_apply =
2456 SimpleInstallFunction(isolate_, prototype, "apply",
2457 Builtin::kFunctionPrototypeApply, 2, kDontAdapt);
2458 native_context()->set_function_prototype_apply(*function_prototype_apply);
2459 SimpleInstallFunction(isolate_, prototype, "bind",
2460 Builtin::kFastFunctionPrototypeBind, 1, kDontAdapt);
2461 SimpleInstallFunction(isolate_, prototype, "call",
2462 Builtin::kFunctionPrototypeCall, 1, kDontAdapt);
2464 isolate_, prototype, "toString", Builtin::kFunctionPrototypeToString, 0,
2465 kDontAdapt);
2466 native_context()->set_function_to_string(*function_to_string);
2467
2468 // Install the @@hasInstance function.
2469 DirectHandle<JSFunction> has_instance = InstallFunctionAtSymbol(
2470 isolate_, prototype, factory->has_instance_symbol(),
2471 "[Symbol.hasInstance]", Builtin::kFunctionPrototypeHasInstance, 1,
2472 kAdapt,
2474 native_context()->set_function_has_instance(*has_instance);
2475
2476 // Complete setting up function maps.
2477 {
2478 isolate_->sloppy_function_map()->SetConstructor(*function_fun);
2479 isolate_->sloppy_function_with_name_map()->SetConstructor(*function_fun);
2480 isolate_->sloppy_function_with_readonly_prototype_map()->SetConstructor(
2481 *function_fun);
2482 isolate_->sloppy_function_without_prototype_map()->SetConstructor(
2483 *function_fun);
2484
2485 isolate_->strict_function_map()->SetConstructor(*function_fun);
2486 isolate_->strict_function_with_name_map()->SetConstructor(*function_fun);
2487 isolate_->strict_function_with_readonly_prototype_map()->SetConstructor(
2488 *function_fun);
2489 isolate_->strict_function_without_prototype_map()->SetConstructor(
2490 *function_fun);
2491
2492 isolate_->class_function_map()->SetConstructor(*function_fun);
2493 }
2494 }
2495
2496 DirectHandle<JSFunction> array_prototype_to_string_fun;
2497 { // --- A r r a y ---
2498 // This seems a bit hackish, but we need to make sure Array.length is 1.
2499 int length = 1;
2500 DirectHandle<JSFunction> array_function = InstallFunction(
2501 isolate_, global, "Array", JS_ARRAY_TYPE, JSArray::kHeaderSize, 0,
2502 isolate_->initial_object_prototype(), Builtin::kArrayConstructor,
2503 length, kDontAdapt);
2504
2505 DirectHandle<Map> initial_map(array_function->initial_map(), isolate());
2506
2507 // This assert protects an optimization in
2508 // HGraphBuilder::JSArrayBuilder::EmitMapCode()
2509 DCHECK(initial_map->elements_kind() == GetInitialFastElementsKind());
2510 Map::EnsureDescriptorSlack(isolate_, initial_map, 1);
2511
2512 PropertyAttributes attribs =
2514
2515 static_assert(JSArray::kLengthDescriptorIndex == 0);
2516 { // Add length.
2518 factory->length_string(), factory->array_length_accessor(), attribs);
2519 initial_map->AppendDescriptor(isolate(), &d);
2520 }
2521
2523 Context::ARRAY_FUNCTION_INDEX);
2524 InstallSpeciesGetter(isolate_, array_function);
2525
2526 // Create the initial array map for Array.prototype which is required by
2527 // the used ArrayConstructorStub.
2528 // This is repeated after properly instantiating the Array.prototype.
2529 InitializeJSArrayMaps(isolate_, native_context(), initial_map);
2530
2531 // Set up %ArrayPrototype%.
2532 // The %ArrayPrototype% has TERMINAL_FAST_ELEMENTS_KIND in order to ensure
2533 // that constant functions stay constant after turning prototype to setup
2534 // mode and back.
2537 JSFunction::SetPrototype(array_function, proto);
2538 native_context()->set_initial_array_prototype(*proto);
2539
2540 InitializeJSArrayMaps(
2542 direct_handle(array_function->initial_map(), isolate_));
2543 SimpleInstallFunction(isolate_, array_function, "isArray",
2544 Builtin::kArrayIsArray, 1, kAdapt);
2545 SimpleInstallFunction(isolate_, array_function, "from", Builtin::kArrayFrom,
2546 1, kDontAdapt);
2547 SimpleInstallFunction(isolate(), array_function, "fromAsync",
2548 Builtin::kArrayFromAsync, 1, kDontAdapt);
2549 SimpleInstallFunction(isolate_, array_function, "of", Builtin::kArrayOf, 0,
2550 kDontAdapt);
2551 SetConstructorInstanceType(isolate_, array_function,
2552 JS_ARRAY_CONSTRUCTOR_TYPE);
2553
2554 JSObject::AddProperty(isolate_, proto, factory->constructor_string(),
2555 array_function, DONT_ENUM);
2556
2557 SimpleInstallFunction(isolate_, proto, "at", Builtin::kArrayPrototypeAt, 1,
2558 kAdapt);
2559 SimpleInstallFunction(isolate_, proto, "concat",
2560 Builtin::kArrayPrototypeConcat, 1, kDontAdapt);
2561 SimpleInstallFunction(isolate_, proto, "copyWithin",
2562 Builtin::kArrayPrototypeCopyWithin, 2, kDontAdapt);
2563 SimpleInstallFunction(isolate_, proto, "fill", Builtin::kArrayPrototypeFill,
2564 1, kDontAdapt);
2565 SimpleInstallFunction(isolate_, proto, "find", Builtin::kArrayPrototypeFind,
2566 1, kDontAdapt);
2567 SimpleInstallFunction(isolate_, proto, "findIndex",
2568 Builtin::kArrayPrototypeFindIndex, 1, kDontAdapt);
2569 SimpleInstallFunction(isolate_, proto, "findLast",
2570 Builtin::kArrayPrototypeFindLast, 1, kDontAdapt);
2571 SimpleInstallFunction(isolate_, proto, "findLastIndex",
2572 Builtin::kArrayPrototypeFindLastIndex, 1, kDontAdapt);
2573 SimpleInstallFunction(isolate_, proto, "lastIndexOf",
2574 Builtin::kArrayPrototypeLastIndexOf, 1, kDontAdapt);
2575 SimpleInstallFunction(isolate_, proto, "pop", Builtin::kArrayPrototypePop,
2576 0, kDontAdapt);
2577 SimpleInstallFunction(isolate_, proto, "push", Builtin::kArrayPrototypePush,
2578 1, kDontAdapt);
2579 SimpleInstallFunction(isolate_, proto, "reverse",
2580 Builtin::kArrayPrototypeReverse, 0, kDontAdapt);
2581 SimpleInstallFunction(isolate_, proto, "shift",
2582 Builtin::kArrayPrototypeShift, 0, kDontAdapt);
2583 SimpleInstallFunction(isolate_, proto, "unshift",
2584 Builtin::kArrayPrototypeUnshift, 1, kDontAdapt);
2585 SimpleInstallFunction(isolate_, proto, "slice",
2586 Builtin::kArrayPrototypeSlice, 2, kDontAdapt);
2587 SimpleInstallFunction(isolate_, proto, "sort", Builtin::kArrayPrototypeSort,
2588 1, kDontAdapt);
2589 SimpleInstallFunction(isolate_, proto, "splice",
2590 Builtin::kArrayPrototypeSplice, 2, kDontAdapt);
2591 SimpleInstallFunction(isolate_, proto, "includes", Builtin::kArrayIncludes,
2592 1, kDontAdapt);
2593 SimpleInstallFunction(isolate_, proto, "indexOf", Builtin::kArrayIndexOf, 1,
2594 kDontAdapt);
2595 SimpleInstallFunction(isolate_, proto, "join", Builtin::kArrayPrototypeJoin,
2596 1, kDontAdapt);
2597
2598 { // Set up iterator-related properties.
2599 DirectHandle<JSFunction> keys = InstallFunctionWithBuiltinId(
2600 isolate_, proto, "keys", Builtin::kArrayPrototypeKeys, 0, kAdapt);
2601 native_context()->set_array_keys_iterator(*keys);
2602
2603 DirectHandle<JSFunction> entries = InstallFunctionWithBuiltinId(
2604 isolate_, proto, "entries", Builtin::kArrayPrototypeEntries, 0,
2605 kAdapt);
2606 native_context()->set_array_entries_iterator(*entries);
2607
2608 DirectHandle<JSFunction> values = InstallFunctionWithBuiltinId(
2609 isolate_, proto, "values", Builtin::kArrayPrototypeValues, 0, kAdapt);
2610 JSObject::AddProperty(isolate_, proto, factory->iterator_symbol(), values,
2611 DONT_ENUM);
2612 native_context()->set_array_values_iterator(*values);
2613 }
2614
2616 isolate_, proto, "forEach", Builtin::kArrayForEach, 1, kDontAdapt);
2617 native_context()->set_array_for_each_iterator(*for_each_fun);
2618 SimpleInstallFunction(isolate_, proto, "filter", Builtin::kArrayFilter, 1,
2619 kDontAdapt);
2620 SimpleInstallFunction(isolate_, proto, "flat", Builtin::kArrayPrototypeFlat,
2621 0, kDontAdapt);
2622 SimpleInstallFunction(isolate_, proto, "flatMap",
2623 Builtin::kArrayPrototypeFlatMap, 1, kDontAdapt);
2624 SimpleInstallFunction(isolate_, proto, "map", Builtin::kArrayMap, 1,
2625 kDontAdapt);
2626 SimpleInstallFunction(isolate_, proto, "every", Builtin::kArrayEvery, 1,
2627 kDontAdapt);
2628 SimpleInstallFunction(isolate_, proto, "some", Builtin::kArraySome, 1,
2629 kDontAdapt);
2630 SimpleInstallFunction(isolate_, proto, "reduce", Builtin::kArrayReduce, 1,
2631 kDontAdapt);
2632 SimpleInstallFunction(isolate_, proto, "reduceRight",
2633 Builtin::kArrayReduceRight, 1, kDontAdapt);
2634
2635 SimpleInstallFunction(isolate_, proto, "toReversed",
2636 Builtin::kArrayPrototypeToReversed, 0, kDontAdapt);
2637 SimpleInstallFunction(isolate_, proto, "toSorted",
2638 Builtin::kArrayPrototypeToSorted, 1, kDontAdapt);
2639 SimpleInstallFunction(isolate_, proto, "toSpliced",
2640 Builtin::kArrayPrototypeToSpliced, 2, kDontAdapt);
2641 SimpleInstallFunction(isolate_, proto, "with", Builtin::kArrayPrototypeWith,
2642 2, kAdapt);
2643
2644 SimpleInstallFunction(isolate_, proto, "toLocaleString",
2645 Builtin::kArrayPrototypeToLocaleString, 0,
2646 kDontAdapt);
2647 array_prototype_to_string_fun =
2648 SimpleInstallFunction(isolate_, proto, "toString",
2649 Builtin::kArrayPrototypeToString, 0, kDontAdapt);
2650
2652 InstallTrueValuedProperty(isolate_, unscopables, "at");
2653 InstallTrueValuedProperty(isolate_, unscopables, "copyWithin");
2654 InstallTrueValuedProperty(isolate_, unscopables, "entries");
2655 InstallTrueValuedProperty(isolate_, unscopables, "fill");
2656 InstallTrueValuedProperty(isolate_, unscopables, "find");
2657 InstallTrueValuedProperty(isolate_, unscopables, "findIndex");
2658 InstallTrueValuedProperty(isolate_, unscopables, "findLast");
2659 InstallTrueValuedProperty(isolate_, unscopables, "findLastIndex");
2660 InstallTrueValuedProperty(isolate_, unscopables, "flat");
2661 InstallTrueValuedProperty(isolate_, unscopables, "flatMap");
2662 InstallTrueValuedProperty(isolate_, unscopables, "includes");
2663 InstallTrueValuedProperty(isolate_, unscopables, "keys");
2664 InstallTrueValuedProperty(isolate_, unscopables, "toReversed");
2665 InstallTrueValuedProperty(isolate_, unscopables, "toSorted");
2666 InstallTrueValuedProperty(isolate_, unscopables, "toSpliced");
2667 InstallTrueValuedProperty(isolate_, unscopables, "values");
2668
2669 JSObject::MigrateSlowToFast(unscopables, 0, "Bootstrapping");
2671 isolate_, proto, factory->unscopables_symbol(), unscopables,
2672 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2673
2674 DirectHandle<Map> map(proto->map(), isolate_);
2676 }
2677
2678 { // --- A r r a y I t e r a t o r ---
2679 DirectHandle<JSObject> iterator_prototype(
2680 native_context()->initial_iterator_prototype(), isolate());
2681
2682 DirectHandle<JSObject> array_iterator_prototype =
2683 factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
2684 JSObject::ForceSetPrototype(isolate(), array_iterator_prototype,
2685 iterator_prototype);
2686 CHECK_NE(array_iterator_prototype->map().ptr(),
2687 isolate_->initial_object_prototype()->map().ptr());
2688 array_iterator_prototype->map()->set_instance_type(
2689 JS_ARRAY_ITERATOR_PROTOTYPE_TYPE);
2690
2691 InstallToStringTag(isolate_, array_iterator_prototype,
2692 factory->ArrayIterator_string());
2693
2694 InstallFunctionWithBuiltinId(isolate_, array_iterator_prototype, "next",
2695 Builtin::kArrayIteratorPrototypeNext, 0,
2696 kAdapt);
2697
2698 DirectHandle<JSFunction> array_iterator_function = CreateFunction(
2699 isolate_, factory->ArrayIterator_string(), JS_ARRAY_ITERATOR_TYPE,
2700 JSArrayIterator::kHeaderSize, 0, array_iterator_prototype,
2701 Builtin::kIllegal, 0, kDontAdapt);
2702 array_iterator_function->shared()->set_native(false);
2703
2704 native_context()->set_initial_array_iterator_map(
2705 array_iterator_function->initial_map());
2706 native_context()->set_initial_array_iterator_prototype(
2707 *array_iterator_prototype);
2708 }
2709
2710 { // --- N u m b e r ---
2711 DirectHandle<JSFunction> number_fun =
2712 InstallFunction(isolate_, global, "Number", JS_PRIMITIVE_WRAPPER_TYPE,
2713 JSPrimitiveWrapper::kHeaderSize, 0,
2714 isolate_->initial_object_prototype(),
2715 Builtin::kNumberConstructor, 1, kDontAdapt);
2717 Context::NUMBER_FUNCTION_INDEX);
2718
2719 // Create the %NumberPrototype%
2722 prototype->set_value(Smi::zero());
2723 JSFunction::SetPrototype(number_fun, prototype);
2724
2725 // Install the "constructor" property on the {prototype}.
2726 JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
2727 number_fun, DONT_ENUM);
2728
2729 // Install the Number.prototype methods.
2730 SimpleInstallFunction(isolate_, prototype, "toExponential",
2731 Builtin::kNumberPrototypeToExponential, 1,
2732 kDontAdapt);
2733 SimpleInstallFunction(isolate_, prototype, "toFixed",
2734 Builtin::kNumberPrototypeToFixed, 1, kDontAdapt);
2735 SimpleInstallFunction(isolate_, prototype, "toPrecision",
2736 Builtin::kNumberPrototypeToPrecision, 1, kDontAdapt);
2737 SimpleInstallFunction(isolate_, prototype, "toString",
2738 Builtin::kNumberPrototypeToString, 1, kDontAdapt);
2739 SimpleInstallFunction(isolate_, prototype, "valueOf",
2740 Builtin::kNumberPrototypeValueOf, 0, kAdapt);
2741
2742 SimpleInstallFunction(isolate_, prototype, "toLocaleString",
2743 Builtin::kNumberPrototypeToLocaleString, 0,
2744 kDontAdapt);
2745
2746 // Install the Number functions.
2747 SimpleInstallFunction(isolate_, number_fun, "isFinite",
2748 Builtin::kNumberIsFinite, 1, kAdapt);
2749 SimpleInstallFunction(isolate_, number_fun, "isInteger",
2750 Builtin::kNumberIsInteger, 1, kAdapt);
2751 SimpleInstallFunction(isolate_, number_fun, "isNaN", Builtin::kNumberIsNaN,
2752 1, kAdapt);
2753 SimpleInstallFunction(isolate_, number_fun, "isSafeInteger",
2754 Builtin::kNumberIsSafeInteger, 1, kAdapt);
2755
2756 // Install Number.parseFloat and Global.parseFloat.
2757 DirectHandle<JSFunction> parse_float_fun =
2758 SimpleInstallFunction(isolate_, number_fun, "parseFloat",
2759 Builtin::kNumberParseFloat, 1, kAdapt);
2760 JSObject::AddProperty(isolate_, global_object, "parseFloat",
2761 parse_float_fun, DONT_ENUM);
2762 native_context()->set_global_parse_float_fun(*parse_float_fun);
2763
2764 // Install Number.parseInt and Global.parseInt.
2766 isolate_, number_fun, "parseInt", Builtin::kNumberParseInt, 2, kAdapt);
2767 JSObject::AddProperty(isolate_, global_object, "parseInt", parse_int_fun,
2768 DONT_ENUM);
2769 native_context()->set_global_parse_int_fun(*parse_int_fun);
2770
2771 // Install Number constants
2772 const double kMaxValue = 1.7976931348623157e+308;
2773 const double kMinValue = 5e-324;
2774 const double kEPS = 2.220446049250313e-16;
2775
2776 InstallConstant(isolate_, number_fun, "MAX_VALUE",
2777 factory->NewNumber(kMaxValue));
2778 InstallConstant(isolate_, number_fun, "MIN_VALUE",
2779 factory->NewNumber(kMinValue));
2780 InstallConstant(isolate_, number_fun, "NaN", factory->nan_value());
2781 InstallConstant(isolate_, number_fun, "NEGATIVE_INFINITY",
2783 InstallConstant(isolate_, number_fun, "POSITIVE_INFINITY",
2784 factory->infinity_value());
2785 InstallConstant(isolate_, number_fun, "MAX_SAFE_INTEGER",
2787 InstallConstant(isolate_, number_fun, "MIN_SAFE_INTEGER",
2789 InstallConstant(isolate_, number_fun, "EPSILON", factory->NewNumber(kEPS));
2790
2791 InstallConstant(isolate_, global, "Infinity", factory->infinity_value());
2792 InstallConstant(isolate_, global, "NaN", factory->nan_value());
2793 InstallConstant(isolate_, global, "undefined", factory->undefined_value());
2794 }
2795
2796 { // --- B o o l e a n ---
2797 DirectHandle<JSFunction> boolean_fun =
2798 InstallFunction(isolate_, global, "Boolean", JS_PRIMITIVE_WRAPPER_TYPE,
2799 JSPrimitiveWrapper::kHeaderSize, 0,
2800 isolate_->initial_object_prototype(),
2801 Builtin::kBooleanConstructor, 1, kDontAdapt);
2803 Context::BOOLEAN_FUNCTION_INDEX);
2804
2805 // Create the %BooleanPrototype%
2808 prototype->set_value(ReadOnlyRoots(isolate_).false_value());
2809 JSFunction::SetPrototype(boolean_fun, prototype);
2810
2811 // Install the "constructor" property on the {prototype}.
2812 JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
2813 boolean_fun, DONT_ENUM);
2814
2815 // Install the Boolean.prototype methods.
2816 SimpleInstallFunction(isolate_, prototype, "toString",
2817 Builtin::kBooleanPrototypeToString, 0, kAdapt);
2818 SimpleInstallFunction(isolate_, prototype, "valueOf",
2819 Builtin::kBooleanPrototypeValueOf, 0, kAdapt);
2820 }
2821
2822 { // --- S t r i n g ---
2823 DirectHandle<JSFunction> string_fun =
2824 InstallFunction(isolate_, global, "String", JS_PRIMITIVE_WRAPPER_TYPE,
2825 JSPrimitiveWrapper::kHeaderSize, 0,
2826 isolate_->initial_object_prototype(),
2827 Builtin::kStringConstructor, 1, kDontAdapt);
2829 Context::STRING_FUNCTION_INDEX);
2830
2831 DirectHandle<Map> string_map(
2832 native_context()->string_function()->initial_map(), isolate());
2833 string_map->set_elements_kind(FAST_STRING_WRAPPER_ELEMENTS);
2834 Map::EnsureDescriptorSlack(isolate_, string_map, 1);
2835
2836 PropertyAttributes attribs =
2838
2839 { // Add length.
2841 factory->length_string(), factory->string_length_accessor(), attribs);
2842 string_map->AppendDescriptor(isolate(), &d);
2843 }
2844
2845 // Install the String.fromCharCode function.
2846 SimpleInstallFunction(isolate_, string_fun, "fromCharCode",
2847 Builtin::kStringFromCharCode, 1, kDontAdapt);
2848
2849 // Install the String.fromCodePoint function.
2850 SimpleInstallFunction(isolate_, string_fun, "fromCodePoint",
2851 Builtin::kStringFromCodePoint, 1, kDontAdapt);
2852
2853 // Install the String.raw function.
2854 SimpleInstallFunction(isolate_, string_fun, "raw", Builtin::kStringRaw, 1,
2855 kDontAdapt);
2856
2857 // Create the %StringPrototype%
2860 prototype->set_value(ReadOnlyRoots(isolate_).empty_string());
2861 JSFunction::SetPrototype(string_fun, prototype);
2862 native_context()->set_initial_string_prototype(*prototype);
2863
2864 // Install the "constructor" property on the {prototype}.
2865 JSObject::AddProperty(isolate_, prototype, factory->constructor_string(),
2866 string_fun, DONT_ENUM);
2867
2868 // Install the String.prototype methods.
2869 SimpleInstallFunction(isolate_, prototype, "anchor",
2870 Builtin::kStringPrototypeAnchor, 1, kDontAdapt);
2871 SimpleInstallFunction(isolate_, prototype, "at",
2872 Builtin::kStringPrototypeAt, 1, kAdapt);
2873 SimpleInstallFunction(isolate_, prototype, "big",
2874 Builtin::kStringPrototypeBig, 0, kDontAdapt);
2875 SimpleInstallFunction(isolate_, prototype, "blink",
2876 Builtin::kStringPrototypeBlink, 0, kDontAdapt);
2877 SimpleInstallFunction(isolate_, prototype, "bold",
2878 Builtin::kStringPrototypeBold, 0, kDontAdapt);
2879 SimpleInstallFunction(isolate_, prototype, "charAt",
2880 Builtin::kStringPrototypeCharAt, 1, kAdapt);
2881 SimpleInstallFunction(isolate_, prototype, "charCodeAt",
2882 Builtin::kStringPrototypeCharCodeAt, 1, kAdapt);
2883 SimpleInstallFunction(isolate_, prototype, "codePointAt",
2884 Builtin::kStringPrototypeCodePointAt, 1, kAdapt);
2885 SimpleInstallFunction(isolate_, prototype, "concat",
2886 Builtin::kStringPrototypeConcat, 1, kDontAdapt);
2887 SimpleInstallFunction(isolate_, prototype, "endsWith",
2888 Builtin::kStringPrototypeEndsWith, 1, kDontAdapt);
2889 SimpleInstallFunction(isolate_, prototype, "fontcolor",
2890 Builtin::kStringPrototypeFontcolor, 1, kDontAdapt);
2891 SimpleInstallFunction(isolate_, prototype, "fontsize",
2892 Builtin::kStringPrototypeFontsize, 1, kDontAdapt);
2893 SimpleInstallFunction(isolate_, prototype, "fixed",
2894 Builtin::kStringPrototypeFixed, 0, kDontAdapt);
2895 SimpleInstallFunction(isolate_, prototype, "includes",
2896 Builtin::kStringPrototypeIncludes, 1, kDontAdapt);
2897 SimpleInstallFunction(isolate_, prototype, "indexOf",
2898 Builtin::kStringPrototypeIndexOf, 1, kDontAdapt);
2899 SimpleInstallFunction(isolate(), prototype, "isWellFormed",
2900 Builtin::kStringPrototypeIsWellFormed, 0, kDontAdapt);
2901 SimpleInstallFunction(isolate_, prototype, "italics",
2902 Builtin::kStringPrototypeItalics, 0, kDontAdapt);
2903 SimpleInstallFunction(isolate_, prototype, "lastIndexOf",
2904 Builtin::kStringPrototypeLastIndexOf, 1, kDontAdapt);
2905 SimpleInstallFunction(isolate_, prototype, "link",
2906 Builtin::kStringPrototypeLink, 1, kDontAdapt);
2907#ifdef V8_INTL_SUPPORT
2908 SimpleInstallFunction(isolate_, prototype, "localeCompare",
2909 Builtin::kStringPrototypeLocaleCompareIntl, 1,
2910 kDontAdapt);
2911#else
2912 SimpleInstallFunction(isolate_, prototype, "localeCompare",
2913 Builtin::kStringPrototypeLocaleCompare, 1, kAdapt);
2914#endif // V8_INTL_SUPPORT
2915 SimpleInstallFunction(isolate_, prototype, "match",
2916 Builtin::kStringPrototypeMatch, 1, kAdapt);
2917 SimpleInstallFunction(isolate_, prototype, "matchAll",
2918 Builtin::kStringPrototypeMatchAll, 1, kAdapt);
2919#ifdef V8_INTL_SUPPORT
2920 SimpleInstallFunction(isolate_, prototype, "normalize",
2921 Builtin::kStringPrototypeNormalizeIntl, 0,
2922 kDontAdapt);
2923#else
2924 SimpleInstallFunction(isolate_, prototype, "normalize",
2925 Builtin::kStringPrototypeNormalize, 0, kDontAdapt);
2926#endif // V8_INTL_SUPPORT
2927 SimpleInstallFunction(isolate_, prototype, "padEnd",
2928 Builtin::kStringPrototypePadEnd, 1, kDontAdapt);
2929 SimpleInstallFunction(isolate_, prototype, "padStart",
2930 Builtin::kStringPrototypePadStart, 1, kDontAdapt);
2931 SimpleInstallFunction(isolate_, prototype, "repeat",
2932 Builtin::kStringPrototypeRepeat, 1, kAdapt);
2933 SimpleInstallFunction(isolate_, prototype, "replace",
2934 Builtin::kStringPrototypeReplace, 2, kAdapt);
2935 SimpleInstallFunction(isolate(), prototype, "replaceAll",
2936 Builtin::kStringPrototypeReplaceAll, 2, kAdapt);
2937 SimpleInstallFunction(isolate_, prototype, "search",
2938 Builtin::kStringPrototypeSearch, 1, kAdapt);
2939 SimpleInstallFunction(isolate_, prototype, "slice",
2940 Builtin::kStringPrototypeSlice, 2, kDontAdapt);
2941 SimpleInstallFunction(isolate_, prototype, "small",
2942 Builtin::kStringPrototypeSmall, 0, kDontAdapt);
2943 SimpleInstallFunction(isolate_, prototype, "split",
2944 Builtin::kStringPrototypeSplit, 2, kDontAdapt);
2945 SimpleInstallFunction(isolate_, prototype, "strike",
2946 Builtin::kStringPrototypeStrike, 0, kDontAdapt);
2947 SimpleInstallFunction(isolate_, prototype, "sub",
2948 Builtin::kStringPrototypeSub, 0, kDontAdapt);
2949 SimpleInstallFunction(isolate_, prototype, "substr",
2950 Builtin::kStringPrototypeSubstr, 2, kDontAdapt);
2951 SimpleInstallFunction(isolate_, prototype, "substring",
2952 Builtin::kStringPrototypeSubstring, 2, kDontAdapt);
2953 SimpleInstallFunction(isolate_, prototype, "sup",
2954 Builtin::kStringPrototypeSup, 0, kDontAdapt);
2955 SimpleInstallFunction(isolate_, prototype, "startsWith",
2956 Builtin::kStringPrototypeStartsWith, 1, kDontAdapt);
2957 SimpleInstallFunction(isolate_, prototype, "toString",
2958 Builtin::kStringPrototypeToString, 0, kAdapt);
2959 SimpleInstallFunction(isolate(), prototype, "toWellFormed",
2960 Builtin::kStringPrototypeToWellFormed, 0, kDontAdapt);
2961 SimpleInstallFunction(isolate_, prototype, "trim",
2962 Builtin::kStringPrototypeTrim, 0, kDontAdapt);
2963
2964 // Install `String.prototype.trimStart` with `trimLeft` alias.
2966 isolate_, prototype, "trimStart", Builtin::kStringPrototypeTrimStart, 0,
2967 kDontAdapt);
2968 JSObject::AddProperty(isolate_, prototype, "trimLeft", trim_start_fun,
2969 DONT_ENUM);
2970
2971 // Install `String.prototype.trimEnd` with `trimRight` alias.
2972 DirectHandle<JSFunction> trim_end_fun =
2973 SimpleInstallFunction(isolate_, prototype, "trimEnd",
2974 Builtin::kStringPrototypeTrimEnd, 0, kDontAdapt);
2975 JSObject::AddProperty(isolate_, prototype, "trimRight", trim_end_fun,
2976 DONT_ENUM);
2977
2978 SimpleInstallFunction(isolate_, prototype, "toLocaleLowerCase",
2979 Builtin::kStringPrototypeToLocaleLowerCase, 0,
2980 kDontAdapt);
2981 SimpleInstallFunction(isolate_, prototype, "toLocaleUpperCase",
2982 Builtin::kStringPrototypeToLocaleUpperCase, 0,
2983 kDontAdapt);
2984#ifdef V8_INTL_SUPPORT
2985 SimpleInstallFunction(isolate_, prototype, "toLowerCase",
2986 Builtin::kStringPrototypeToLowerCaseIntl, 0, kAdapt);
2987 SimpleInstallFunction(isolate_, prototype, "toUpperCase",
2988 Builtin::kStringPrototypeToUpperCaseIntl, 0,
2989 kDontAdapt);
2990#else
2991 SimpleInstallFunction(isolate_, prototype, "toLowerCase",
2992 Builtin::kStringPrototypeToLowerCase, 0, kDontAdapt);
2993 SimpleInstallFunction(isolate_, prototype, "toUpperCase",
2994 Builtin::kStringPrototypeToUpperCase, 0, kDontAdapt);
2995#endif
2996 SimpleInstallFunction(isolate_, prototype, "valueOf",
2997 Builtin::kStringPrototypeValueOf, 0, kAdapt);
2998
2999 InstallFunctionAtSymbol(
3000 isolate_, prototype, factory->iterator_symbol(), "[Symbol.iterator]",
3001 Builtin::kStringPrototypeIterator, 0, kAdapt, DONT_ENUM);
3002 }
3003
3004 { // --- S t r i n g I t e r a t o r ---
3005 DirectHandle<JSObject> iterator_prototype(
3006 native_context()->initial_iterator_prototype(), isolate());
3007
3008 DirectHandle<JSObject> string_iterator_prototype =
3009 factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
3010 JSObject::ForceSetPrototype(isolate(), string_iterator_prototype,
3011 iterator_prototype);
3012 CHECK_NE(string_iterator_prototype->map().ptr(),
3013 isolate_->initial_object_prototype()->map().ptr());
3014 string_iterator_prototype->map()->set_instance_type(
3015 JS_STRING_ITERATOR_PROTOTYPE_TYPE);
3016 InstallToStringTag(isolate_, string_iterator_prototype, "String Iterator");
3017
3018 InstallFunctionWithBuiltinId(isolate_, string_iterator_prototype, "next",
3019 Builtin::kStringIteratorPrototypeNext, 0,
3020 kAdapt);
3021
3022 DirectHandle<JSFunction> string_iterator_function = CreateFunction(
3023 isolate_, factory->InternalizeUtf8String("StringIterator"),
3024 JS_STRING_ITERATOR_TYPE, JSStringIterator::kHeaderSize, 0,
3025 string_iterator_prototype, Builtin::kIllegal, 0, kDontAdapt);
3026 string_iterator_function->shared()->set_native(false);
3027 native_context()->set_initial_string_iterator_map(
3028 string_iterator_function->initial_map());
3029 native_context()->set_initial_string_iterator_prototype(
3030 *string_iterator_prototype);
3031 }
3032
3033 { // --- S y m b o l ---
3034 DirectHandle<JSFunction> symbol_fun = InstallFunction(
3035 isolate_, global, "Symbol", JS_PRIMITIVE_WRAPPER_TYPE,
3036 JSPrimitiveWrapper::kHeaderSize, 0, factory->the_hole_value(),
3037 Builtin::kSymbolConstructor, 0, kDontAdapt);
3038 native_context()->set_symbol_function(*symbol_fun);
3039
3040 // Install the Symbol.for and Symbol.keyFor functions.
3041 SimpleInstallFunction(isolate_, symbol_fun, "for", Builtin::kSymbolFor, 1,
3042 kDontAdapt);
3043 SimpleInstallFunction(isolate_, symbol_fun, "keyFor",
3044 Builtin::kSymbolKeyFor, 1, kDontAdapt);
3045
3046 // Install well-known symbols.
3047 InstallConstant(isolate_, symbol_fun, "asyncIterator",
3048 factory->async_iterator_symbol());
3049 InstallConstant(isolate_, symbol_fun, "hasInstance",
3050 factory->has_instance_symbol());
3051 InstallConstant(isolate_, symbol_fun, "isConcatSpreadable",
3052 factory->is_concat_spreadable_symbol());
3053 InstallConstant(isolate_, symbol_fun, "iterator",
3054 factory->iterator_symbol());
3055 InstallConstant(isolate_, symbol_fun, "match", factory->match_symbol());
3056 InstallConstant(isolate_, symbol_fun, "matchAll",
3057 factory->match_all_symbol());
3058 InstallConstant(isolate_, symbol_fun, "replace", factory->replace_symbol());
3059 InstallConstant(isolate_, symbol_fun, "search", factory->search_symbol());
3060 InstallConstant(isolate_, symbol_fun, "species", factory->species_symbol());
3061 InstallConstant(isolate_, symbol_fun, "split", factory->split_symbol());
3062 InstallConstant(isolate_, symbol_fun, "toPrimitive",
3063 factory->to_primitive_symbol());
3064 InstallConstant(isolate_, symbol_fun, "toStringTag",
3065 factory->to_string_tag_symbol());
3066 InstallConstant(isolate_, symbol_fun, "unscopables",
3067 factory->unscopables_symbol());
3068 InstallConstant(isolate_, symbol_fun, "dispose", factory->dispose_symbol());
3069 InstallConstant(isolate_, symbol_fun, "asyncDispose",
3070 factory->async_dispose_symbol());
3071
3072 // Setup %SymbolPrototype%.
3074 Cast<JSObject>(symbol_fun->instance_prototype()), isolate());
3075
3076 InstallToStringTag(isolate_, prototype, "Symbol");
3077
3078 // Install the Symbol.prototype methods.
3079 InstallFunctionWithBuiltinId(isolate_, prototype, "toString",
3080 Builtin::kSymbolPrototypeToString, 0, kAdapt);
3081 InstallFunctionWithBuiltinId(isolate_, prototype, "valueOf",
3082 Builtin::kSymbolPrototypeValueOf, 0, kAdapt);
3083
3084 // Install the Symbol.prototype.description getter.
3085 SimpleInstallGetter(isolate_, prototype,
3086 factory->InternalizeUtf8String("description"),
3087 Builtin::kSymbolPrototypeDescriptionGetter, kAdapt);
3088
3089 // Install the @@toPrimitive function.
3090 InstallFunctionAtSymbol(
3091 isolate_, prototype, factory->to_primitive_symbol(),
3092 "[Symbol.toPrimitive]", Builtin::kSymbolPrototypeToPrimitive, 1, kAdapt,
3093 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
3094 }
3095
3096 { // --- D a t e ---
3097 DirectHandle<JSFunction> date_fun = InstallFunction(
3098 isolate_, global, "Date", JS_DATE_TYPE, JSDate::kHeaderSize, 0,
3099 factory->the_hole_value(), Builtin::kDateConstructor, 7, kDontAdapt);
3101 Context::DATE_FUNCTION_INDEX);
3102
3103 // Install the Date.now, Date.parse and Date.UTC functions.
3104 SimpleInstallFunction(isolate_, date_fun, "now", Builtin::kDateNow, 0,
3105 kDontAdapt);
3106 SimpleInstallFunction(isolate_, date_fun, "parse", Builtin::kDateParse, 1,
3107 kDontAdapt);
3108 SimpleInstallFunction(isolate_, date_fun, "UTC", Builtin::kDateUTC, 7,
3109 kDontAdapt);
3110
3111 // Setup %DatePrototype%.
3113 Cast<JSObject>(date_fun->instance_prototype()), isolate());
3114
3115 // Install the Date.prototype methods.
3116 SimpleInstallFunction(isolate_, prototype, "toString",
3117 Builtin::kDatePrototypeToString, 0, kDontAdapt);
3118 SimpleInstallFunction(isolate_, prototype, "toDateString",
3119 Builtin::kDatePrototypeToDateString, 0, kDontAdapt);
3120 SimpleInstallFunction(isolate_, prototype, "toTimeString",
3121 Builtin::kDatePrototypeToTimeString, 0, kDontAdapt);
3122 SimpleInstallFunction(isolate_, prototype, "toISOString",
3123 Builtin::kDatePrototypeToISOString, 0, kDontAdapt);
3125 isolate_, prototype, "toUTCString", Builtin::kDatePrototypeToUTCString,
3126 0, kDontAdapt);
3127 JSObject::AddProperty(isolate_, prototype, "toGMTString", to_utc_string,
3128 DONT_ENUM);
3129 SimpleInstallFunction(isolate_, prototype, "getDate",
3130 Builtin::kDatePrototypeGetDate, 0, kAdapt);
3131 SimpleInstallFunction(isolate_, prototype, "setDate",
3132 Builtin::kDatePrototypeSetDate, 1, kDontAdapt);
3133 SimpleInstallFunction(isolate_, prototype, "getDay",
3134 Builtin::kDatePrototypeGetDay, 0, kAdapt);
3135 SimpleInstallFunction(isolate_, prototype, "getFullYear",
3136 Builtin::kDatePrototypeGetFullYear, 0, kAdapt);
3137 SimpleInstallFunction(isolate_, prototype, "setFullYear",
3138 Builtin::kDatePrototypeSetFullYear, 3, kDontAdapt);
3139 SimpleInstallFunction(isolate_, prototype, "getHours",
3140 Builtin::kDatePrototypeGetHours, 0, kAdapt);
3141 SimpleInstallFunction(isolate_, prototype, "setHours",
3142 Builtin::kDatePrototypeSetHours, 4, kDontAdapt);
3143 SimpleInstallFunction(isolate_, prototype, "getMilliseconds",
3144 Builtin::kDatePrototypeGetMilliseconds, 0, kAdapt);
3145 SimpleInstallFunction(isolate_, prototype, "setMilliseconds",
3146 Builtin::kDatePrototypeSetMilliseconds, 1,
3147 kDontAdapt);
3148 SimpleInstallFunction(isolate_, prototype, "getMinutes",
3149 Builtin::kDatePrototypeGetMinutes, 0, kAdapt);
3150 SimpleInstallFunction(isolate_, prototype, "setMinutes",
3151 Builtin::kDatePrototypeSetMinutes, 3, kDontAdapt);
3152 SimpleInstallFunction(isolate_, prototype, "getMonth",
3153 Builtin::kDatePrototypeGetMonth, 0, kAdapt);
3154 SimpleInstallFunction(isolate_, prototype, "setMonth",
3155 Builtin::kDatePrototypeSetMonth, 2, kDontAdapt);
3156 SimpleInstallFunction(isolate_, prototype, "getSeconds",
3157 Builtin::kDatePrototypeGetSeconds, 0, kAdapt);
3158 SimpleInstallFunction(isolate_, prototype, "setSeconds",
3159 Builtin::kDatePrototypeSetSeconds, 2, kDontAdapt);
3160 SimpleInstallFunction(isolate_, prototype, "getTime",
3161 Builtin::kDatePrototypeGetTime, 0, kAdapt);
3162 SimpleInstallFunction(isolate_, prototype, "setTime",
3163 Builtin::kDatePrototypeSetTime, 1, kDontAdapt);
3164 SimpleInstallFunction(isolate_, prototype, "getTimezoneOffset",
3165 Builtin::kDatePrototypeGetTimezoneOffset, 0, kAdapt);
3166 SimpleInstallFunction(isolate_, prototype, "getUTCDate",
3167 Builtin::kDatePrototypeGetUTCDate, 0, kAdapt);
3168 SimpleInstallFunction(isolate_, prototype, "setUTCDate",
3169 Builtin::kDatePrototypeSetUTCDate, 1, kDontAdapt);
3170 SimpleInstallFunction(isolate_, prototype, "getUTCDay",
3171 Builtin::kDatePrototypeGetUTCDay, 0, kAdapt);
3172 SimpleInstallFunction(isolate_, prototype, "getUTCFullYear",
3173 Builtin::kDatePrototypeGetUTCFullYear, 0, kAdapt);
3174 SimpleInstallFunction(isolate_, prototype, "setUTCFullYear",
3175 Builtin::kDatePrototypeSetUTCFullYear, 3, kDontAdapt);
3176 SimpleInstallFunction(isolate_, prototype, "getUTCHours",
3177 Builtin::kDatePrototypeGetUTCHours, 0, kAdapt);
3178 SimpleInstallFunction(isolate_, prototype, "setUTCHours",
3179 Builtin::kDatePrototypeSetUTCHours, 4, kDontAdapt);
3180 SimpleInstallFunction(isolate_, prototype, "getUTCMilliseconds",
3181 Builtin::kDatePrototypeGetUTCMilliseconds, 0, kAdapt);
3182 SimpleInstallFunction(isolate_, prototype, "setUTCMilliseconds",
3183 Builtin::kDatePrototypeSetUTCMilliseconds, 1,
3184 kDontAdapt);
3185 SimpleInstallFunction(isolate_, prototype, "getUTCMinutes",
3186 Builtin::kDatePrototypeGetUTCMinutes, 0, kAdapt);
3187 SimpleInstallFunction(isolate_, prototype, "setUTCMinutes",
3188 Builtin::kDatePrototypeSetUTCMinutes, 3, kDontAdapt);
3189 SimpleInstallFunction(isolate_, prototype, "getUTCMonth",
3190 Builtin::kDatePrototypeGetUTCMonth, 0, kAdapt);
3191 SimpleInstallFunction(isolate_, prototype, "setUTCMonth",
3192 Builtin::kDatePrototypeSetUTCMonth, 2, kDontAdapt);
3193 SimpleInstallFunction(isolate_, prototype, "getUTCSeconds",
3194 Builtin::kDatePrototypeGetUTCSeconds, 0, kAdapt);
3195 SimpleInstallFunction(isolate_, prototype, "setUTCSeconds",
3196 Builtin::kDatePrototypeSetUTCSeconds, 2, kDontAdapt);
3197 SimpleInstallFunction(isolate_, prototype, "valueOf",
3198 Builtin::kDatePrototypeValueOf, 0, kAdapt);
3199 SimpleInstallFunction(isolate_, prototype, "getYear",
3200 Builtin::kDatePrototypeGetYear, 0, kAdapt);
3201 SimpleInstallFunction(isolate_, prototype, "setYear",
3202 Builtin::kDatePrototypeSetYear, 1, kDontAdapt);
3203 SimpleInstallFunction(isolate_, prototype, "toJSON",
3204 Builtin::kDatePrototypeToJson, 1, kDontAdapt);
3205
3206#ifdef V8_INTL_SUPPORT
3207 SimpleInstallFunction(isolate_, prototype, "toLocaleString",
3208 Builtin::kDatePrototypeToLocaleString, 0, kDontAdapt);
3209 SimpleInstallFunction(isolate_, prototype, "toLocaleDateString",
3210 Builtin::kDatePrototypeToLocaleDateString, 0,
3211 kDontAdapt);
3212 SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
3213 Builtin::kDatePrototypeToLocaleTimeString, 0,
3214 kDontAdapt);
3215#else
3216 // Install Intl fallback functions.
3217 SimpleInstallFunction(isolate_, prototype, "toLocaleString",
3218 Builtin::kDatePrototypeToString, 0, kDontAdapt);
3219 SimpleInstallFunction(isolate_, prototype, "toLocaleDateString",
3220 Builtin::kDatePrototypeToDateString, 0, kDontAdapt);
3221 SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
3222 Builtin::kDatePrototypeToTimeString, 0, kDontAdapt);
3223#endif // V8_INTL_SUPPORT
3224
3225 // Install the @@toPrimitive function.
3226 InstallFunctionAtSymbol(
3227 isolate_, prototype, factory->to_primitive_symbol(),
3228 "[Symbol.toPrimitive]", Builtin::kDatePrototypeToPrimitive, 1, kAdapt,
3229 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
3230 }
3231
3232 { // -- P r o m i s e
3233 DirectHandle<JSFunction> promise_fun = InstallFunction(
3234 isolate_, global, "Promise", JS_PROMISE_TYPE,
3235 JSPromise::kSizeWithEmbedderFields, 0, factory->the_hole_value(),
3236 Builtin::kPromiseConstructor, 1, kAdapt);
3238 Context::PROMISE_FUNCTION_INDEX);
3239
3240 InstallSpeciesGetter(isolate_, promise_fun);
3241
3242 DirectHandle<JSFunction> promise_all = InstallFunctionWithBuiltinId(
3243 isolate_, promise_fun, "all", Builtin::kPromiseAll, 1, kAdapt);
3244 native_context()->set_promise_all(*promise_all);
3245
3246 DirectHandle<JSFunction> promise_all_settled =
3247 InstallFunctionWithBuiltinId(isolate_, promise_fun, "allSettled",
3248 Builtin::kPromiseAllSettled, 1, kAdapt);
3249 native_context()->set_promise_all_settled(*promise_all_settled);
3250
3251 DirectHandle<JSFunction> promise_any = InstallFunctionWithBuiltinId(
3252 isolate_, promise_fun, "any", Builtin::kPromiseAny, 1, kAdapt);
3253 native_context()->set_promise_any(*promise_any);
3254
3255 InstallFunctionWithBuiltinId(isolate_, promise_fun, "race",
3256 Builtin::kPromiseRace, 1, kAdapt);
3257
3258 DirectHandle<JSFunction> promise_resolve = InstallFunctionWithBuiltinId(
3259 isolate_, promise_fun, "resolve", Builtin::kPromiseResolveTrampoline, 1,
3260 kAdapt);
3261 native_context()->set_promise_resolve(*promise_resolve);
3262
3263 InstallFunctionWithBuiltinId(isolate_, promise_fun, "reject",
3264 Builtin::kPromiseReject, 1, kAdapt);
3265
3266 std::array<DirectHandle<Name>, 3> fields{factory->promise_string(),
3267 factory->resolve_string(),
3268 factory->reject_string()};
3269 DirectHandle<Map> result_map =
3270 CreateLiteralObjectMapFromCache(isolate_, fields);
3271 native_context()->set_promise_withresolvers_result_map(*result_map);
3272 InstallFunctionWithBuiltinId(isolate_, promise_fun, "withResolvers",
3273 Builtin::kPromiseWithResolvers, 0, kAdapt);
3274
3275 SetConstructorInstanceType(isolate_, promise_fun,
3276 JS_PROMISE_CONSTRUCTOR_TYPE);
3277
3278 // Setup %PromisePrototype%.
3280 Cast<JSObject>(promise_fun->instance_prototype()), isolate());
3281 native_context()->set_promise_prototype(*prototype);
3282
3283 InstallToStringTag(isolate_, prototype, factory->Promise_string());
3284
3285 DirectHandle<JSFunction> promise_then = InstallFunctionWithBuiltinId(
3286 isolate_, prototype, "then", Builtin::kPromisePrototypeThen, 2, kAdapt);
3287 native_context()->set_promise_then(*promise_then);
3288
3289 DirectHandle<JSFunction> perform_promise_then =
3290 SimpleCreateFunction(isolate_, factory->empty_string(),
3291 Builtin::kPerformPromiseThenFunction, 2, kAdapt);
3292 native_context()->set_perform_promise_then(*perform_promise_then);
3293
3294 InstallFunctionWithBuiltinId(isolate_, prototype, "catch",
3295 Builtin::kPromisePrototypeCatch, 1, kAdapt);
3296
3297 InstallFunctionWithBuiltinId(isolate_, prototype, "finally",
3298 Builtin::kPromisePrototypeFinally, 1, kAdapt);
3299
3300 DCHECK(promise_fun->HasFastProperties());
3301
3302 DirectHandle<Map> prototype_map(prototype->map(), isolate());
3303 Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate_);
3304 CHECK_NE(prototype->map().ptr(),
3305 isolate_->initial_object_prototype()->map().ptr());
3306 prototype->map()->set_instance_type(JS_PROMISE_PROTOTYPE_TYPE);
3307
3308 DCHECK(promise_fun->HasFastProperties());
3309 }
3310
3311 { // -- R e g E x p
3312 // Builtin functions for RegExp.prototype.
3313 DirectHandle<JSFunction> regexp_fun = InstallFunction(
3314 isolate_, global, "RegExp", JS_REG_EXP_TYPE,
3315 JSRegExp::kHeaderSize + JSRegExp::kInObjectFieldCount * kTaggedSize,
3316 JSRegExp::kInObjectFieldCount, factory->the_hole_value(),
3317 Builtin::kRegExpConstructor, 2, kAdapt);
3319 Context::REGEXP_FUNCTION_INDEX);
3320
3321 {
3322 // Setup %RegExpPrototype%.
3324 Cast<JSObject>(regexp_fun->instance_prototype()), isolate());
3325 native_context()->set_regexp_prototype(*prototype);
3326
3327 {
3329 SimpleInstallFunction(isolate_, prototype, "exec",
3330 Builtin::kRegExpPrototypeExec, 1, kAdapt);
3331 native_context()->set_regexp_exec_function(*fun);
3333 prototype->map()->LastAdded().as_int());
3334 }
3335
3336 SimpleInstallGetter(isolate_, prototype, factory->dotAll_string(),
3337 Builtin::kRegExpPrototypeDotAllGetter, kAdapt);
3338 SimpleInstallGetter(isolate_, prototype, factory->flags_string(),
3339 Builtin::kRegExpPrototypeFlagsGetter, kAdapt);
3340 SimpleInstallGetter(isolate_, prototype, factory->global_string(),
3341 Builtin::kRegExpPrototypeGlobalGetter, kAdapt);
3342 SimpleInstallGetter(isolate(), prototype, factory->hasIndices_string(),
3343 Builtin::kRegExpPrototypeHasIndicesGetter, kAdapt);
3344 SimpleInstallGetter(isolate_, prototype, factory->ignoreCase_string(),
3345 Builtin::kRegExpPrototypeIgnoreCaseGetter, kAdapt);
3346 SimpleInstallGetter(isolate_, prototype, factory->multiline_string(),
3347 Builtin::kRegExpPrototypeMultilineGetter, kAdapt);
3348 SimpleInstallGetter(isolate_, prototype, factory->source_string(),
3349 Builtin::kRegExpPrototypeSourceGetter, kAdapt);
3350 SimpleInstallGetter(isolate_, prototype, factory->sticky_string(),
3351 Builtin::kRegExpPrototypeStickyGetter, kAdapt);
3352 SimpleInstallGetter(isolate_, prototype, factory->unicode_string(),
3353 Builtin::kRegExpPrototypeUnicodeGetter, kAdapt);
3354 SimpleInstallGetter(isolate(), prototype, factory->unicodeSets_string(),
3355 Builtin::kRegExpPrototypeUnicodeSetsGetter, kAdapt);
3356
3357 SimpleInstallFunction(isolate_, prototype, "compile",
3358 Builtin::kRegExpPrototypeCompile, 2, kAdapt);
3359 SimpleInstallFunction(isolate_, prototype, "toString",
3360 Builtin::kRegExpPrototypeToString, 0, kDontAdapt);
3361 SimpleInstallFunction(isolate_, prototype, "test",
3362 Builtin::kRegExpPrototypeTest, 1, kAdapt);
3363
3364 {
3365 DirectHandle<JSFunction> fun = InstallFunctionAtSymbol(
3366 isolate_, prototype, factory->match_symbol(), "[Symbol.match]",
3367 Builtin::kRegExpPrototypeMatch, 1, kAdapt);
3368 native_context()->set_regexp_match_function(*fun);
3370 prototype->map()->LastAdded().as_int());
3371 }
3372
3373 {
3374 DirectHandle<JSFunction> fun = InstallFunctionAtSymbol(
3375 isolate_, prototype, factory->match_all_symbol(),
3376 "[Symbol.matchAll]", Builtin::kRegExpPrototypeMatchAll, 1, kAdapt);
3377 native_context()->set_regexp_match_all_function(*fun);
3379 prototype->map()->LastAdded().as_int());
3380 }
3381
3382 {
3383 DirectHandle<JSFunction> fun = InstallFunctionAtSymbol(
3384 isolate_, prototype, factory->replace_symbol(), "[Symbol.replace]",
3385 Builtin::kRegExpPrototypeReplace, 2, kDontAdapt);
3386 native_context()->set_regexp_replace_function(*fun);
3388 prototype->map()->LastAdded().as_int());
3389 }
3390
3391 {
3392 DirectHandle<JSFunction> fun = InstallFunctionAtSymbol(
3393 isolate_, prototype, factory->search_symbol(), "[Symbol.search]",
3394 Builtin::kRegExpPrototypeSearch, 1, kAdapt);
3395 native_context()->set_regexp_search_function(*fun);
3397 prototype->map()->LastAdded().as_int());
3398 }
3399
3400 {
3401 DirectHandle<JSFunction> fun = InstallFunctionAtSymbol(
3402 isolate_, prototype, factory->split_symbol(), "[Symbol.split]",
3403 Builtin::kRegExpPrototypeSplit, 2, kDontAdapt);
3404 native_context()->set_regexp_split_function(*fun);
3406 prototype->map()->LastAdded().as_int());
3407 }
3408
3409 DirectHandle<Map> prototype_map(prototype->map(), isolate());
3410 Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate_);
3411 CHECK_NE((*prototype_map).ptr(),
3412 isolate_->initial_object_prototype()->map().ptr());
3413 prototype_map->set_instance_type(JS_REG_EXP_PROTOTYPE_TYPE);
3414
3415 // Store the initial RegExp.prototype map. This is used in fast-path
3416 // checks. Do not alter the prototype after this point.
3417 native_context()->set_regexp_prototype_map(*prototype_map);
3418 }
3419
3420 {
3421 // RegExp getters and setters.
3422
3423 InstallSpeciesGetter(isolate_, regexp_fun);
3424
3425 // Static properties set by a successful match.
3426
3427 SimpleInstallGetterSetter(isolate_, regexp_fun, factory->input_string(),
3428 Builtin::kRegExpInputGetter,
3429 Builtin::kRegExpInputSetter);
3430 SimpleInstallGetterSetter(isolate_, regexp_fun, "$_",
3431 Builtin::kRegExpInputGetter,
3432 Builtin::kRegExpInputSetter);
3433
3434 SimpleInstallGetterSetter(isolate_, regexp_fun, "lastMatch",
3435 Builtin::kRegExpLastMatchGetter,
3436 Builtin::kEmptyFunction1);
3437 SimpleInstallGetterSetter(isolate_, regexp_fun, "$&",
3438 Builtin::kRegExpLastMatchGetter,
3439 Builtin::kEmptyFunction1);
3440
3441 SimpleInstallGetterSetter(isolate_, regexp_fun, "lastParen",
3442 Builtin::kRegExpLastParenGetter,
3443 Builtin::kEmptyFunction1);
3444 SimpleInstallGetterSetter(isolate_, regexp_fun, "$+",
3445 Builtin::kRegExpLastParenGetter,
3446 Builtin::kEmptyFunction1);
3447
3448 SimpleInstallGetterSetter(isolate_, regexp_fun, "leftContext",
3449 Builtin::kRegExpLeftContextGetter,
3450 Builtin::kEmptyFunction1);
3451 SimpleInstallGetterSetter(isolate_, regexp_fun, "$`",
3452 Builtin::kRegExpLeftContextGetter,
3453 Builtin::kEmptyFunction1);
3454
3455 SimpleInstallGetterSetter(isolate_, regexp_fun, "rightContext",
3456 Builtin::kRegExpRightContextGetter,
3457 Builtin::kEmptyFunction1);
3458 SimpleInstallGetterSetter(isolate_, regexp_fun, "$'",
3459 Builtin::kRegExpRightContextGetter,
3460 Builtin::kEmptyFunction1);
3461
3462#define INSTALL_CAPTURE_GETTER(i) \
3463 SimpleInstallGetterSetter(isolate_, regexp_fun, "$" #i, \
3464 Builtin::kRegExpCapture##i##Getter, \
3465 Builtin::kEmptyFunction1)
3475#undef INSTALL_CAPTURE_GETTER
3476 }
3477 SetConstructorInstanceType(isolate_, regexp_fun,
3478 JS_REG_EXP_CONSTRUCTOR_TYPE);
3479
3480 DCHECK(regexp_fun->has_initial_map());
3481 DirectHandle<Map> initial_map(regexp_fun->initial_map(), isolate());
3482
3483 DCHECK_EQ(1, initial_map->GetInObjectProperties());
3484
3485 Map::EnsureDescriptorSlack(isolate_, initial_map, 1);
3486
3487 // ECMA-262, section 15.10.7.5.
3488 PropertyAttributes writable =
3490 Descriptor d = Descriptor::DataField(isolate(), factory->lastIndex_string(),
3492 writable, Representation::Tagged());
3493 initial_map->AppendDescriptor(isolate(), &d);
3494
3495 // Create the last match info.
3496 DirectHandle<RegExpMatchInfo> last_match_info =
3498 native_context()->set_regexp_last_match_info(*last_match_info);
3499
3500 // Install the species protector cell.
3502 native_context()->set_regexp_species_protector(*cell);
3503
3504 DCHECK(regexp_fun->HasFastProperties());
3505 }
3506
3507 { // --- R e g E x p S t r i n g I t e r a t o r ---
3508 DirectHandle<JSObject> iterator_prototype(
3509 native_context()->initial_iterator_prototype(), isolate());
3510
3511 DirectHandle<JSObject> regexp_string_iterator_prototype =
3512 factory->NewJSObject(isolate()->object_function(),
3514 JSObject::ForceSetPrototype(isolate(), regexp_string_iterator_prototype,
3515 iterator_prototype);
3516
3517 InstallToStringTag(isolate(), regexp_string_iterator_prototype,
3518 "RegExp String Iterator");
3519
3520 SimpleInstallFunction(isolate(), regexp_string_iterator_prototype, "next",
3521 Builtin::kRegExpStringIteratorPrototypeNext, 0,
3522 kAdapt);
3523
3524 DirectHandle<JSFunction> regexp_string_iterator_function = CreateFunction(
3525 isolate(), "RegExpStringIterator", JS_REG_EXP_STRING_ITERATOR_TYPE,
3526 JSRegExpStringIterator::kHeaderSize, 0,
3527 regexp_string_iterator_prototype, Builtin::kIllegal, 0, kDontAdapt);
3528 regexp_string_iterator_function->shared()->set_native(false);
3529 native_context()->set_initial_regexp_string_iterator_prototype_map(
3530 regexp_string_iterator_function->initial_map());
3531 }
3532
3533 // -- E r r o r
3534 InstallError(isolate_, global, factory->Error_string(),
3535 Context::ERROR_FUNCTION_INDEX);
3536
3537 // -- A g g r e g a t e E r r o r
3538 InstallError(isolate_, global, factory->AggregateError_string(),
3539 Context::AGGREGATE_ERROR_FUNCTION_INDEX,
3540 Builtin::kAggregateErrorConstructor, 2);
3541
3542 // -- E v a l E r r o r
3543 InstallError(isolate_, global, factory->EvalError_string(),
3544 Context::EVAL_ERROR_FUNCTION_INDEX);
3545
3546 // -- R a n g e E r r o r
3547 InstallError(isolate_, global, factory->RangeError_string(),
3548 Context::RANGE_ERROR_FUNCTION_INDEX);
3549
3550 // -- R e f e r e n c e E r r o r
3551 InstallError(isolate_, global, factory->ReferenceError_string(),
3552 Context::REFERENCE_ERROR_FUNCTION_INDEX);
3553
3554 // -- S y n t a x E r r o r
3555 InstallError(isolate_, global, factory->SyntaxError_string(),
3556 Context::SYNTAX_ERROR_FUNCTION_INDEX);
3557
3558 // -- T y p e E r r o r
3559 InstallError(isolate_, global, factory->TypeError_string(),
3560 Context::TYPE_ERROR_FUNCTION_INDEX);
3561
3562 // -- U R I E r r o r
3563 InstallError(isolate_, global, factory->URIError_string(),
3564 Context::URI_ERROR_FUNCTION_INDEX);
3565
3566 // Initialize the embedder data slot.
3567 // TODO(ishell): microtask queue pointer will be moved from native context
3568 // to the embedder data array so we don't need an empty embedder data array.
3569 DirectHandle<EmbedderDataArray> embedder_data =
3571 native_context()->set_embedder_data(*embedder_data);
3572
3573 { // -- g l o b a l T h i s
3575 isolate_);
3576 JSObject::AddProperty(isolate_, global, factory->globalThis_string(),
3578 }
3579
3580 { // -- J S O N
3582 JS_RAW_JSON_TYPE, JSRawJson::kInitialSize, TERMINAL_FAST_ELEMENTS_KIND,
3583 1);
3584 Map::EnsureDescriptorSlack(isolate_, raw_json_map, 1);
3585 {
3587 isolate(), factory->raw_json_string(),
3589 raw_json_map->AppendDescriptor(isolate(), &d);
3590 }
3591 raw_json_map->SetPrototype(isolate(), raw_json_map, factory->null_value());
3592 raw_json_map->SetConstructor(native_context()->object_function());
3593 native_context()->set_js_raw_json_map(*raw_json_map);
3594
3595 DirectHandle<JSObject> json_object =
3596 factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
3597 JSObject::AddProperty(isolate_, global, "JSON", json_object, DONT_ENUM);
3598 SimpleInstallFunction(isolate_, json_object, "parse", Builtin::kJsonParse,
3599 2, kDontAdapt);
3600 SimpleInstallFunction(isolate_, json_object, "stringify",
3601 Builtin::kJsonStringify, 3, kAdapt);
3602 SimpleInstallFunction(isolate_, json_object, "rawJSON",
3603 Builtin::kJsonRawJson, 1, kAdapt);
3604 SimpleInstallFunction(isolate_, json_object, "isRawJSON",
3605 Builtin::kJsonIsRawJson, 1, kAdapt);
3606 InstallToStringTag(isolate_, json_object, "JSON");
3607 native_context()->set_json_object(*json_object);
3608 }
3609
3610 { // -- M a t h
3612 factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
3613 JSObject::AddProperty(isolate_, global, "Math", math, DONT_ENUM);
3614 SimpleInstallFunction(isolate_, math, "abs", Builtin::kMathAbs, 1, kAdapt);
3615 SimpleInstallFunction(isolate_, math, "acos", Builtin::kMathAcos, 1,
3616 kAdapt);
3617 SimpleInstallFunction(isolate_, math, "acosh", Builtin::kMathAcosh, 1,
3618 kAdapt);
3619 SimpleInstallFunction(isolate_, math, "asin", Builtin::kMathAsin, 1,
3620 kAdapt);
3621 SimpleInstallFunction(isolate_, math, "asinh", Builtin::kMathAsinh, 1,
3622 kAdapt);
3623 SimpleInstallFunction(isolate_, math, "atan", Builtin::kMathAtan, 1,
3624 kAdapt);
3625 SimpleInstallFunction(isolate_, math, "atanh", Builtin::kMathAtanh, 1,
3626 kAdapt);
3627 SimpleInstallFunction(isolate_, math, "atan2", Builtin::kMathAtan2, 2,
3628 kAdapt);
3629 SimpleInstallFunction(isolate_, math, "ceil", Builtin::kMathCeil, 1,
3630 kAdapt);
3631 SimpleInstallFunction(isolate_, math, "cbrt", Builtin::kMathCbrt, 1,
3632 kAdapt);
3633 SimpleInstallFunction(isolate_, math, "expm1", Builtin::kMathExpm1, 1,
3634 kAdapt);
3635 SimpleInstallFunction(isolate_, math, "clz32", Builtin::kMathClz32, 1,
3636 kAdapt);
3637 SimpleInstallFunction(isolate_, math, "cos", Builtin::kMathCos, 1, kAdapt);
3638 SimpleInstallFunction(isolate_, math, "cosh", Builtin::kMathCosh, 1,
3639 kAdapt);
3640 SimpleInstallFunction(isolate_, math, "exp", Builtin::kMathExp, 1, kAdapt);
3641 SimpleInstallFunction(isolate_, math, "floor", Builtin::kMathFloor, 1,
3642 kAdapt);
3643 SimpleInstallFunction(isolate_, math, "fround", Builtin::kMathFround, 1,
3644 kAdapt);
3645 SimpleInstallFunction(isolate_, math, "hypot", Builtin::kMathHypot, 2,
3646 kDontAdapt);
3647 SimpleInstallFunction(isolate_, math, "imul", Builtin::kMathImul, 2,
3648 kAdapt);
3649 SimpleInstallFunction(isolate_, math, "log", Builtin::kMathLog, 1, kAdapt);
3650 SimpleInstallFunction(isolate_, math, "log1p", Builtin::kMathLog1p, 1,
3651 kAdapt);
3652 SimpleInstallFunction(isolate_, math, "log2", Builtin::kMathLog2, 1,
3653 kAdapt);
3654 SimpleInstallFunction(isolate_, math, "log10", Builtin::kMathLog10, 1,
3655 kAdapt);
3656 SimpleInstallFunction(isolate_, math, "max", Builtin::kMathMax, 2,
3657 kDontAdapt);
3658 SimpleInstallFunction(isolate_, math, "min", Builtin::kMathMin, 2,
3659 kDontAdapt);
3660 SimpleInstallFunction(isolate_, math, "pow", Builtin::kMathPow, 2, kAdapt);
3661 SimpleInstallFunction(isolate_, math, "random", Builtin::kMathRandom, 0,
3662 kAdapt);
3663 SimpleInstallFunction(isolate_, math, "round", Builtin::kMathRound, 1,
3664 kAdapt);
3665 SimpleInstallFunction(isolate_, math, "sign", Builtin::kMathSign, 1,
3666 kAdapt);
3667 SimpleInstallFunction(isolate_, math, "sin", Builtin::kMathSin, 1, kAdapt);
3668 SimpleInstallFunction(isolate_, math, "sinh", Builtin::kMathSinh, 1,
3669 kAdapt);
3670 SimpleInstallFunction(isolate_, math, "sqrt", Builtin::kMathSqrt, 1,
3671 kAdapt);
3672 SimpleInstallFunction(isolate_, math, "tan", Builtin::kMathTan, 1, kAdapt);
3673 SimpleInstallFunction(isolate_, math, "tanh", Builtin::kMathTanh, 1,
3674 kAdapt);
3675 SimpleInstallFunction(isolate_, math, "trunc", Builtin::kMathTrunc, 1,
3676 kAdapt);
3677
3678 // Install math constants.
3679 double const kE = base::ieee754::exp(1.0);
3680 double const kPI = 3.1415926535897932;
3681 InstallConstant(isolate_, math, "E", factory->NewNumber(kE));
3682 InstallConstant(isolate_, math, "LN10",
3684 InstallConstant(isolate_, math, "LN2",
3686 InstallConstant(isolate_, math, "LOG10E",
3688 InstallConstant(isolate_, math, "LOG2E",
3690 InstallConstant(isolate_, math, "PI", factory->NewNumber(kPI));
3691 InstallConstant(isolate_, math, "SQRT1_2",
3692 factory->NewNumber(std::sqrt(0.5)));
3693 InstallConstant(isolate_, math, "SQRT2",
3694 factory->NewNumber(std::sqrt(2.0)));
3695 InstallToStringTag(isolate_, math, "Math");
3696 }
3697
3698#ifdef V8_INTL_SUPPORT
3699 { // -- I n t l
3701 factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
3702 JSObject::AddProperty(isolate_, global, "Intl", intl, DONT_ENUM);
3703
3704 // ecma402 #sec-Intl-toStringTag
3705 // The initial value of the @@toStringTag property is the string value
3706 // *"Intl"*.
3707 InstallToStringTag(isolate_, intl, "Intl");
3708
3709 SimpleInstallFunction(isolate(), intl, "getCanonicalLocales",
3710 Builtin::kIntlGetCanonicalLocales, 1, kDontAdapt);
3711
3712 SimpleInstallFunction(isolate(), intl, "supportedValuesOf",
3713 Builtin::kIntlSupportedValuesOf, 1, kDontAdapt);
3714
3715 { // -- D a t e T i m e F o r m a t
3716 DirectHandle<JSFunction> date_time_format_constructor = InstallFunction(
3717 isolate_, intl, "DateTimeFormat", JS_DATE_TIME_FORMAT_TYPE,
3718 JSDateTimeFormat::kHeaderSize, 0, factory->the_hole_value(),
3719 Builtin::kDateTimeFormatConstructor, 0, kDontAdapt);
3721 isolate_, date_time_format_constructor,
3722 Context::INTL_DATE_TIME_FORMAT_FUNCTION_INDEX);
3723
3725 isolate(), date_time_format_constructor, "supportedLocalesOf",
3726 Builtin::kDateTimeFormatSupportedLocalesOf, 1, kDontAdapt);
3727
3729 Cast<JSObject>(date_time_format_constructor->prototype()), isolate_);
3730
3731 InstallToStringTag(isolate_, prototype, "Intl.DateTimeFormat");
3732
3733 SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
3734 Builtin::kDateTimeFormatPrototypeResolvedOptions, 0,
3735 kDontAdapt);
3736
3737 SimpleInstallFunction(isolate_, prototype, "formatToParts",
3738 Builtin::kDateTimeFormatPrototypeFormatToParts, 1,
3739 kDontAdapt);
3740
3741 SimpleInstallGetter(isolate_, prototype, factory->format_string(),
3742 Builtin::kDateTimeFormatPrototypeFormat, kDontAdapt);
3743
3744 SimpleInstallFunction(isolate_, prototype, "formatRange",
3745 Builtin::kDateTimeFormatPrototypeFormatRange, 2,
3746 kDontAdapt);
3747 SimpleInstallFunction(isolate_, prototype, "formatRangeToParts",
3748 Builtin::kDateTimeFormatPrototypeFormatRangeToParts,
3749 2, kDontAdapt);
3750 }
3751
3752 { // -- N u m b e r F o r m a t
3753 DirectHandle<JSFunction> number_format_constructor = InstallFunction(
3754 isolate_, intl, "NumberFormat", JS_NUMBER_FORMAT_TYPE,
3755 JSNumberFormat::kHeaderSize, 0, factory->the_hole_value(),
3756 Builtin::kNumberFormatConstructor, 0, kDontAdapt);
3758 isolate_, number_format_constructor,
3759 Context::INTL_NUMBER_FORMAT_FUNCTION_INDEX);
3760
3762 isolate(), number_format_constructor, "supportedLocalesOf",
3763 Builtin::kNumberFormatSupportedLocalesOf, 1, kDontAdapt);
3764
3766 Cast<JSObject>(number_format_constructor->prototype()), isolate_);
3767
3768 InstallToStringTag(isolate_, prototype, "Intl.NumberFormat");
3769
3770 SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
3771 Builtin::kNumberFormatPrototypeResolvedOptions, 0,
3772 kDontAdapt);
3773
3774 SimpleInstallFunction(isolate_, prototype, "formatToParts",
3775 Builtin::kNumberFormatPrototypeFormatToParts, 1,
3776 kDontAdapt);
3777 SimpleInstallGetter(isolate_, prototype, factory->format_string(),
3778 Builtin::kNumberFormatPrototypeFormatNumber,
3779 kDontAdapt);
3780
3781 SimpleInstallFunction(isolate(), prototype, "formatRange",
3782 Builtin::kNumberFormatPrototypeFormatRange, 2,
3783 kDontAdapt);
3784 SimpleInstallFunction(isolate(), prototype, "formatRangeToParts",
3785 Builtin::kNumberFormatPrototypeFormatRangeToParts,
3786 2, kDontAdapt);
3787 }
3788
3789 { // -- C o l l a t o r
3790 DirectHandle<JSFunction> collator_constructor =
3791 InstallFunction(isolate_, intl, "Collator", JS_COLLATOR_TYPE,
3792 JSCollator::kHeaderSize, 0, factory->the_hole_value(),
3793 Builtin::kCollatorConstructor, 0, kDontAdapt);
3794 InstallWithIntrinsicDefaultProto(isolate_, collator_constructor,
3795 Context::INTL_COLLATOR_FUNCTION_INDEX);
3796
3798 isolate(), collator_constructor, "supportedLocalesOf",
3799 Builtin::kCollatorSupportedLocalesOf, 1, kDontAdapt);
3800
3802 Cast<JSObject>(collator_constructor->prototype()), isolate_);
3803
3804 InstallToStringTag(isolate_, prototype, "Intl.Collator");
3805
3806 SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
3807 Builtin::kCollatorPrototypeResolvedOptions, 0,
3808 kDontAdapt);
3809
3810 SimpleInstallGetter(isolate_, prototype, factory->compare_string(),
3811 Builtin::kCollatorPrototypeCompare, kDontAdapt);
3812 }
3813
3814 { // -- V 8 B r e a k I t e r a t o r
3815 DirectHandle<JSFunction> v8_break_iterator_constructor = InstallFunction(
3816 isolate_, intl, "v8BreakIterator", JS_V8_BREAK_ITERATOR_TYPE,
3817 JSV8BreakIterator::kHeaderSize, 0, factory->the_hole_value(),
3818 Builtin::kV8BreakIteratorConstructor, 0, kDontAdapt);
3819
3821 isolate_, v8_break_iterator_constructor, "supportedLocalesOf",
3822 Builtin::kV8BreakIteratorSupportedLocalesOf, 1, kDontAdapt);
3823
3825 Cast<JSObject>(v8_break_iterator_constructor->prototype()), isolate_);
3826
3827 InstallToStringTag(isolate_, prototype, factory->Object_string());
3828
3829 SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
3830 Builtin::kV8BreakIteratorPrototypeResolvedOptions,
3831 0, kDontAdapt);
3832
3833 SimpleInstallGetter(isolate_, prototype, factory->adoptText_string(),
3834 Builtin::kV8BreakIteratorPrototypeAdoptText,
3835 kDontAdapt);
3836
3837 SimpleInstallGetter(isolate_, prototype, factory->first_string(),
3838 Builtin::kV8BreakIteratorPrototypeFirst, kDontAdapt);
3839
3840 SimpleInstallGetter(isolate_, prototype, factory->next_string(),
3841 Builtin::kV8BreakIteratorPrototypeNext, kDontAdapt);
3842
3843 SimpleInstallGetter(isolate_, prototype, factory->current_string(),
3844 Builtin::kV8BreakIteratorPrototypeCurrent,
3845 kDontAdapt);
3846
3847 SimpleInstallGetter(isolate_, prototype, factory->breakType_string(),
3848 Builtin::kV8BreakIteratorPrototypeBreakType,
3849 kDontAdapt);
3850 }
3851
3852 { // -- P l u r a l R u l e s
3853 DirectHandle<JSFunction> plural_rules_constructor = InstallFunction(
3854 isolate_, intl, "PluralRules", JS_PLURAL_RULES_TYPE,
3855 JSPluralRules::kHeaderSize, 0, factory->the_hole_value(),
3856 Builtin::kPluralRulesConstructor, 0, kDontAdapt);
3858 isolate_, plural_rules_constructor,
3859 Context::INTL_PLURAL_RULES_FUNCTION_INDEX);
3860
3862 isolate(), plural_rules_constructor, "supportedLocalesOf",
3863 Builtin::kPluralRulesSupportedLocalesOf, 1, kDontAdapt);
3864
3866 Cast<JSObject>(plural_rules_constructor->prototype()), isolate_);
3867
3868 InstallToStringTag(isolate_, prototype, "Intl.PluralRules");
3869
3870 SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
3871 Builtin::kPluralRulesPrototypeResolvedOptions, 0,
3872 kDontAdapt);
3873
3874 SimpleInstallFunction(isolate_, prototype, "select",
3875 Builtin::kPluralRulesPrototypeSelect, 1,
3876 kDontAdapt);
3877
3878 SimpleInstallFunction(isolate(), prototype, "selectRange",
3879 Builtin::kPluralRulesPrototypeSelectRange, 2,
3880 kDontAdapt);
3881 }
3882
3883 { // -- R e l a t i v e T i m e F o r m a t
3884 DirectHandle<JSFunction> relative_time_format_fun = InstallFunction(
3885 isolate(), intl, "RelativeTimeFormat", JS_RELATIVE_TIME_FORMAT_TYPE,
3886 JSRelativeTimeFormat::kHeaderSize, 0, factory->the_hole_value(),
3887 Builtin::kRelativeTimeFormatConstructor, 0, kDontAdapt);
3889 isolate_, relative_time_format_fun,
3890 Context::INTL_RELATIVE_TIME_FORMAT_FUNCTION_INDEX);
3891
3893 isolate(), relative_time_format_fun, "supportedLocalesOf",
3894 Builtin::kRelativeTimeFormatSupportedLocalesOf, 1, kDontAdapt);
3895
3896 // Setup %RelativeTimeFormatPrototype%.
3898 Cast<JSObject>(relative_time_format_fun->instance_prototype()),
3899 isolate());
3900
3901 InstallToStringTag(isolate(), prototype, "Intl.RelativeTimeFormat");
3902
3904 isolate(), prototype, "resolvedOptions",
3905 Builtin::kRelativeTimeFormatPrototypeResolvedOptions, 0, kDontAdapt);
3906 SimpleInstallFunction(isolate(), prototype, "format",
3907 Builtin::kRelativeTimeFormatPrototypeFormat, 2,
3908 kDontAdapt);
3909 SimpleInstallFunction(isolate(), prototype, "formatToParts",
3910 Builtin::kRelativeTimeFormatPrototypeFormatToParts,
3911 2, kDontAdapt);
3912 }
3913
3914 { // -- L i s t F o r m a t
3915 DirectHandle<JSFunction> list_format_fun = InstallFunction(
3916 isolate(), intl, "ListFormat", JS_LIST_FORMAT_TYPE,
3917 JSListFormat::kHeaderSize, 0, factory->the_hole_value(),
3918 Builtin::kListFormatConstructor, 0, kDontAdapt);
3920 isolate_, list_format_fun, Context::INTL_LIST_FORMAT_FUNCTION_INDEX);
3921
3922 SimpleInstallFunction(isolate(), list_format_fun, "supportedLocalesOf",
3923 Builtin::kListFormatSupportedLocalesOf, 1,
3924 kDontAdapt);
3925
3926 // Setup %ListFormatPrototype%.
3928 Cast<JSObject>(list_format_fun->instance_prototype()), isolate());
3929
3930 InstallToStringTag(isolate(), prototype, "Intl.ListFormat");
3931
3932 SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
3933 Builtin::kListFormatPrototypeResolvedOptions, 0,
3934 kDontAdapt);
3935 SimpleInstallFunction(isolate(), prototype, "format",
3936 Builtin::kListFormatPrototypeFormat, 1, kDontAdapt);
3937 SimpleInstallFunction(isolate(), prototype, "formatToParts",
3938 Builtin::kListFormatPrototypeFormatToParts, 1,
3939 kDontAdapt);
3940 }
3941
3942 { // -- L o c a l e
3943 DirectHandle<JSFunction> locale_fun =
3944 InstallFunction(isolate(), intl, "Locale", JS_LOCALE_TYPE,
3945 JSLocale::kHeaderSize, 0, factory->the_hole_value(),
3946 Builtin::kLocaleConstructor, 1, kDontAdapt);
3948 Context::INTL_LOCALE_FUNCTION_INDEX);
3949
3950 // Setup %LocalePrototype%.
3952 Cast<JSObject>(locale_fun->instance_prototype()), isolate());
3953
3954 InstallToStringTag(isolate(), prototype, "Intl.Locale");
3955
3956 SimpleInstallFunction(isolate(), prototype, "toString",
3957 Builtin::kLocalePrototypeToString, 0, kDontAdapt);
3958 SimpleInstallFunction(isolate(), prototype, "maximize",
3959 Builtin::kLocalePrototypeMaximize, 0, kDontAdapt);
3960 SimpleInstallFunction(isolate(), prototype, "minimize",
3961 Builtin::kLocalePrototypeMinimize, 0, kDontAdapt);
3962 // Base locale getters.
3963 SimpleInstallGetter(isolate(), prototype, factory->language_string(),
3964 Builtin::kLocalePrototypeLanguage, kAdapt);
3965 SimpleInstallGetter(isolate(), prototype, factory->script_string(),
3966 Builtin::kLocalePrototypeScript, kAdapt);
3967 SimpleInstallGetter(isolate(), prototype, factory->region_string(),
3968 Builtin::kLocalePrototypeRegion, kAdapt);
3969 SimpleInstallGetter(isolate(), prototype, factory->baseName_string(),
3970 Builtin::kLocalePrototypeBaseName, kAdapt);
3971 // Unicode extension getters.
3972 SimpleInstallGetter(isolate(), prototype, factory->calendar_string(),
3973 Builtin::kLocalePrototypeCalendar, kAdapt);
3974 SimpleInstallGetter(isolate(), prototype, factory->caseFirst_string(),
3975 Builtin::kLocalePrototypeCaseFirst, kAdapt);
3976 SimpleInstallGetter(isolate(), prototype, factory->collation_string(),
3977 Builtin::kLocalePrototypeCollation, kAdapt);
3978 SimpleInstallGetter(isolate(), prototype,
3979 factory->firstDayOfWeek_string(),
3980 Builtin::kLocalePrototypeFirstDayOfWeek, kAdapt);
3981 SimpleInstallGetter(isolate(), prototype, factory->hourCycle_string(),
3982 Builtin::kLocalePrototypeHourCycle, kAdapt);
3983 SimpleInstallGetter(isolate(), prototype, factory->numeric_string(),
3984 Builtin::kLocalePrototypeNumeric, kAdapt);
3985 SimpleInstallGetter(isolate(), prototype,
3986 factory->numberingSystem_string(),
3987 Builtin::kLocalePrototypeNumberingSystem, kAdapt);
3988
3989 if (!v8_flags.harmony_remove_intl_locale_info_getters) {
3990 // Intl Locale Info functions
3991 SimpleInstallGetter(isolate(), prototype, factory->calendars_string(),
3992 Builtin::kLocalePrototypeCalendars, kAdapt);
3993 SimpleInstallGetter(isolate(), prototype, factory->collations_string(),
3994 Builtin::kLocalePrototypeCollations, kAdapt);
3995 SimpleInstallGetter(isolate(), prototype, factory->hourCycles_string(),
3996 Builtin::kLocalePrototypeHourCycles, kAdapt);
3997 SimpleInstallGetter(isolate(), prototype,
3998 factory->numberingSystems_string(),
3999 Builtin::kLocalePrototypeNumberingSystems, kAdapt);
4000 SimpleInstallGetter(isolate(), prototype, factory->textInfo_string(),
4001 Builtin::kLocalePrototypeTextInfo, kAdapt);
4002 SimpleInstallGetter(isolate(), prototype, factory->timeZones_string(),
4003 Builtin::kLocalePrototypeTimeZones, kAdapt);
4004 SimpleInstallGetter(isolate(), prototype, factory->weekInfo_string(),
4005 Builtin::kLocalePrototypeWeekInfo, kAdapt);
4006 }
4007
4008 SimpleInstallFunction(isolate(), prototype, "getCalendars",
4009 Builtin::kLocalePrototypeGetCalendars, 0,
4010 kDontAdapt);
4011 SimpleInstallFunction(isolate(), prototype, "getCollations",
4012 Builtin::kLocalePrototypeGetCollations, 0,
4013 kDontAdapt);
4014 SimpleInstallFunction(isolate(), prototype, "getHourCycles",
4015 Builtin::kLocalePrototypeGetHourCycles, 0,
4016 kDontAdapt);
4017 SimpleInstallFunction(isolate(), prototype, "getNumberingSystems",
4018 Builtin::kLocalePrototypeGetNumberingSystems, 0,
4019 kDontAdapt);
4020 SimpleInstallFunction(isolate(), prototype, "getTimeZones",
4021 Builtin::kLocalePrototypeGetTimeZones, 0,
4022 kDontAdapt);
4023 SimpleInstallFunction(isolate(), prototype, "getTextInfo",
4024 Builtin::kLocalePrototypeGetTextInfo, 0,
4025 kDontAdapt);
4026 SimpleInstallFunction(isolate(), prototype, "getWeekInfo",
4027 Builtin::kLocalePrototypeGetWeekInfo, 0,
4028 kDontAdapt);
4029 }
4030
4031 { // -- D i s p l a y N a m e s
4032 DirectHandle<JSFunction> display_names_fun = InstallFunction(
4033 isolate(), intl, "DisplayNames", JS_DISPLAY_NAMES_TYPE,
4034 JSDisplayNames::kHeaderSize, 0, factory->the_hole_value(),
4035 Builtin::kDisplayNamesConstructor, 2, kDontAdapt);
4037 isolate(), display_names_fun,
4038 Context::INTL_DISPLAY_NAMES_FUNCTION_INDEX);
4039
4040 SimpleInstallFunction(isolate(), display_names_fun, "supportedLocalesOf",
4041 Builtin::kDisplayNamesSupportedLocalesOf, 1,
4042 kDontAdapt);
4043
4044 {
4045 // Setup %DisplayNamesPrototype%.
4047 Cast<JSObject>(display_names_fun->instance_prototype()), isolate());
4048
4049 InstallToStringTag(isolate(), prototype, "Intl.DisplayNames");
4050
4051 SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
4052 Builtin::kDisplayNamesPrototypeResolvedOptions, 0,
4053 kDontAdapt);
4054
4055 SimpleInstallFunction(isolate(), prototype, "of",
4056 Builtin::kDisplayNamesPrototypeOf, 1, kDontAdapt);
4057 }
4058 }
4059
4060 { // -- S e g m e n t e r
4061 DirectHandle<JSFunction> segmenter_fun = InstallFunction(
4062 isolate(), intl, "Segmenter", JS_SEGMENTER_TYPE,
4063 JSSegmenter::kHeaderSize, 0, factory->the_hole_value(),
4064 Builtin::kSegmenterConstructor, 0, kDontAdapt);
4066 Context::INTL_SEGMENTER_FUNCTION_INDEX);
4067 SimpleInstallFunction(isolate(), segmenter_fun, "supportedLocalesOf",
4068 Builtin::kSegmenterSupportedLocalesOf, 1,
4069 kDontAdapt);
4070 {
4071 // Setup %SegmenterPrototype%.
4073 Cast<JSObject>(segmenter_fun->instance_prototype()), isolate());
4074 // #sec-intl.segmenter.prototype-@@tostringtag
4075 //
4076 // Intl.Segmenter.prototype [ @@toStringTag ]
4077 //
4078 // The initial value of the @@toStringTag property is the String value
4079 // "Intl.Segmenter".
4080 InstallToStringTag(isolate(), prototype, "Intl.Segmenter");
4081 SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
4082 Builtin::kSegmenterPrototypeResolvedOptions, 0,
4083 kDontAdapt);
4084 SimpleInstallFunction(isolate(), prototype, "segment",
4085 Builtin::kSegmenterPrototypeSegment, 1,
4086 kDontAdapt);
4087 }
4088 {
4089 // Setup %SegmentsPrototype%.
4091 isolate()->object_function(), AllocationType::kOld);
4092 DirectHandle<String> name_string =
4093 Name::ToFunctionName(isolate(), factory->Segments_string())
4094 .ToHandleChecked();
4095 DirectHandle<JSFunction> segments_fun = CreateFunction(
4096 isolate(), name_string, JS_SEGMENTS_TYPE, JSSegments::kHeaderSize,
4097 0, prototype, Builtin::kIllegal, 0, kDontAdapt);
4098 segments_fun->shared()->set_native(false);
4099 SimpleInstallFunction(isolate(), prototype, "containing",
4100 Builtin::kSegmentsPrototypeContaining, 1,
4101 kDontAdapt);
4102 InstallFunctionAtSymbol(isolate_, prototype, factory->iterator_symbol(),
4103 "[Symbol.iterator]",
4104 Builtin::kSegmentsPrototypeIterator, 0, kAdapt,
4105 DONT_ENUM);
4106 DirectHandle<Map> segments_map(segments_fun->initial_map(), isolate());
4107 native_context()->set_intl_segments_map(*segments_map);
4108 }
4109 {
4110 // Setup %SegmentIteratorPrototype%.
4111 DirectHandle<JSObject> iterator_prototype(
4112 native_context()->initial_iterator_prototype(), isolate());
4114 isolate()->object_function(), AllocationType::kOld);
4115 JSObject::ForceSetPrototype(isolate(), prototype, iterator_prototype);
4116 // #sec-%segmentiteratorprototype%.@@tostringtag
4117 //
4118 // %SegmentIteratorPrototype% [ @@toStringTag ]
4119 //
4120 // The initial value of the @@toStringTag property is the String value
4121 // "Segmenter String Iterator".
4122 InstallToStringTag(isolate(), prototype, "Segmenter String Iterator");
4123 SimpleInstallFunction(isolate(), prototype, "next",
4124 Builtin::kSegmentIteratorPrototypeNext, 0,
4125 kDontAdapt);
4126 // Setup SegmentIterator constructor.
4127 DirectHandle<String> name_string =
4128 Name::ToFunctionName(isolate(), factory->SegmentIterator_string())
4129 .ToHandleChecked();
4130 DirectHandle<JSFunction> segment_iterator_fun =
4131 CreateFunction(isolate(), name_string, JS_SEGMENT_ITERATOR_TYPE,
4132 JSSegmentIterator::kHeaderSize, 0, prototype,
4133 Builtin::kIllegal, 0, kDontAdapt);
4134 segment_iterator_fun->shared()->set_native(false);
4135 DirectHandle<Map> segment_iterator_map(
4136 segment_iterator_fun->initial_map(), isolate());
4137 native_context()->set_intl_segment_iterator_map(*segment_iterator_map);
4138 }
4139 {
4140 // Set up the maps for SegmentDataObjects, with and without "isWordLike"
4141 // property.
4142 constexpr int kNumProperties = 3;
4143 constexpr int kNumPropertiesWithWordlike = kNumProperties + 1;
4144 constexpr int kInstanceSize =
4145 JSObject::kHeaderSize + kNumProperties * kTaggedSize;
4146 constexpr int kInstanceSizeWithWordlike =
4147 JSObject::kHeaderSize + kNumPropertiesWithWordlike * kTaggedSize;
4149 JS_OBJECT_TYPE, kInstanceSize, TERMINAL_FAST_ELEMENTS_KIND,
4150 kNumProperties);
4151 DirectHandle<Map> map_with_wordlike =
4153 JS_OBJECT_TYPE, kInstanceSizeWithWordlike,
4154 TERMINAL_FAST_ELEMENTS_KIND, kNumPropertiesWithWordlike);
4155 map->SetConstructor(native_context()->object_function());
4156 map_with_wordlike->SetConstructor(native_context()->object_function());
4157 map->set_prototype(*isolate_->initial_object_prototype());
4158 map_with_wordlike->set_prototype(*isolate_->initial_object_prototype());
4159 Map::EnsureDescriptorSlack(isolate_, map, kNumProperties);
4160 Map::EnsureDescriptorSlack(isolate_, map_with_wordlike,
4161 kNumPropertiesWithWordlike);
4162 int index = 0;
4163 { // segment
4164 Descriptor d =
4165 Descriptor::DataField(isolate_, factory->segment_string(),
4166 index++, NONE, Representation::Tagged());
4167 map->AppendDescriptor(isolate_, &d);
4168 map_with_wordlike->AppendDescriptor(isolate_, &d);
4169 }
4170 { // index
4171 Descriptor d =
4172 Descriptor::DataField(isolate_, factory->index_string(), index++,
4174 map->AppendDescriptor(isolate_, &d);
4175 map_with_wordlike->AppendDescriptor(isolate_, &d);
4176 }
4177 { // input
4178 Descriptor d =
4179 Descriptor::DataField(isolate_, factory->input_string(), index++,
4181 map->AppendDescriptor(isolate_, &d);
4182 map_with_wordlike->AppendDescriptor(isolate_, &d);
4183 }
4184 DCHECK_EQ(index, kNumProperties);
4185 { // isWordLike
4186 Descriptor d =
4187 Descriptor::DataField(isolate_, factory->isWordLike_string(),
4188 index++, NONE, Representation::Tagged());
4189 map_with_wordlike->AppendDescriptor(isolate_, &d);
4190 }
4191 DCHECK_EQ(index, kNumPropertiesWithWordlike);
4192 DCHECK(!map->is_dictionary_map());
4193 DCHECK(!map_with_wordlike->is_dictionary_map());
4194 native_context()->set_intl_segment_data_object_map(*map);
4195 native_context()->set_intl_segment_data_object_wordlike_map(
4196 *map_with_wordlike);
4197 }
4198 }
4199
4200 { // -- D u r a t i o n F o r m a t
4201 DirectHandle<JSFunction> duration_format_fun = InstallFunction(
4202 isolate(), intl, "DurationFormat", JS_DURATION_FORMAT_TYPE,
4203 JSDurationFormat::kHeaderSize, 0, factory->the_hole_value(),
4204 Builtin::kDurationFormatConstructor, 0, kDontAdapt);
4206 isolate(), duration_format_fun,
4207 Context::INTL_DURATION_FORMAT_FUNCTION_INDEX);
4208
4210 isolate(), duration_format_fun, "supportedLocalesOf",
4211 Builtin::kDurationFormatSupportedLocalesOf, 1, kDontAdapt);
4212
4214 Cast<JSObject>(duration_format_fun->instance_prototype()), isolate());
4215
4216 InstallToStringTag(isolate(), prototype, "Intl.DurationFormat");
4217
4218 SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
4219 Builtin::kDurationFormatPrototypeResolvedOptions, 0,
4220 kDontAdapt);
4221
4222 SimpleInstallFunction(isolate(), prototype, "format",
4223 Builtin::kDurationFormatPrototypeFormat, 1,
4224 kDontAdapt);
4225 SimpleInstallFunction(isolate(), prototype, "formatToParts",
4226 Builtin::kDurationFormatPrototypeFormatToParts, 1,
4227 kDontAdapt);
4228 }
4229 }
4230#endif // V8_INTL_SUPPORT
4231
4232 { // -- A r r a y B u f f e r
4233 DirectHandle<String> name = factory->ArrayBuffer_string();
4234 DirectHandle<JSFunction> array_buffer_fun =
4236 JSObject::AddProperty(isolate_, global, name, array_buffer_fun, DONT_ENUM);
4238 Context::ARRAY_BUFFER_FUN_INDEX);
4239 InstallSpeciesGetter(isolate_, array_buffer_fun);
4240
4241 DirectHandle<JSFunction> array_buffer_noinit_fun = SimpleCreateFunction(
4242 isolate_,
4244 "arrayBufferConstructor_DoNotInitialize"),
4245 Builtin::kArrayBufferConstructor_DoNotInitialize, 1, kDontAdapt);
4246 native_context()->set_array_buffer_noinit_fun(*array_buffer_noinit_fun);
4247
4248 DirectHandle<JSObject> array_buffer_prototype(
4249 Cast<JSObject>(array_buffer_fun->instance_prototype()), isolate_);
4250 SimpleInstallGetter(isolate_, array_buffer_prototype,
4251 factory->max_byte_length_string(),
4252 Builtin::kArrayBufferPrototypeGetMaxByteLength, kAdapt);
4253 SimpleInstallGetter(isolate_, array_buffer_prototype,
4254 factory->resizable_string(),
4255 Builtin::kArrayBufferPrototypeGetResizable, kAdapt);
4256 SimpleInstallFunction(isolate_, array_buffer_prototype, "resize",
4257 Builtin::kArrayBufferPrototypeResize, 1, kAdapt);
4258 SimpleInstallFunction(isolate_, array_buffer_prototype, "transfer",
4259 Builtin::kArrayBufferPrototypeTransfer, 0,
4260 kDontAdapt);
4262 isolate_, array_buffer_prototype, "transferToFixedLength",
4263 Builtin::kArrayBufferPrototypeTransferToFixedLength, 0, kDontAdapt);
4264 SimpleInstallGetter(isolate_, array_buffer_prototype,
4265 factory->detached_string(),
4266 Builtin::kArrayBufferPrototypeGetDetached, kAdapt);
4267 }
4268
4269 { // -- S h a r e d A r r a y B u f f e r
4270 DirectHandle<String> name = factory->SharedArrayBuffer_string();
4271 DirectHandle<JSFunction> shared_array_buffer_fun =
4273 InstallWithIntrinsicDefaultProto(isolate_, shared_array_buffer_fun,
4274 Context::SHARED_ARRAY_BUFFER_FUN_INDEX);
4275 InstallSpeciesGetter(isolate_, shared_array_buffer_fun);
4276
4277 DirectHandle<JSObject> shared_array_buffer_prototype(
4278 Cast<JSObject>(shared_array_buffer_fun->instance_prototype()),
4279 isolate_);
4280 SimpleInstallGetter(isolate_, shared_array_buffer_prototype,
4281 factory->max_byte_length_string(),
4282 Builtin::kSharedArrayBufferPrototypeGetMaxByteLength,
4283 kAdapt);
4284 SimpleInstallGetter(
4285 isolate_, shared_array_buffer_prototype, factory->growable_string(),
4286 Builtin::kSharedArrayBufferPrototypeGetGrowable, kAdapt);
4287 SimpleInstallFunction(isolate_, shared_array_buffer_prototype, "grow",
4288 Builtin::kSharedArrayBufferPrototypeGrow, 1, kAdapt);
4289 }
4290
4291 { // -- A t o m i c s
4292 DirectHandle<JSObject> atomics_object =
4293 factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
4294 JSObject::AddProperty(isolate_, global, "Atomics", atomics_object,
4295 DONT_ENUM);
4296 InstallToStringTag(isolate_, atomics_object, "Atomics");
4297
4298 SimpleInstallFunction(isolate_, atomics_object, "load",
4299 Builtin::kAtomicsLoad, 2, kAdapt);
4300 SimpleInstallFunction(isolate_, atomics_object, "store",
4301 Builtin::kAtomicsStore, 3, kAdapt);
4302 SimpleInstallFunction(isolate_, atomics_object, "add", Builtin::kAtomicsAdd,
4303 3, kAdapt);
4304 SimpleInstallFunction(isolate_, atomics_object, "sub", Builtin::kAtomicsSub,
4305 3, kAdapt);
4306 SimpleInstallFunction(isolate_, atomics_object, "and", Builtin::kAtomicsAnd,
4307 3, kAdapt);
4308 SimpleInstallFunction(isolate_, atomics_object, "or", Builtin::kAtomicsOr,
4309 3, kAdapt);
4310 SimpleInstallFunction(isolate_, atomics_object, "xor", Builtin::kAtomicsXor,
4311 3, kAdapt);
4312 SimpleInstallFunction(isolate_, atomics_object, "exchange",
4313 Builtin::kAtomicsExchange, 3, kAdapt);
4314 SimpleInstallFunction(isolate_, atomics_object, "compareExchange",
4315 Builtin::kAtomicsCompareExchange, 4, kAdapt);
4316 SimpleInstallFunction(isolate_, atomics_object, "isLockFree",
4317 Builtin::kAtomicsIsLockFree, 1, kAdapt);
4318 SimpleInstallFunction(isolate_, atomics_object, "wait",
4319 Builtin::kAtomicsWait, 4, kAdapt);
4320 SimpleInstallFunction(isolate(), atomics_object, "waitAsync",
4321 Builtin::kAtomicsWaitAsync, 4, kAdapt);
4322 SimpleInstallFunction(isolate_, atomics_object, "notify",
4323 Builtin::kAtomicsNotify, 3, kAdapt);
4324 }
4325
4326 { // -- T y p e d A r r a y
4327 DirectHandle<JSFunction> typed_array_fun =
4328 CreateFunction(isolate_, factory->InternalizeUtf8String("TypedArray"),
4329 JS_TYPED_ARRAY_TYPE, JSTypedArray::kHeaderSize, 0,
4330 factory->the_hole_value(),
4331 Builtin::kTypedArrayBaseConstructor, 0, kAdapt);
4332 typed_array_fun->shared()->set_native(false);
4333 InstallSpeciesGetter(isolate_, typed_array_fun);
4334 native_context()->set_typed_array_function(*typed_array_fun);
4335
4336 SimpleInstallFunction(isolate_, typed_array_fun, "of",
4337 Builtin::kTypedArrayOf, 0, kDontAdapt);
4338 SimpleInstallFunction(isolate_, typed_array_fun, "from",
4339 Builtin::kTypedArrayFrom, 1, kDontAdapt);
4340
4341 // Setup %TypedArrayPrototype%.
4343 Cast<JSObject>(typed_array_fun->instance_prototype()), isolate());
4344 native_context()->set_typed_array_prototype(*prototype);
4345
4346 // Install the "buffer", "byteOffset", "byteLength", "length"
4347 // and @@toStringTag getters on the {prototype}.
4348 SimpleInstallGetter(isolate_, prototype, factory->buffer_string(),
4349 Builtin::kTypedArrayPrototypeBuffer, kDontAdapt);
4350 SimpleInstallGetter(isolate_, prototype, factory->byte_length_string(),
4351 Builtin::kTypedArrayPrototypeByteLength, kAdapt);
4352 SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
4353 Builtin::kTypedArrayPrototypeByteOffset, kAdapt);
4354 SimpleInstallGetter(isolate_, prototype, factory->length_string(),
4355 Builtin::kTypedArrayPrototypeLength, kAdapt);
4356 SimpleInstallGetter(isolate_, prototype, factory->to_string_tag_symbol(),
4357 Builtin::kTypedArrayPrototypeToStringTag, kAdapt);
4358
4359 // Install "keys", "values" and "entries" methods on the {prototype}.
4360 InstallFunctionWithBuiltinId(isolate_, prototype, "entries",
4361 Builtin::kTypedArrayPrototypeEntries, 0,
4362 kDontAdapt);
4363
4364 InstallFunctionWithBuiltinId(isolate_, prototype, "keys",
4365 Builtin::kTypedArrayPrototypeKeys, 0,
4366 kDontAdapt);
4367
4368 DirectHandle<JSFunction> values = InstallFunctionWithBuiltinId(
4369 isolate_, prototype, "values", Builtin::kTypedArrayPrototypeValues, 0,
4370 kDontAdapt);
4371 JSObject::AddProperty(isolate_, prototype, factory->iterator_symbol(),
4372 values, DONT_ENUM);
4373
4374 // TODO(caitp): alphasort accessors/methods
4375 SimpleInstallFunction(isolate_, prototype, "at",
4376 Builtin::kTypedArrayPrototypeAt, 1, kAdapt);
4377 SimpleInstallFunction(isolate_, prototype, "copyWithin",
4378 Builtin::kTypedArrayPrototypeCopyWithin, 2,
4379 kDontAdapt);
4380 SimpleInstallFunction(isolate_, prototype, "every",
4381 Builtin::kTypedArrayPrototypeEvery, 1, kDontAdapt);
4382 SimpleInstallFunction(isolate_, prototype, "fill",
4383 Builtin::kTypedArrayPrototypeFill, 1, kDontAdapt);
4384 SimpleInstallFunction(isolate_, prototype, "filter",
4385 Builtin::kTypedArrayPrototypeFilter, 1, kDontAdapt);
4386 SimpleInstallFunction(isolate_, prototype, "find",
4387 Builtin::kTypedArrayPrototypeFind, 1, kDontAdapt);
4388 SimpleInstallFunction(isolate_, prototype, "findIndex",
4389 Builtin::kTypedArrayPrototypeFindIndex, 1,
4390 kDontAdapt);
4391 SimpleInstallFunction(isolate_, prototype, "findLast",
4392 Builtin::kTypedArrayPrototypeFindLast, 1, kDontAdapt);
4393 SimpleInstallFunction(isolate_, prototype, "findLastIndex",
4394 Builtin::kTypedArrayPrototypeFindLastIndex, 1,
4395 kDontAdapt);
4396 SimpleInstallFunction(isolate_, prototype, "forEach",
4397 Builtin::kTypedArrayPrototypeForEach, 1, kDontAdapt);
4398 SimpleInstallFunction(isolate_, prototype, "includes",
4399 Builtin::kTypedArrayPrototypeIncludes, 1, kDontAdapt);
4400 SimpleInstallFunction(isolate_, prototype, "indexOf",
4401 Builtin::kTypedArrayPrototypeIndexOf, 1, kDontAdapt);
4402 SimpleInstallFunction(isolate_, prototype, "join",
4403 Builtin::kTypedArrayPrototypeJoin, 1, kDontAdapt);
4404 SimpleInstallFunction(isolate_, prototype, "lastIndexOf",
4405 Builtin::kTypedArrayPrototypeLastIndexOf, 1,
4406 kDontAdapt);
4407 SimpleInstallFunction(isolate_, prototype, "map",
4408 Builtin::kTypedArrayPrototypeMap, 1, kDontAdapt);
4409 SimpleInstallFunction(isolate_, prototype, "reverse",
4410 Builtin::kTypedArrayPrototypeReverse, 0, kDontAdapt);
4411 SimpleInstallFunction(isolate_, prototype, "reduce",
4412 Builtin::kTypedArrayPrototypeReduce, 1, kDontAdapt);
4413 SimpleInstallFunction(isolate_, prototype, "reduceRight",
4414 Builtin::kTypedArrayPrototypeReduceRight, 1,
4415 kDontAdapt);
4416 SimpleInstallFunction(isolate_, prototype, "set",
4417 Builtin::kTypedArrayPrototypeSet, 1, kDontAdapt);
4418 SimpleInstallFunction(isolate_, prototype, "slice",
4419 Builtin::kTypedArrayPrototypeSlice, 2, kDontAdapt);
4420 SimpleInstallFunction(isolate_, prototype, "some",
4421 Builtin::kTypedArrayPrototypeSome, 1, kDontAdapt);
4422 SimpleInstallFunction(isolate_, prototype, "sort",
4423 Builtin::kTypedArrayPrototypeSort, 1, kDontAdapt);
4424 SimpleInstallFunction(isolate_, prototype, "subarray",
4425 Builtin::kTypedArrayPrototypeSubArray, 2, kDontAdapt);
4426 SimpleInstallFunction(isolate_, prototype, "toReversed",
4427 Builtin::kTypedArrayPrototypeToReversed, 0,
4428 kDontAdapt);
4429 SimpleInstallFunction(isolate_, prototype, "toSorted",
4430 Builtin::kTypedArrayPrototypeToSorted, 1, kDontAdapt);
4431 SimpleInstallFunction(isolate_, prototype, "with",
4432 Builtin::kTypedArrayPrototypeWith, 2, kAdapt);
4433 SimpleInstallFunction(isolate_, prototype, "toLocaleString",
4434 Builtin::kTypedArrayPrototypeToLocaleString, 0,
4435 kDontAdapt);
4436 JSObject::AddProperty(isolate_, prototype, factory->toString_string(),
4437 array_prototype_to_string_fun, DONT_ENUM);
4438 }
4439
4440 { // -- T y p e d A r r a y s
4441#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype) \
4442 { \
4443 DirectHandle<JSFunction> fun = InstallTypedArray( \
4444 #Type "Array", TYPE##_ELEMENTS, TYPE##_TYPED_ARRAY_CONSTRUCTOR_TYPE, \
4445 Context::RAB_GSAB_##TYPE##_ARRAY_MAP_INDEX); \
4446 InstallWithIntrinsicDefaultProto(isolate_, fun, \
4447 Context::TYPE##_ARRAY_FUN_INDEX); \
4448 }
4450#undef INSTALL_TYPED_ARRAY
4451 }
4452
4453 { // -- D a t a V i e w
4454 DirectHandle<JSFunction> data_view_fun = InstallFunction(
4455 isolate_, global, "DataView", JS_DATA_VIEW_TYPE,
4456 JSDataView::kSizeWithEmbedderFields, 0, factory->the_hole_value(),
4457 Builtin::kDataViewConstructor, 1, kDontAdapt);
4459 Context::DATA_VIEW_FUN_INDEX);
4460
4461 // Setup %DataViewPrototype%.
4463 Cast<JSObject>(data_view_fun->instance_prototype()), isolate());
4464
4465 InstallToStringTag(isolate_, prototype, "DataView");
4466
4467 // Setup objects needed for the JSRabGsabDataView.
4468 DirectHandle<Map> rab_gsab_data_view_map =
4470 JS_RAB_GSAB_DATA_VIEW_TYPE, JSDataView::kSizeWithEmbedderFields,
4472 Map::SetPrototype(isolate(), rab_gsab_data_view_map, prototype);
4473 rab_gsab_data_view_map->SetConstructor(*data_view_fun);
4474 native_context()->set_js_rab_gsab_data_view_map(*rab_gsab_data_view_map);
4475
4476 // Install the "buffer", "byteOffset" and "byteLength" getters
4477 // on the {prototype}.
4478 SimpleInstallGetter(isolate_, prototype, factory->buffer_string(),
4479 Builtin::kDataViewPrototypeGetBuffer, kDontAdapt);
4480 SimpleInstallGetter(isolate_, prototype, factory->byte_length_string(),
4481 Builtin::kDataViewPrototypeGetByteLength, kDontAdapt);
4482 SimpleInstallGetter(isolate_, prototype, factory->byte_offset_string(),
4483 Builtin::kDataViewPrototypeGetByteOffset, kDontAdapt);
4484
4485 SimpleInstallFunction(isolate_, prototype, "getInt8",
4486 Builtin::kDataViewPrototypeGetInt8, 1, kDontAdapt);
4487 SimpleInstallFunction(isolate_, prototype, "setInt8",
4488 Builtin::kDataViewPrototypeSetInt8, 2, kDontAdapt);
4489 SimpleInstallFunction(isolate_, prototype, "getUint8",
4490 Builtin::kDataViewPrototypeGetUint8, 1, kDontAdapt);
4491 SimpleInstallFunction(isolate_, prototype, "setUint8",
4492 Builtin::kDataViewPrototypeSetUint8, 2, kDontAdapt);
4493 SimpleInstallFunction(isolate_, prototype, "getInt16",
4494 Builtin::kDataViewPrototypeGetInt16, 1, kDontAdapt);
4495 SimpleInstallFunction(isolate_, prototype, "setInt16",
4496 Builtin::kDataViewPrototypeSetInt16, 2, kDontAdapt);
4497 SimpleInstallFunction(isolate_, prototype, "getUint16",
4498 Builtin::kDataViewPrototypeGetUint16, 1, kDontAdapt);
4499 SimpleInstallFunction(isolate_, prototype, "setUint16",
4500 Builtin::kDataViewPrototypeSetUint16, 2, kDontAdapt);
4501 SimpleInstallFunction(isolate_, prototype, "getInt32",
4502 Builtin::kDataViewPrototypeGetInt32, 1, kDontAdapt);
4503 SimpleInstallFunction(isolate_, prototype, "setInt32",
4504 Builtin::kDataViewPrototypeSetInt32, 2, kDontAdapt);
4505 SimpleInstallFunction(isolate_, prototype, "getUint32",
4506 Builtin::kDataViewPrototypeGetUint32, 1, kDontAdapt);
4507 SimpleInstallFunction(isolate_, prototype, "setUint32",
4508 Builtin::kDataViewPrototypeSetUint32, 2, kDontAdapt);
4509 SimpleInstallFunction(isolate_, prototype, "getFloat32",
4510 Builtin::kDataViewPrototypeGetFloat32, 1, kDontAdapt);
4511 SimpleInstallFunction(isolate_, prototype, "setFloat32",
4512 Builtin::kDataViewPrototypeSetFloat32, 2, kDontAdapt);
4513 SimpleInstallFunction(isolate_, prototype, "getFloat64",
4514 Builtin::kDataViewPrototypeGetFloat64, 1, kDontAdapt);
4515 SimpleInstallFunction(isolate_, prototype, "setFloat64",
4516 Builtin::kDataViewPrototypeSetFloat64, 2, kDontAdapt);
4517 SimpleInstallFunction(isolate_, prototype, "getBigInt64",
4518 Builtin::kDataViewPrototypeGetBigInt64, 1,
4519 kDontAdapt);
4520 SimpleInstallFunction(isolate_, prototype, "setBigInt64",
4521 Builtin::kDataViewPrototypeSetBigInt64, 2,
4522 kDontAdapt);
4523 SimpleInstallFunction(isolate_, prototype, "getBigUint64",
4524 Builtin::kDataViewPrototypeGetBigUint64, 1,
4525 kDontAdapt);
4526 SimpleInstallFunction(isolate_, prototype, "setBigUint64",
4527 Builtin::kDataViewPrototypeSetBigUint64, 2,
4528 kDontAdapt);
4529 }
4530
4531 { // -- M a p
4532 DirectHandle<JSFunction> js_map_fun = InstallFunction(
4533 isolate_, global, "Map", JS_MAP_TYPE, JSMap::kHeaderSize, 0,
4534 factory->the_hole_value(), Builtin::kMapConstructor, 0, kDontAdapt);
4536 Context::JS_MAP_FUN_INDEX);
4537
4538 SimpleInstallFunction(isolate_, js_map_fun, "groupBy", Builtin::kMapGroupBy,
4539 2, kAdapt);
4540
4541 // Setup %MapPrototype%.
4543 Cast<JSObject>(js_map_fun->instance_prototype()), isolate());
4544
4545 InstallToStringTag(isolate_, prototype, factory->Map_string());
4546
4548 isolate_, prototype, "get", Builtin::kMapPrototypeGet, 1, kAdapt);
4549 native_context()->set_map_get(*map_get);
4550
4552 isolate_, prototype, "set", Builtin::kMapPrototypeSet, 2, kAdapt);
4553 // Check that index of "set" function in JSCollection is correct.
4555 prototype->map()->LastAdded().as_int());
4556 native_context()->set_map_set(*map_set);
4557
4559 isolate_, prototype, "has", Builtin::kMapPrototypeHas, 1, kAdapt);
4560 native_context()->set_map_has(*map_has);
4561
4563 isolate_, prototype, "delete", Builtin::kMapPrototypeDelete, 1, kAdapt);
4564 native_context()->set_map_delete(*map_delete);
4565
4566 SimpleInstallFunction(isolate_, prototype, "clear",
4567 Builtin::kMapPrototypeClear, 0, kAdapt);
4569 SimpleInstallFunction(isolate_, prototype, "entries",
4570 Builtin::kMapPrototypeEntries, 0, kAdapt);
4571 JSObject::AddProperty(isolate_, prototype, factory->iterator_symbol(),
4573 SimpleInstallFunction(isolate_, prototype, "forEach",
4574 Builtin::kMapPrototypeForEach, 1, kDontAdapt);
4575 SimpleInstallFunction(isolate_, prototype, "keys",
4576 Builtin::kMapPrototypeKeys, 0, kAdapt);
4577 SimpleInstallGetter(isolate_, prototype,
4579 Builtin::kMapPrototypeGetSize, kAdapt);
4580 SimpleInstallFunction(isolate_, prototype, "values",
4581 Builtin::kMapPrototypeValues, 0, kAdapt);
4582
4583 native_context()->set_initial_map_prototype_map(prototype->map());
4584
4585 InstallSpeciesGetter(isolate_, js_map_fun);
4586
4587 DCHECK(js_map_fun->HasFastProperties());
4588
4589 native_context()->set_js_map_map(js_map_fun->initial_map());
4590 }
4591
4592 { // -- B i g I n t
4593 DirectHandle<JSFunction> bigint_fun = InstallFunction(
4594 isolate_, global, "BigInt", JS_PRIMITIVE_WRAPPER_TYPE,
4595 JSPrimitiveWrapper::kHeaderSize, 0, factory->the_hole_value(),
4596 Builtin::kBigIntConstructor, 1, kDontAdapt);
4598 Context::BIGINT_FUNCTION_INDEX);
4599
4600 // Install the properties of the BigInt constructor.
4601 // asUintN(bits, bigint)
4602 SimpleInstallFunction(isolate_, bigint_fun, "asUintN",
4603 Builtin::kBigIntAsUintN, 2, kDontAdapt);
4604 // asIntN(bits, bigint)
4605 SimpleInstallFunction(isolate_, bigint_fun, "asIntN",
4606 Builtin::kBigIntAsIntN, 2, kDontAdapt);
4607
4608 // Set up the %BigIntPrototype%.
4610 Cast<JSObject>(bigint_fun->instance_prototype()), isolate_);
4611 JSFunction::SetPrototype(bigint_fun, prototype);
4612
4613 // Install the properties of the BigInt.prototype.
4614 // "constructor" is created implicitly by InstallFunction() above.
4615 // toLocaleString([reserved1 [, reserved2]])
4616 SimpleInstallFunction(isolate_, prototype, "toLocaleString",
4617 Builtin::kBigIntPrototypeToLocaleString, 0,
4618 kDontAdapt);
4619 // toString([radix])
4620 SimpleInstallFunction(isolate_, prototype, "toString",
4621 Builtin::kBigIntPrototypeToString, 0, kDontAdapt);
4622 // valueOf()
4623 SimpleInstallFunction(isolate_, prototype, "valueOf",
4624 Builtin::kBigIntPrototypeValueOf, 0, kDontAdapt);
4625 // @@toStringTag
4626 InstallToStringTag(isolate_, prototype, factory->BigInt_string());
4627 }
4628
4629 { // -- S e t
4630 DirectHandle<JSFunction> js_set_fun = InstallFunction(
4631 isolate_, global, "Set", JS_SET_TYPE, JSSet::kHeaderSize, 0,
4632 factory->the_hole_value(), Builtin::kSetConstructor, 0, kDontAdapt);
4634 Context::JS_SET_FUN_INDEX);
4635
4636 // Setup %SetPrototype%.
4638 Cast<JSObject>(js_set_fun->instance_prototype()), isolate());
4639
4640 InstallToStringTag(isolate_, prototype, factory->Set_string());
4641
4643 isolate_, prototype, "has", Builtin::kSetPrototypeHas, 1, kAdapt);
4644 native_context()->set_set_has(*set_has);
4645
4647 isolate_, prototype, "add", Builtin::kSetPrototypeAdd, 1, kAdapt);
4648 // Check that index of "add" function in JSCollection is correct.
4650 prototype->map()->LastAdded().as_int());
4651 native_context()->set_set_add(*set_add);
4652
4654 isolate_, prototype, "delete", Builtin::kSetPrototypeDelete, 1, kAdapt);
4655 native_context()->set_set_delete(*set_delete);
4656
4657 SimpleInstallFunction(isolate_, prototype, "difference",
4658 Builtin::kSetPrototypeDifference, 1, kAdapt);
4659 SimpleInstallFunction(isolate_, prototype, "clear",
4660 Builtin::kSetPrototypeClear, 0, kAdapt);
4661 SimpleInstallFunction(isolate_, prototype, "entries",
4662 Builtin::kSetPrototypeEntries, 0, kAdapt);
4663 SimpleInstallFunction(isolate_, prototype, "forEach",
4664 Builtin::kSetPrototypeForEach, 1, kDontAdapt);
4665 SimpleInstallFunction(isolate_, prototype, "intersection",
4666 Builtin::kSetPrototypeIntersection, 1, kAdapt);
4667 SimpleInstallFunction(isolate_, prototype, "isSubsetOf",
4668 Builtin::kSetPrototypeIsSubsetOf, 1, kAdapt);
4669 SimpleInstallFunction(isolate_, prototype, "isSupersetOf",
4670 Builtin::kSetPrototypeIsSupersetOf, 1, kAdapt);
4671 SimpleInstallFunction(isolate_, prototype, "isDisjointFrom",
4672 Builtin::kSetPrototypeIsDisjointFrom, 1, kAdapt);
4673 SimpleInstallGetter(isolate_, prototype,
4675 Builtin::kSetPrototypeGetSize, kAdapt);
4676 SimpleInstallFunction(isolate_, prototype, "symmetricDifference",
4677 Builtin::kSetPrototypeSymmetricDifference, 1, kAdapt);
4678 SimpleInstallFunction(isolate_, prototype, "union",
4679 Builtin::kSetPrototypeUnion, 1, kAdapt);
4680
4682 isolate_, prototype, "values", Builtin::kSetPrototypeValues, 0, kAdapt);
4683 JSObject::AddProperty(isolate_, prototype, factory->keys_string(), values,
4684 DONT_ENUM);
4685 JSObject::AddProperty(isolate_, prototype, factory->iterator_symbol(),
4686 values, DONT_ENUM);
4687
4688 native_context()->set_initial_set_prototype_map(prototype->map());
4689 native_context()->set_initial_set_prototype(*prototype);
4690
4691 InstallSpeciesGetter(isolate_, js_set_fun);
4692
4693 DCHECK(js_set_fun->HasFastProperties());
4694
4695 native_context()->set_js_set_map(js_set_fun->initial_map());
4696 CHECK_NE(prototype->map().ptr(),
4697 isolate_->initial_object_prototype()->map().ptr());
4698 prototype->map()->set_instance_type(JS_SET_PROTOTYPE_TYPE);
4699 }
4700
4701 { // -- J S M o d u l e N a m e s p a c e
4703 JS_MODULE_NAMESPACE_TYPE, JSModuleNamespace::kSize,
4705 map->SetConstructor(native_context()->object_function());
4706 Map::SetPrototype(isolate(), map, isolate_->factory()->null_value());
4708 native_context()->set_js_module_namespace_map(*map);
4709
4710 { // Install @@toStringTag.
4711 PropertyAttributes attribs =
4713 Descriptor d =
4714 Descriptor::DataField(isolate(), factory->to_string_tag_symbol(),
4716 attribs, Representation::Tagged());
4717 map->AppendDescriptor(isolate(), &d);
4718 }
4719 }
4720
4721 { // -- I t e r a t o r and helpers
4722 DirectHandle<JSObject> iterator_prototype(
4723 native_context()->initial_iterator_prototype(), isolate());
4724 DirectHandle<JSFunction> iterator_function = InstallFunction(
4725 isolate(), global, "Iterator", JS_OBJECT_TYPE, JSObject::kHeaderSize, 0,
4726 iterator_prototype, Builtin::kIteratorConstructor, 0, kAdapt);
4727
4728 SimpleInstallFunction(isolate(), iterator_function, "from",
4729 Builtin::kIteratorFrom, 1, kAdapt);
4730 InstallWithIntrinsicDefaultProto(isolate(), iterator_function,
4731 Context::ITERATOR_FUNCTION_INDEX);
4732
4733 // --- %WrapForValidIteratorPrototype%
4734 DirectHandle<JSObject> wrap_for_valid_iterator_prototype =
4735 factory->NewJSObject(isolate()->object_function(),
4737 JSObject::ForceSetPrototype(isolate(), wrap_for_valid_iterator_prototype,
4738 iterator_prototype);
4739 JSObject::AddProperty(isolate(), iterator_prototype,
4740 factory->constructor_string(), iterator_function,
4741 DONT_ENUM);
4742 SimpleInstallFunction(isolate(), wrap_for_valid_iterator_prototype, "next",
4743 Builtin::kWrapForValidIteratorPrototypeNext, 0,
4744 kAdapt);
4746 isolate(), wrap_for_valid_iterator_prototype, "return",
4747 Builtin::kWrapForValidIteratorPrototypeReturn, 0, kAdapt);
4748 DirectHandle<Map> valid_iterator_wrapper_map =
4750 JS_VALID_ITERATOR_WRAPPER_TYPE, JSValidIteratorWrapper::kHeaderSize,
4752 Map::SetPrototype(isolate(), valid_iterator_wrapper_map,
4753 wrap_for_valid_iterator_prototype);
4754 valid_iterator_wrapper_map->SetConstructor(*iterator_function);
4755 native_context()->set_valid_iterator_wrapper_map(
4756 *valid_iterator_wrapper_map);
4757
4758 // --- %IteratorHelperPrototype%
4759 DirectHandle<JSObject> iterator_helper_prototype = factory->NewJSObject(
4760 isolate()->object_function(), AllocationType::kOld);
4761 JSObject::ForceSetPrototype(isolate(), iterator_helper_prototype,
4762 iterator_prototype);
4763 InstallToStringTag(isolate(), iterator_helper_prototype, "Iterator Helper");
4764 SimpleInstallFunction(isolate(), iterator_helper_prototype, "next",
4765 Builtin::kIteratorHelperPrototypeNext, 0, kAdapt);
4766 SimpleInstallFunction(isolate(), iterator_helper_prototype, "return",
4767 Builtin::kIteratorHelperPrototypeReturn, 0, kAdapt);
4768 SimpleInstallFunction(isolate(), iterator_prototype, "reduce",
4769 Builtin::kIteratorPrototypeReduce, 1, kDontAdapt);
4770 SimpleInstallFunction(isolate(), iterator_prototype, "toArray",
4771 Builtin::kIteratorPrototypeToArray, 0, kAdapt);
4772 SimpleInstallFunction(isolate(), iterator_prototype, "forEach",
4773 Builtin::kIteratorPrototypeForEach, 1, kAdapt);
4774 SimpleInstallFunction(isolate(), iterator_prototype, "some",
4775 Builtin::kIteratorPrototypeSome, 1, kAdapt);
4776 SimpleInstallFunction(isolate(), iterator_prototype, "every",
4777 Builtin::kIteratorPrototypeEvery, 1, kAdapt);
4778 SimpleInstallFunction(isolate(), iterator_prototype, "find",
4779 Builtin::kIteratorPrototypeFind, 1, kAdapt);
4780 SimpleInstallGetterSetter(isolate(), iterator_prototype,
4781 factory->to_string_tag_symbol(),
4782 Builtin::kIteratorPrototypeGetToStringTag,
4783 Builtin::kIteratorPrototypeSetToStringTag);
4784
4785 SimpleInstallGetterSetter(isolate(), iterator_prototype,
4786 factory->constructor_string(),
4787 Builtin::kIteratorPrototypeGetConstructor,
4788 Builtin::kIteratorPrototypeSetConstructor);
4789
4790 // --- Helper maps
4791#define INSTALL_ITERATOR_HELPER(lowercase_name, Capitalized_name, \
4792 ALL_CAPS_NAME, argc) \
4793 { \
4794 DirectHandle<Map> map = factory->NewContextfulMapForCurrentContext( \
4795 JS_ITERATOR_##ALL_CAPS_NAME##_HELPER_TYPE, \
4796 JSIterator##Capitalized_name##Helper::kHeaderSize, \
4797 TERMINAL_FAST_ELEMENTS_KIND, 0); \
4798 Map::SetPrototype(isolate(), map, iterator_helper_prototype); \
4799 map->SetConstructor(*iterator_function); \
4800 native_context()->set_iterator_##lowercase_name##_helper_map(*map); \
4801 SimpleInstallFunction(isolate(), iterator_prototype, #lowercase_name, \
4802 Builtin::kIteratorPrototype##Capitalized_name, argc, \
4803 kAdapt); \
4804 }
4805
4806#define ITERATOR_HELPERS(V) \
4807 V(map, Map, MAP, 1) \
4808 V(filter, Filter, FILTER, 1) \
4809 V(take, Take, TAKE, 1) \
4810 V(drop, Drop, DROP, 1) \
4811 V(flatMap, FlatMap, FLAT_MAP, 1)
4812
4814
4815#undef INSTALL_ITERATOR_HELPER
4816#undef ITERATOR_HELPERS
4817 }
4818
4819 { // -- I t e r a t o r R e s u l t
4820 std::array<DirectHandle<Name>, 2> fields{factory->value_string(),
4821 factory->done_string()};
4822 DirectHandle<Map> map = CreateLiteralObjectMapFromCache(isolate(), fields);
4823 native_context()->set_iterator_result_map(*map);
4824 }
4825
4826 { // -- W e a k M a p
4828 InstallFunction(isolate_, global, "WeakMap", JS_WEAK_MAP_TYPE,
4829 JSWeakMap::kHeaderSize, 0, factory->the_hole_value(),
4830 Builtin::kWeakMapConstructor, 0, kDontAdapt);
4832 Context::JS_WEAK_MAP_FUN_INDEX);
4833
4834 // Setup %WeakMapPrototype%.
4835 DirectHandle<JSObject> prototype(Cast<JSObject>(cons->instance_prototype()),
4836 isolate());
4837
4838 DirectHandle<JSFunction> weakmap_delete =
4839 SimpleInstallFunction(isolate_, prototype, "delete",
4840 Builtin::kWeakMapPrototypeDelete, 1, kAdapt);
4841 native_context()->set_weakmap_delete(*weakmap_delete);
4842
4844 isolate_, prototype, "get", Builtin::kWeakMapGet, 1, kAdapt);
4845 native_context()->set_weakmap_get(*weakmap_get);
4846
4848 isolate_, prototype, "set", Builtin::kWeakMapPrototypeSet, 2, kAdapt);
4849 // Check that index of "set" function in JSWeakCollection is correct.
4851 prototype->map()->LastAdded().as_int());
4852
4853 native_context()->set_weakmap_set(*weakmap_set);
4854 SimpleInstallFunction(isolate_, prototype, "has",
4855 Builtin::kWeakMapPrototypeHas, 1, kAdapt);
4856
4857 InstallToStringTag(isolate_, prototype, "WeakMap");
4858
4859 native_context()->set_initial_weakmap_prototype_map(prototype->map());
4860 }
4861
4862 { // -- W e a k S e t
4864 InstallFunction(isolate_, global, "WeakSet", JS_WEAK_SET_TYPE,
4865 JSWeakSet::kHeaderSize, 0, factory->the_hole_value(),
4866 Builtin::kWeakSetConstructor, 0, kDontAdapt);
4868 Context::JS_WEAK_SET_FUN_INDEX);
4869
4870 // Setup %WeakSetPrototype%.
4871 DirectHandle<JSObject> prototype(Cast<JSObject>(cons->instance_prototype()),
4872 isolate());
4873
4874 SimpleInstallFunction(isolate_, prototype, "delete",
4875 Builtin::kWeakSetPrototypeDelete, 1, kAdapt);
4876 SimpleInstallFunction(isolate_, prototype, "has",
4877 Builtin::kWeakSetPrototypeHas, 1, kAdapt);
4878
4880 isolate_, prototype, "add", Builtin::kWeakSetPrototypeAdd, 1, kAdapt);
4881 // Check that index of "add" function in JSWeakCollection is correct.
4883 prototype->map()->LastAdded().as_int());
4884
4885 native_context()->set_weakset_add(*weakset_add);
4886
4887 InstallToStringTag(isolate_, prototype,
4888 factory->InternalizeUtf8String("WeakSet"));
4889
4890 native_context()->set_initial_weakset_prototype_map(prototype->map());
4891 }
4892
4893 { // -- P r o x y
4895 // Proxy function map has prototype slot for storing initial map but does
4896 // not have a prototype property.
4897 DirectHandle<Map> proxy_function_map = Map::Copy(
4898 isolate_, isolate_->strict_function_without_prototype_map(), "Proxy");
4899 proxy_function_map->set_is_constructor(true);
4900
4901 DirectHandle<String> name = factory->Proxy_string();
4902 DirectHandle<JSFunction> proxy_function =
4903 CreateFunctionForBuiltin(isolate(), name, proxy_function_map,
4904 Builtin::kProxyConstructor, 2, kAdapt);
4905
4906 isolate_->proxy_map()->SetConstructor(*proxy_function);
4907
4908 native_context()->set_proxy_function(*proxy_function);
4909 JSObject::AddProperty(isolate_, global, name, proxy_function, DONT_ENUM);
4910
4911 DCHECK(!proxy_function->has_prototype_property());
4912
4913 SimpleInstallFunction(isolate_, proxy_function, "revocable",
4914 Builtin::kProxyRevocable, 2, kAdapt);
4915 }
4916
4917 { // -- R e f l e c t
4918 DirectHandle<String> reflect_string =
4919 factory->InternalizeUtf8String("Reflect");
4920 DirectHandle<JSObject> reflect =
4921 factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
4922 JSObject::AddProperty(isolate_, global, reflect_string, reflect, DONT_ENUM);
4923 InstallToStringTag(isolate_, reflect, reflect_string);
4924
4925 SimpleInstallFunction(isolate_, reflect, "defineProperty",
4926 Builtin::kReflectDefineProperty, 3, kAdapt);
4927
4928 SimpleInstallFunction(isolate_, reflect, "deleteProperty",
4929 Builtin::kReflectDeleteProperty, 2, kAdapt);
4930
4932 isolate_, reflect, "apply", Builtin::kReflectApply, 3, kDontAdapt);
4933 native_context()->set_reflect_apply(*apply);
4934
4935 DirectHandle<JSFunction> construct =
4936 SimpleInstallFunction(isolate_, reflect, "construct",
4937 Builtin::kReflectConstruct, 2, kDontAdapt);
4938 native_context()->set_reflect_construct(*construct);
4939
4940 SimpleInstallFunction(isolate_, reflect, "get", Builtin::kReflectGet, 2,
4941 kDontAdapt);
4942 SimpleInstallFunction(isolate_, reflect, "getOwnPropertyDescriptor",
4943 Builtin::kReflectGetOwnPropertyDescriptor, 2, kAdapt);
4944 SimpleInstallFunction(isolate_, reflect, "getPrototypeOf",
4945 Builtin::kReflectGetPrototypeOf, 1, kAdapt);
4946 SimpleInstallFunction(isolate_, reflect, "has", Builtin::kReflectHas, 2,
4947 kAdapt);
4948 SimpleInstallFunction(isolate_, reflect, "isExtensible",
4949 Builtin::kReflectIsExtensible, 1, kAdapt);
4950 SimpleInstallFunction(isolate_, reflect, "ownKeys",
4951 Builtin::kReflectOwnKeys, 1, kAdapt);
4952 SimpleInstallFunction(isolate_, reflect, "preventExtensions",
4953 Builtin::kReflectPreventExtensions, 1, kAdapt);
4954 SimpleInstallFunction(isolate_, reflect, "set", Builtin::kReflectSet, 3,
4955 kDontAdapt);
4956 SimpleInstallFunction(isolate_, reflect, "setPrototypeOf",
4957 Builtin::kReflectSetPrototypeOf, 2, kAdapt);
4958 }
4959
4960 { // --- B o u n d F u n c t i o n
4962 JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kHeaderSize,
4964 map->SetConstructor(native_context()->object_function());
4965 map->set_is_callable(true);
4966 Map::SetPrototype(isolate(), map, empty_function);
4967
4968 PropertyAttributes roc_attribs =
4969 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
4971
4972 { // length
4973 static_assert(
4975 0);
4977 factory->length_string(), factory->bound_function_length_accessor(),
4978 roc_attribs);
4979 map->AppendDescriptor(isolate(), &d);
4980 }
4981
4982 { // name
4983 static_assert(
4985 1);
4987 factory->name_string(), factory->bound_function_name_accessor(),
4988 roc_attribs);
4989 map->AppendDescriptor(isolate(), &d);
4990 }
4991 native_context()->set_bound_function_without_constructor_map(*map);
4992
4993 map = Map::Copy(isolate_, map, "IsConstructor");
4994 map->set_is_constructor(true);
4995 native_context()->set_bound_function_with_constructor_map(*map);
4996 }
4997
4998 { // -- F i n a l i z a t i o n R e g i s t r y
4999 DirectHandle<JSFunction> finalization_registry_fun = InstallFunction(
5000 isolate_, global, factory->FinalizationRegistry_string(),
5001 JS_FINALIZATION_REGISTRY_TYPE, JSFinalizationRegistry::kHeaderSize, 0,
5002 factory->the_hole_value(), Builtin::kFinalizationRegistryConstructor, 1,
5003 kDontAdapt);
5005 isolate_, finalization_registry_fun,
5006 Context::JS_FINALIZATION_REGISTRY_FUNCTION_INDEX);
5007
5008 DirectHandle<JSObject> finalization_registry_prototype(
5009 Cast<JSObject>(finalization_registry_fun->instance_prototype()),
5010 isolate());
5011
5012 InstallToStringTag(isolate_, finalization_registry_prototype,
5013 factory->FinalizationRegistry_string());
5014
5015 SimpleInstallFunction(isolate_, finalization_registry_prototype, "register",
5016 Builtin::kFinalizationRegistryRegister, 2,
5017 kDontAdapt);
5018
5020 isolate_, finalization_registry_prototype, "unregister",
5021 Builtin::kFinalizationRegistryUnregister, 1, kDontAdapt);
5022 }
5023
5024 { // -- W e a k R e f
5025 DirectHandle<JSFunction> weak_ref_fun =
5026 InstallFunction(isolate_, global, "WeakRef", JS_WEAK_REF_TYPE,
5027 JSWeakRef::kHeaderSize, 0, factory->the_hole_value(),
5028 Builtin::kWeakRefConstructor, 1, kDontAdapt);
5030 Context::JS_WEAK_REF_FUNCTION_INDEX);
5031
5032 DirectHandle<JSObject> weak_ref_prototype(
5033 Cast<JSObject>(weak_ref_fun->instance_prototype()), isolate());
5034
5035 InstallToStringTag(isolate_, weak_ref_prototype, factory->WeakRef_string());
5036
5037 SimpleInstallFunction(isolate_, weak_ref_prototype, "deref",
5038 Builtin::kWeakRefDeref, 0, kAdapt);
5039 }
5040
5041 { // --- sloppy arguments map
5042 DirectHandle<String> arguments_string = factory->Arguments_string();
5043 DirectHandle<JSFunction> function = CreateFunctionForBuiltinWithPrototype(
5044 isolate(), arguments_string, Builtin::kIllegal,
5045 isolate()->initial_object_prototype(), JS_ARGUMENTS_OBJECT_TYPE,
5046 JSSloppyArgumentsObject::kSize, 2, MUTABLE, 0, kDontAdapt);
5047 DirectHandle<Map> map(function->initial_map(), isolate());
5048
5049 // Create the descriptor array for the arguments object.
5051
5052 { // length
5053 Descriptor d =
5054 Descriptor::DataField(isolate(), factory->length_string(),
5057 map->AppendDescriptor(isolate(), &d);
5058 }
5059 { // callee
5060 Descriptor d =
5061 Descriptor::DataField(isolate(), factory->callee_string(),
5064 map->AppendDescriptor(isolate(), &d);
5065 }
5066 // @@iterator method is added later.
5067
5068 native_context()->set_sloppy_arguments_map(*map);
5069
5070 DCHECK(!map->is_dictionary_map());
5071 DCHECK(IsObjectElementsKind(map->elements_kind()));
5072 }
5073
5074 { // --- fast and slow aliased arguments map
5075 DirectHandle<Map> map = isolate_->sloppy_arguments_map();
5076 map = Map::Copy(isolate_, map, "FastAliasedArguments");
5077 map->set_elements_kind(FAST_SLOPPY_ARGUMENTS_ELEMENTS);
5078 DCHECK_EQ(2, map->GetInObjectProperties());
5079 native_context()->set_fast_aliased_arguments_map(*map);
5080
5081 map = Map::Copy(isolate_, map, "SlowAliasedArguments");
5082 map->set_elements_kind(SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
5083 DCHECK_EQ(2, map->GetInObjectProperties());
5084 native_context()->set_slow_aliased_arguments_map(*map);
5085 }
5086
5087 { // --- strict mode arguments map
5088 const PropertyAttributes attributes =
5090
5091 // Create the ThrowTypeError function.
5093
5095
5096 // Install the ThrowTypeError function.
5097 callee->set_getter(*poison);
5098 callee->set_setter(*poison);
5099
5100 // Create the map. Allocate one in-object field for length.
5102 JS_ARGUMENTS_OBJECT_TYPE, JSStrictArgumentsObject::kSize,
5103 PACKED_ELEMENTS, 1);
5104 // Create the descriptor array for the arguments object.
5106
5107 { // length
5108 Descriptor d =
5109 Descriptor::DataField(isolate(), factory->length_string(),
5112 map->AppendDescriptor(isolate(), &d);
5113 }
5114 { // callee
5115 Descriptor d = Descriptor::AccessorConstant(factory->callee_string(),
5116 callee, attributes);
5117 map->AppendDescriptor(isolate(), &d);
5118 }
5119 // @@iterator method is added later.
5120
5121 DCHECK_EQ(native_context()->object_function()->prototype(),
5122 *isolate_->initial_object_prototype());
5123 Map::SetPrototype(isolate(), map, isolate_->initial_object_prototype());
5124
5125 // Copy constructor from the sloppy arguments boilerplate.
5126 map->SetConstructor(
5127 native_context()->sloppy_arguments_map()->GetConstructor());
5128
5129 native_context()->set_strict_arguments_map(*map);
5130
5131 DCHECK(!map->is_dictionary_map());
5132 DCHECK(IsObjectElementsKind(map->elements_kind()));
5133 }
5134
5135 { // --- context extension
5136 // Create a function for the context extension objects.
5137 DirectHandle<JSFunction> context_extension_fun = CreateFunction(
5138 isolate_, factory->empty_string(), JS_CONTEXT_EXTENSION_OBJECT_TYPE,
5139 JSObject::kHeaderSize, 0, factory->the_hole_value(), Builtin::kIllegal,
5140 0, kDontAdapt);
5141 native_context()->set_context_extension_function(*context_extension_fun);
5142 }
5143
5144 {
5145 // Set up the call-as-function delegate.
5146 DirectHandle<JSFunction> delegate = SimpleCreateFunction(
5147 isolate_, factory->empty_string(),
5148 Builtin::kHandleApiCallAsFunctionDelegate, 0, kDontAdapt);
5149 native_context()->set_call_as_function_delegate(*delegate);
5150 }
5151
5152 {
5153 // Set up the call-as-constructor delegate.
5154 DirectHandle<JSFunction> delegate = SimpleCreateFunction(
5155 isolate_, factory->empty_string(),
5156 Builtin::kHandleApiCallAsConstructorDelegate, 0, kDontAdapt);
5157 native_context()->set_call_as_constructor_delegate(*delegate);
5158 }
5159}
5160
5162 const char* name, ElementsKind elements_kind, InstanceType constructor_type,
5163 int rab_gsab_initial_map_index) {
5164 DirectHandle<JSObject> global(native_context()->global_object(), isolate());
5165
5166 DirectHandle<JSObject> typed_array_prototype =
5167 isolate()->typed_array_prototype();
5168 DirectHandle<JSFunction> typed_array_function =
5169 isolate()->typed_array_function();
5170
5171 DirectHandle<JSFunction> result = InstallFunction(
5172 isolate(), global, name, JS_TYPED_ARRAY_TYPE,
5173 JSTypedArray::kSizeWithEmbedderFields, 0, factory()->the_hole_value(),
5174 Builtin::kTypedArrayConstructor, 3, kDontAdapt);
5175 result->initial_map()->set_elements_kind(elements_kind);
5176
5177 CHECK(JSObject::SetPrototype(isolate(), result, typed_array_function, false,
5178 kDontThrow)
5179 .FromJust());
5180
5181 DirectHandle<Smi> bytes_per_element(
5182 Smi::FromInt(1 << ElementsKindToShiftSize(elements_kind)), isolate());
5183
5184 InstallConstant(isolate(), result, "BYTES_PER_ELEMENT", bytes_per_element);
5185
5186 // TODO(v8:11256, ishell): given the granularity of typed array constructor
5187 // protectors, consider creating only one constructor instance type for all
5188 // typed array constructors.
5189 SetConstructorInstanceType(isolate_, result, constructor_type);
5190
5191 // Setup prototype object.
5192 DCHECK(IsJSObject(result->prototype()));
5194 isolate());
5195
5196 CHECK(JSObject::SetPrototype(isolate(), prototype, typed_array_prototype,
5197 false, kDontThrow)
5198 .FromJust());
5199
5200 CHECK_NE(prototype->map().ptr(),
5201 isolate_->initial_object_prototype()->map().ptr());
5202 prototype->map()->set_instance_type(JS_TYPED_ARRAY_PROTOTYPE_TYPE);
5203
5204 InstallConstant(isolate(), prototype, "BYTES_PER_ELEMENT", bytes_per_element);
5205
5206 // RAB / GSAB backed TypedArrays don't have separate constructors, but they
5207 // have their own maps. Create the corresponding map here.
5208 DirectHandle<Map> rab_gsab_initial_map =
5210 JS_TYPED_ARRAY_TYPE, JSTypedArray::kSizeWithEmbedderFields,
5211 GetCorrespondingRabGsabElementsKind(elements_kind), 0);
5212 rab_gsab_initial_map->SetConstructor(*result);
5213
5214 native_context()->set(rab_gsab_initial_map_index, *rab_gsab_initial_map,
5216 Map::SetPrototype(isolate(), rab_gsab_initial_map, prototype);
5217
5218 return result;
5219}
5220
5222#define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id();
5223
5224 // Initialize features from more mature to less mature, because less mature
5225 // features may depend on more mature features having been initialized
5226 // already.
5233#undef FEATURE_INITIALIZE_GLOBAL
5236}
5237
5238namespace {
5239class TryCallScope {
5240 public:
5241 explicit TryCallScope(Isolate* isolate) : top(isolate->thread_local_top()) {
5242 top->IncrementCallDepth<true>(this);
5243 }
5244 ~TryCallScope() { top->DecrementCallDepth(this); }
5245
5246 private:
5247 friend class i::ThreadLocalTop;
5248 ThreadLocalTop* top;
5250};
5251} // namespace
5252
5254 Factory* factory = isolate->factory();
5255 HandleScope scope(isolate);
5257
5258 Handle<String> source =
5259 isolate->factory()
5260 ->NewExternalStringFromOneByte(extension->source())
5261 .ToHandleChecked();
5262 DCHECK(source->IsOneByteRepresentation());
5263
5264 // If we can't find the function in the cache, we compile a new
5265 // function and insert it into the cache.
5267 SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache();
5268 DirectHandle<Context> context(isolate->context(), isolate);
5269 DCHECK(IsNativeContext(*context));
5270
5271 if (!cache->Lookup(isolate, name, &function_info)) {
5272 Handle<String> script_name =
5273 factory->NewStringFromUtf8(name).ToHandleChecked();
5274 ScriptCompiler::CompilationDetails compilation_details;
5275 MaybeDirectHandle<SharedFunctionInfo> maybe_function_info =
5277 isolate, source, ScriptDetails(script_name), extension,
5279 &compilation_details);
5280 if (!maybe_function_info.ToHandle(&function_info)) return false;
5281 cache->Add(isolate, name, function_info);
5282 }
5283
5284 // Set up the function context. Conceptually, we should clone the
5285 // function before overwriting the context but since we're in a
5286 // single-threaded environment it is not strictly necessary.
5288 Factory::JSFunctionBuilder{isolate, function_info, context}.Build();
5289
5290 // Call function using either the runtime object or the global
5291 // object as the receiver. Provide no parameters.
5292 DirectHandle<Object> receiver = isolate->global_object();
5293 DirectHandle<FixedArray> host_defined_options =
5294 isolate->factory()->empty_fixed_array();
5295 TryCallScope try_call_scope(isolate);
5296 // Blink generally assumes that context creation (where extension compilation
5297 // is part) cannot be interrupted.
5298 PostponeInterruptsScope postpone(isolate);
5299 return !Execution::TryCallScript(isolate, fun, receiver, host_defined_options)
5300 .is_null();
5301}
5302
5304 Isolate* isolate = isolate_;
5305 Factory* factory = isolate->factory();
5306 HandleScope scope(isolate);
5307 DirectHandle<NativeContext> native_context = isolate->native_context();
5308 DirectHandle<JSObject> iterator_prototype(
5309 native_context->initial_iterator_prototype(), isolate);
5310
5311 { // -- G e n e r a t o r
5312 PrototypeIterator iter(isolate, native_context->generator_function_map());
5313 DirectHandle<JSObject> generator_function_prototype(
5314 iter.GetCurrent<JSObject>(), isolate);
5315 DirectHandle<JSFunction> generator_function_function = CreateFunction(
5316 isolate, "GeneratorFunction", JS_FUNCTION_TYPE,
5317 JSFunction::kSizeWithPrototype, 0, generator_function_prototype,
5318 Builtin::kGeneratorFunctionConstructor, 1, kDontAdapt);
5319 generator_function_function->set_prototype_or_initial_map(
5320 native_context->generator_function_map(), kReleaseStore);
5322 isolate, generator_function_function,
5323 Context::GENERATOR_FUNCTION_FUNCTION_INDEX);
5324
5325 JSObject::ForceSetPrototype(isolate, generator_function_function,
5326 isolate->function_function());
5328 isolate, generator_function_prototype, factory->constructor_string(),
5329 generator_function_function,
5330 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
5331
5332 native_context->generator_function_map()->SetConstructor(
5333 *generator_function_function);
5334 native_context->generator_function_with_name_map()->SetConstructor(
5335 *generator_function_function);
5336 }
5337
5338 { // -- A s y n c G e n e r a t o r
5339 PrototypeIterator iter(isolate,
5340 native_context->async_generator_function_map());
5341 DirectHandle<JSObject> async_generator_function_prototype(
5342 iter.GetCurrent<JSObject>(), isolate);
5343
5344 DirectHandle<JSFunction> async_generator_function_function = CreateFunction(
5345 isolate, "AsyncGeneratorFunction", JS_FUNCTION_TYPE,
5346 JSFunction::kSizeWithPrototype, 0, async_generator_function_prototype,
5347 Builtin::kAsyncGeneratorFunctionConstructor, 1, kDontAdapt);
5348 async_generator_function_function->set_prototype_or_initial_map(
5349 native_context->async_generator_function_map(), kReleaseStore);
5351 isolate, async_generator_function_function,
5352 Context::ASYNC_GENERATOR_FUNCTION_FUNCTION_INDEX);
5353
5354 JSObject::ForceSetPrototype(isolate, async_generator_function_function,
5355 isolate->function_function());
5356
5358 isolate, async_generator_function_prototype,
5359 factory->constructor_string(), async_generator_function_function,
5360 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
5361
5362 native_context->async_generator_function_map()->SetConstructor(
5363 *async_generator_function_function);
5364 native_context->async_generator_function_with_name_map()->SetConstructor(
5365 *async_generator_function_function);
5366 }
5367
5368 { // -- S e t I t e r a t o r
5369 // Setup %SetIteratorPrototype%.
5370 DirectHandle<JSObject> prototype =
5371 factory->NewJSObject(isolate->object_function(), AllocationType::kOld);
5372 JSObject::ForceSetPrototype(isolate, prototype, iterator_prototype);
5373
5374 InstallToStringTag(isolate, prototype, factory->SetIterator_string());
5375
5376 // Install the next function on the {prototype}.
5377 InstallFunctionWithBuiltinId(isolate, prototype, "next",
5378 Builtin::kSetIteratorPrototypeNext, 0, kAdapt);
5379 native_context->set_initial_set_iterator_prototype(*prototype);
5380 CHECK_NE(prototype->map().ptr(),
5381 isolate_->initial_object_prototype()->map().ptr());
5382 prototype->map()->set_instance_type(JS_SET_ITERATOR_PROTOTYPE_TYPE);
5383
5384 // Setup SetIterator constructor.
5385 DirectHandle<JSFunction> set_iterator_function =
5386 CreateFunction(isolate, "SetIterator", JS_SET_VALUE_ITERATOR_TYPE,
5387 JSSetIterator::kHeaderSize, 0, prototype,
5388 Builtin::kIllegal, 0, kDontAdapt);
5389 set_iterator_function->shared()->set_native(false);
5390
5391 DirectHandle<Map> set_value_iterator_map(
5392 set_iterator_function->initial_map(), isolate);
5393 native_context->set_set_value_iterator_map(*set_value_iterator_map);
5394
5395 DirectHandle<Map> set_key_value_iterator_map = Map::Copy(
5396 isolate, set_value_iterator_map, "JS_SET_KEY_VALUE_ITERATOR_TYPE");
5397 set_key_value_iterator_map->set_instance_type(
5398 JS_SET_KEY_VALUE_ITERATOR_TYPE);
5399 native_context->set_set_key_value_iterator_map(*set_key_value_iterator_map);
5400 }
5401
5402 { // -- M a p I t e r a t o r
5403 // Setup %MapIteratorPrototype%.
5404 DirectHandle<JSObject> prototype =
5405 factory->NewJSObject(isolate->object_function(), AllocationType::kOld);
5406 JSObject::ForceSetPrototype(isolate, prototype, iterator_prototype);
5407
5408 InstallToStringTag(isolate, prototype, factory->MapIterator_string());
5409
5410 // Install the next function on the {prototype}.
5411 InstallFunctionWithBuiltinId(isolate, prototype, "next",
5412 Builtin::kMapIteratorPrototypeNext, 0, kAdapt);
5413 native_context->set_initial_map_iterator_prototype(*prototype);
5414 CHECK_NE(prototype->map().ptr(),
5415 isolate_->initial_object_prototype()->map().ptr());
5416 prototype->map()->set_instance_type(JS_MAP_ITERATOR_PROTOTYPE_TYPE);
5417
5418 // Setup MapIterator constructor.
5419 DirectHandle<JSFunction> map_iterator_function =
5420 CreateFunction(isolate, "MapIterator", JS_MAP_KEY_ITERATOR_TYPE,
5421 JSMapIterator::kHeaderSize, 0, prototype,
5422 Builtin::kIllegal, 0, kDontAdapt);
5423 map_iterator_function->shared()->set_native(false);
5424
5425 DirectHandle<Map> map_key_iterator_map(map_iterator_function->initial_map(),
5426 isolate);
5427 native_context->set_map_key_iterator_map(*map_key_iterator_map);
5428
5429 DirectHandle<Map> map_key_value_iterator_map = Map::Copy(
5430 isolate, map_key_iterator_map, "JS_MAP_KEY_VALUE_ITERATOR_TYPE");
5431 map_key_value_iterator_map->set_instance_type(
5432 JS_MAP_KEY_VALUE_ITERATOR_TYPE);
5433 native_context->set_map_key_value_iterator_map(*map_key_value_iterator_map);
5434
5435 DirectHandle<Map> map_value_iterator_map =
5436 Map::Copy(isolate, map_key_iterator_map, "JS_MAP_VALUE_ITERATOR_TYPE");
5437 map_value_iterator_map->set_instance_type(JS_MAP_VALUE_ITERATOR_TYPE);
5438 native_context->set_map_value_iterator_map(*map_value_iterator_map);
5439 }
5440
5441 { // -- A s y n c F u n c t i o n
5442 // Builtin functions for AsyncFunction.
5443 PrototypeIterator iter(isolate, native_context->async_function_map());
5444 DirectHandle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>(),
5445 isolate);
5446
5447 DirectHandle<JSFunction> async_function_constructor = CreateFunction(
5448 isolate, "AsyncFunction", JS_FUNCTION_TYPE,
5449 JSFunction::kSizeWithPrototype, 0, async_function_prototype,
5450 Builtin::kAsyncFunctionConstructor, 1, kDontAdapt);
5451 async_function_constructor->set_prototype_or_initial_map(
5452 native_context->async_function_map(), kReleaseStore);
5453 InstallWithIntrinsicDefaultProto(isolate, async_function_constructor,
5454 Context::ASYNC_FUNCTION_FUNCTION_INDEX);
5455
5456 native_context->set_async_function_constructor(*async_function_constructor);
5457 JSObject::ForceSetPrototype(isolate, async_function_constructor,
5458 isolate->function_function());
5459
5461 isolate, async_function_prototype, factory->constructor_string(),
5462 async_function_constructor,
5463 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
5464
5465 // Async functions don't have a prototype, but they use generator objects
5466 // under the hood to model the suspend/resume (in await). Instead of using
5467 // the "prototype" / initial_map machinery (like for (async) generators),
5468 // there's one global (per native context) map here that is used for the
5469 // async function generator objects. These objects never escape to user
5470 // JavaScript anyways.
5471 DirectHandle<Map> async_function_object_map =
5473 JS_ASYNC_FUNCTION_OBJECT_TYPE, JSAsyncFunctionObject::kHeaderSize);
5474 native_context->set_async_function_object_map(*async_function_object_map);
5475
5476 isolate_->async_function_map()->SetConstructor(*async_function_constructor);
5477 isolate_->async_function_with_name_map()->SetConstructor(
5478 *async_function_constructor);
5479 }
5480}
5481
5484 HandleScope scope(isolate());
5485 // -- C a l l S i t e
5486 // Builtin functions for CallSite.
5487
5488 // CallSites are a special case; the constructor is for our private use
5489 // only, therefore we set it up as a builtin that throws. Internally, we use
5490 // CallSiteUtils::Construct to create CallSite objects.
5491
5492 DirectHandle<JSFunction> callsite_fun = CreateFunction(
5493 isolate(), "CallSite", JS_OBJECT_TYPE, JSObject::kHeaderSize, 0,
5494 factory->the_hole_value(), Builtin::kUnsupportedThrower, 0, kDontAdapt);
5495 isolate()->native_context()->set_callsite_function(*callsite_fun);
5496
5497 // Setup CallSite.prototype.
5499 Cast<JSObject>(callsite_fun->instance_prototype()), isolate());
5500
5501 struct FunctionInfo {
5502 const char* name;
5503 Builtin id;
5504 };
5505
5506 FunctionInfo infos[] = {
5507 {"getColumnNumber", Builtin::kCallSitePrototypeGetColumnNumber},
5508 {"getEnclosingColumnNumber",
5509 Builtin::kCallSitePrototypeGetEnclosingColumnNumber},
5510 {"getEnclosingLineNumber",
5511 Builtin::kCallSitePrototypeGetEnclosingLineNumber},
5512 {"getEvalOrigin", Builtin::kCallSitePrototypeGetEvalOrigin},
5513 {"getFileName", Builtin::kCallSitePrototypeGetFileName},
5514 {"getFunction", Builtin::kCallSitePrototypeGetFunction},
5515 {"getFunctionName", Builtin::kCallSitePrototypeGetFunctionName},
5516 {"getLineNumber", Builtin::kCallSitePrototypeGetLineNumber},
5517 {"getMethodName", Builtin::kCallSitePrototypeGetMethodName},
5518 {"getPosition", Builtin::kCallSitePrototypeGetPosition},
5519 {"getPromiseIndex", Builtin::kCallSitePrototypeGetPromiseIndex},
5520 {"getScriptNameOrSourceURL",
5521 Builtin::kCallSitePrototypeGetScriptNameOrSourceURL},
5522 {"getScriptHash", Builtin::kCallSitePrototypeGetScriptHash},
5523 {"getThis", Builtin::kCallSitePrototypeGetThis},
5524 {"getTypeName", Builtin::kCallSitePrototypeGetTypeName},
5525 {"isAsync", Builtin::kCallSitePrototypeIsAsync},
5526 {"isConstructor", Builtin::kCallSitePrototypeIsConstructor},
5527 {"isEval", Builtin::kCallSitePrototypeIsEval},
5528 {"isNative", Builtin::kCallSitePrototypeIsNative},
5529 {"isPromiseAll", Builtin::kCallSitePrototypeIsPromiseAll},
5530 {"isToplevel", Builtin::kCallSitePrototypeIsToplevel},
5531 {"toString", Builtin::kCallSitePrototypeToString}};
5532
5533 PropertyAttributes attrs =
5535
5536 for (const FunctionInfo& info : infos) {
5537 SimpleInstallFunction(isolate(), prototype, info.name, info.id, 0, kAdapt,
5538 attrs);
5539 }
5540}
5541
5543 HandleScope scope(isolate());
5545
5546 // -- C o n s o l e
5547 DirectHandle<String> name = factory->console_string();
5548
5550 DirectHandle<JSGlobalObject> global(context->global_object(), isolate());
5552 factory->NewSharedFunctionInfoForBuiltin(name, Builtin::kIllegal, 0,
5553 kDontAdapt);
5554 info->set_language_mode(LanguageMode::kStrict);
5555
5559 factory->NewJSObject(isolate_->object_function());
5560 JSFunction::SetPrototype(cons, empty);
5561
5562 DirectHandle<JSObject> console =
5564 DCHECK(IsJSObject(*console));
5565
5566 JSObject::AddProperty(isolate_, extras_binding, name, console, DONT_ENUM);
5567 // TODO(v8:11989): remove this in the next release
5568 JSObject::AddProperty(isolate_, global, name, console, DONT_ENUM);
5569
5570 SimpleInstallFunction(isolate_, console, "debug", Builtin::kConsoleDebug, 0,
5571 kDontAdapt, NONE);
5572 SimpleInstallFunction(isolate_, console, "error", Builtin::kConsoleError, 0,
5573 kDontAdapt, NONE);
5574 SimpleInstallFunction(isolate_, console, "info", Builtin::kConsoleInfo, 0,
5575 kDontAdapt, NONE);
5576 SimpleInstallFunction(isolate_, console, "log", Builtin::kConsoleLog, 0,
5577 kDontAdapt, NONE);
5578 SimpleInstallFunction(isolate_, console, "warn", Builtin::kConsoleWarn, 0,
5579 kDontAdapt, NONE);
5580 SimpleInstallFunction(isolate_, console, "dir", Builtin::kConsoleDir, 0,
5581 kDontAdapt, NONE);
5582 SimpleInstallFunction(isolate_, console, "dirxml", Builtin::kConsoleDirXml, 0,
5583 kDontAdapt, NONE);
5584 SimpleInstallFunction(isolate_, console, "table", Builtin::kConsoleTable, 0,
5585 kDontAdapt, NONE);
5586 SimpleInstallFunction(isolate_, console, "trace", Builtin::kConsoleTrace, 0,
5587 kDontAdapt, NONE);
5588 SimpleInstallFunction(isolate_, console, "group", Builtin::kConsoleGroup, 0,
5589 kDontAdapt, NONE);
5590 SimpleInstallFunction(isolate_, console, "groupCollapsed",
5591 Builtin::kConsoleGroupCollapsed, 0, kDontAdapt, NONE);
5592 SimpleInstallFunction(isolate_, console, "groupEnd",
5593 Builtin::kConsoleGroupEnd, 0, kDontAdapt, NONE);
5594 SimpleInstallFunction(isolate_, console, "clear", Builtin::kConsoleClear, 0,
5595 kDontAdapt, NONE);
5596 SimpleInstallFunction(isolate_, console, "count", Builtin::kConsoleCount, 0,
5597 kDontAdapt, NONE);
5598 SimpleInstallFunction(isolate_, console, "countReset",
5599 Builtin::kConsoleCountReset, 0, kDontAdapt, NONE);
5600 SimpleInstallFunction(isolate_, console, "assert",
5601 Builtin::kFastConsoleAssert, 0, kDontAdapt, NONE);
5602 SimpleInstallFunction(isolate_, console, "profile", Builtin::kConsoleProfile,
5603 0, kDontAdapt, NONE);
5604 SimpleInstallFunction(isolate_, console, "profileEnd",
5605 Builtin::kConsoleProfileEnd, 0, kDontAdapt, NONE);
5606 SimpleInstallFunction(isolate_, console, "time", Builtin::kConsoleTime, 0,
5607 kDontAdapt, NONE);
5608 SimpleInstallFunction(isolate_, console, "timeLog", Builtin::kConsoleTimeLog,
5609 0, kDontAdapt, NONE);
5610 SimpleInstallFunction(isolate_, console, "timeEnd", Builtin::kConsoleTimeEnd,
5611 0, kDontAdapt, NONE);
5612 SimpleInstallFunction(isolate_, console, "timeStamp",
5613 Builtin::kConsoleTimeStamp, 0, kDontAdapt, NONE);
5614 SimpleInstallFunction(isolate_, console, "context", Builtin::kConsoleContext,
5615 1, kDontAdapt, NONE);
5616 InstallToStringTag(isolate_, console, "console");
5617}
5618
5619#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
5620 void Genesis::InitializeGlobal_##id() {}
5621
5622EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_attributes)
5623EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(js_regexp_modifiers)
5624EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(js_regexp_duplicate_named_groups)
5626
5627#ifdef V8_INTL_SUPPORT
5628EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_best_fit_matcher)
5629EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_remove_intl_locale_info_getters)
5630#endif // V8_INTL_SUPPORT
5631
5632#undef EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE
5633
5634void Genesis::InitializeGlobal_js_atomics_pause() {
5635 if (!v8_flags.js_atomics_pause) return;
5636 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
5637 isolate());
5638 DirectHandle<JSObject> atomics_object = Cast<JSObject>(
5639 JSReceiver::GetProperty(isolate(), global, "Atomics").ToHandleChecked());
5640 InstallFunctionWithBuiltinId(isolate(), atomics_object, "pause",
5641 Builtin::kAtomicsPause, 0, kDontAdapt);
5642}
5643
5644void Genesis::InitializeGlobal_js_promise_try() {
5645 if (!v8_flags.js_promise_try) return;
5646 DirectHandle<JSFunction> promise_fun(native_context()->promise_function(),
5647 isolate());
5648 InstallFunctionWithBuiltinId(isolate(), promise_fun, "try",
5649 Builtin::kPromiseTry, 1, kDontAdapt);
5650}
5651
5652void Genesis::InitializeGlobal_js_error_iserror() {
5653 if (!v8_flags.js_error_iserror) return;
5654 DirectHandle<JSFunction> error_fun(native_context()->error_function(),
5655 isolate());
5656 InstallFunctionWithBuiltinId(isolate(), error_fun, "isError",
5657 Builtin::kErrorIsError, 1, kAdapt);
5658}
5659
5660void Genesis::InitializeGlobal_harmony_shadow_realm() {
5661 if (!v8_flags.harmony_shadow_realm) return;
5662 Factory* factory = isolate()->factory();
5663 // -- S h a d o w R e a l m
5664 // #sec-shadowrealm-objects
5665 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
5666 isolate());
5667 DirectHandle<JSFunction> shadow_realm_fun =
5668 InstallFunction(isolate_, global, "ShadowRealm", JS_SHADOW_REALM_TYPE,
5669 JSShadowRealm::kHeaderSize, 0, factory->the_hole_value(),
5670 Builtin::kShadowRealmConstructor, 0, kDontAdapt);
5671
5672 // Setup %ShadowRealmPrototype%.
5673 DirectHandle<JSObject> prototype(
5674 Cast<JSObject>(shadow_realm_fun->instance_prototype()), isolate());
5675
5676 InstallToStringTag(isolate_, prototype, factory->ShadowRealm_string());
5677
5678 SimpleInstallFunction(isolate_, prototype, "evaluate",
5679 Builtin::kShadowRealmPrototypeEvaluate, 1, kAdapt);
5680 SimpleInstallFunction(isolate_, prototype, "importValue",
5681 Builtin::kShadowRealmPrototypeImportValue, 2, kAdapt);
5682
5683 { // --- W r a p p e d F u n c t i o n
5684 DirectHandle<Map> map = factory->NewContextfulMapForCurrentContext(
5685 JS_WRAPPED_FUNCTION_TYPE, JSWrappedFunction::kHeaderSize,
5687 map->SetConstructor(native_context()->object_function());
5688 map->set_is_callable(true);
5689 DirectHandle<JSObject> empty_function(
5690 native_context()->function_prototype(), isolate());
5691 Map::SetPrototype(isolate(), map, empty_function);
5692
5693 PropertyAttributes roc_attribs =
5694 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
5696 { // length
5697 static_assert(
5699 0);
5700 Descriptor d = Descriptor::AccessorConstant(
5701 factory->length_string(), factory->wrapped_function_length_accessor(),
5702 roc_attribs);
5703 map->AppendDescriptor(isolate(), &d);
5704 }
5705
5706 { // name
5707 static_assert(
5709 1);
5710 Descriptor d = Descriptor::AccessorConstant(
5711 factory->name_string(), factory->wrapped_function_name_accessor(),
5712 roc_attribs);
5713 map->AppendDescriptor(isolate(), &d);
5714 }
5715
5716 native_context()->set_wrapped_function_map(*map);
5717 }
5718
5719 // Internal steps of ShadowRealmImportValue
5720 {
5721 DirectHandle<JSFunction> shadow_realm_import_value_rejected =
5722 SimpleCreateFunction(isolate(), factory->empty_string(),
5723 Builtin::kShadowRealmImportValueRejected, 1,
5724 kAdapt);
5725 shadow_realm_import_value_rejected->shared()->set_native(false);
5726 native_context()->set_shadow_realm_import_value_rejected(
5727 *shadow_realm_import_value_rejected);
5728 }
5729}
5730
5731void Genesis::InitializeGlobal_harmony_struct() {
5732 if (!v8_flags.harmony_struct) return;
5733
5734 ReadOnlyRoots roots(isolate());
5735 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
5736 isolate());
5737 DirectHandle<JSObject> atomics_object = Cast<JSObject>(
5738 JSReceiver::GetProperty(isolate(), global, "Atomics").ToHandleChecked());
5739
5740 {
5741 // Install shared objects @@hasInstance in the native context.
5742 DirectHandle<JSFunction> has_instance = SimpleCreateFunction(
5743 isolate(), factory()->empty_string(),
5744 Builtin::kSharedSpaceJSObjectHasInstance, 1, kDontAdapt);
5745 native_context()->set_shared_space_js_object_has_instance(*has_instance);
5746 }
5747
5748 { // SharedStructType
5749 DirectHandle<String> name =
5750 isolate()->factory()->InternalizeUtf8String("SharedStructType");
5751 DirectHandle<JSFunction> shared_struct_type_fun = CreateFunctionForBuiltin(
5752 isolate(), name,
5753 isolate()->strict_function_with_readonly_prototype_map(),
5754 Builtin::kSharedStructTypeConstructor, 1, kDontAdapt);
5755 JSObject::MakePrototypesFast(shared_struct_type_fun, kStartAtReceiver,
5756 isolate());
5757 shared_struct_type_fun->shared()->set_native(true);
5758 JSObject::AddProperty(isolate(), global, "SharedStructType",
5759 shared_struct_type_fun, DONT_ENUM);
5760
5761 SimpleInstallFunction(isolate(), shared_struct_type_fun, "isSharedStruct",
5762 Builtin::kSharedStructTypeIsSharedStruct, 1, kAdapt);
5763 }
5764
5765 { // SharedArray
5766 DirectHandle<String> shared_array_str =
5767 isolate()->factory()->InternalizeUtf8String("SharedArray");
5768 DirectHandle<JSFunction> shared_array_fun = CreateSharedObjectConstructor(
5769 isolate(), shared_array_str,
5770 isolate()->factory()->js_shared_array_map(),
5771 Builtin::kSharedArrayConstructor, 0, kAdapt);
5772
5773 // Install SharedArray constructor.
5774 JSObject::AddProperty(isolate(), global, "SharedArray", shared_array_fun,
5775 DONT_ENUM);
5776
5777 SimpleInstallFunction(isolate(), shared_array_fun, "isSharedArray",
5778 Builtin::kSharedArrayIsSharedArray, 1, kAdapt);
5779 }
5780
5781 { // Atomics.Mutex
5782 DirectHandle<String> mutex_str =
5783 isolate()->factory()->InternalizeUtf8String("Mutex");
5784 DirectHandle<JSFunction> mutex_fun = CreateSharedObjectConstructor(
5785 isolate(), mutex_str, isolate()->factory()->js_atomics_mutex_map(),
5786 Builtin::kAtomicsMutexConstructor, 0, kAdapt);
5787 JSObject::AddProperty(isolate(), atomics_object, mutex_str, mutex_fun,
5788 DONT_ENUM);
5789
5790 SimpleInstallFunction(isolate(), mutex_fun, "lock",
5791 Builtin::kAtomicsMutexLock, 2, kAdapt);
5792 SimpleInstallFunction(isolate(), mutex_fun, "lockWithTimeout",
5793 Builtin::kAtomicsMutexLockWithTimeout, 3, kAdapt);
5794 SimpleInstallFunction(isolate(), mutex_fun, "tryLock",
5795 Builtin::kAtomicsMutexTryLock, 2, kAdapt);
5796 SimpleInstallFunction(isolate(), mutex_fun, "isMutex",
5797 Builtin::kAtomicsMutexIsMutex, 1, kAdapt);
5798 SimpleInstallFunction(isolate(), mutex_fun, "lockAsync",
5799 Builtin::kAtomicsMutexLockAsync, 2, kAdapt);
5800 }
5801
5802 { // Atomics.Condition
5803 DirectHandle<String> condition_str =
5804 isolate()->factory()->InternalizeUtf8String("Condition");
5805 DirectHandle<JSFunction> condition_fun = CreateSharedObjectConstructor(
5806 isolate(), condition_str,
5807 isolate()->factory()->js_atomics_condition_map(),
5808 Builtin::kAtomicsConditionConstructor, 0, kAdapt);
5809 JSObject::AddProperty(isolate(), atomics_object, condition_str,
5810 condition_fun, DONT_ENUM);
5811
5812 SimpleInstallFunction(isolate(), condition_fun, "wait",
5813 Builtin::kAtomicsConditionWait, 2, kDontAdapt);
5814 SimpleInstallFunction(isolate(), condition_fun, "notify",
5815 Builtin::kAtomicsConditionNotify, 2, kDontAdapt);
5816 SimpleInstallFunction(isolate(), condition_fun, "isCondition",
5817 Builtin::kAtomicsConditionIsCondition, 1, kAdapt);
5818 SimpleInstallFunction(isolate(), condition_fun, "waitAsync",
5819 Builtin::kAtomicsConditionWaitAsync, 2, kDontAdapt);
5820 }
5821}
5822
5824 if (v8_flags.enable_sharedarraybuffer_per_context) {
5825 return;
5826 }
5827
5828 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
5829 isolate());
5830
5831 JSObject::AddProperty(isolate_, global, "SharedArrayBuffer",
5832 isolate()->shared_array_buffer_fun(), DONT_ENUM);
5833}
5834
5835void Genesis::InitializeGlobal_js_explicit_resource_management() {
5836 if (!v8_flags.js_explicit_resource_management) return;
5837
5839 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
5840 isolate());
5841
5842 // -- S u p p r e s s e d E r r o r
5843 InstallError(isolate(), global, factory->SuppressedError_string(),
5844 Context::SUPPRESSED_ERROR_FUNCTION_INDEX,
5845 Builtin::kSuppressedErrorConstructor, 3);
5846
5847 // -- D i s p o s a b l e S t a c k
5848 DirectHandle<Map> js_disposable_stack_map =
5850 JS_DISPOSABLE_STACK_BASE_TYPE, JSDisposableStackBase::kHeaderSize);
5851 js_disposable_stack_map->SetConstructor(native_context()->object_function());
5852 native_context()->set_js_disposable_stack_map(*js_disposable_stack_map);
5853 LOG(isolate(), MapDetails(*js_disposable_stack_map));
5854
5855 // SyncDisposableStack
5856 DirectHandle<JSFunction> disposable_stack_function = InstallFunction(
5857 isolate(), global, "DisposableStack", JS_SYNC_DISPOSABLE_STACK_TYPE,
5858 JSSyncDisposableStack::kHeaderSize, 0, factory->the_hole_value(),
5859 Builtin::kDisposableStackConstructor, 0, kDontAdapt);
5860 DirectHandle<JSObject> sync_disposable_stack_prototype(
5861 Cast<JSObject>(disposable_stack_function->instance_prototype()),
5862 isolate());
5863 InstallWithIntrinsicDefaultProto(isolate(), disposable_stack_function,
5864 Context::JS_DISPOSABLE_STACK_FUNCTION_INDEX);
5865
5866 SimpleInstallFunction(isolate(), sync_disposable_stack_prototype, "use",
5867 Builtin::kDisposableStackPrototypeUse, 1, kAdapt);
5869 isolate(), sync_disposable_stack_prototype, "dispose",
5870 Builtin::kDisposableStackPrototypeDispose, 0, kAdapt);
5871 JSObject::AddProperty(isolate(), sync_disposable_stack_prototype,
5872 factory->dispose_symbol(), dispose, DONT_ENUM);
5873 SimpleInstallFunction(isolate(), sync_disposable_stack_prototype, "adopt",
5874 Builtin::kDisposableStackPrototypeAdopt, 2, kAdapt);
5875 SimpleInstallFunction(isolate(), sync_disposable_stack_prototype, "defer",
5876 Builtin::kDisposableStackPrototypeDefer, 1, kAdapt);
5877 SimpleInstallFunction(isolate(), sync_disposable_stack_prototype, "move",
5878 Builtin::kDisposableStackPrototypeMove, 0, kAdapt);
5879
5880 InstallToStringTag(isolate(), sync_disposable_stack_prototype,
5881 "DisposableStack");
5882 SimpleInstallGetter(isolate(), sync_disposable_stack_prototype,
5883 factory->disposed_string(),
5884 Builtin::kDisposableStackPrototypeGetDisposed, kAdapt);
5885
5886 // AsyncDisposableStack
5887 DirectHandle<JSFunction> async_disposable_stack_function = InstallFunction(
5888 isolate(), global, "AsyncDisposableStack", JS_ASYNC_DISPOSABLE_STACK_TYPE,
5889 JSAsyncDisposableStack::kHeaderSize, 0, factory->the_hole_value(),
5890 Builtin::kAsyncDisposableStackConstructor, 0, kDontAdapt);
5891 DirectHandle<JSObject> async_disposable_stack_prototype(
5892 Cast<JSObject>(async_disposable_stack_function->instance_prototype()),
5893 isolate());
5895 isolate(), async_disposable_stack_function,
5896 Context::JS_ASYNC_DISPOSABLE_STACK_FUNCTION_INDEX);
5897
5898 SimpleInstallFunction(isolate(), async_disposable_stack_prototype, "use",
5899 Builtin::kAsyncDisposableStackPrototypeUse, 1, kAdapt);
5901 isolate(), async_disposable_stack_prototype, "disposeAsync",
5902 Builtin::kAsyncDisposableStackPrototypeDisposeAsync, 0, kAdapt);
5903 JSObject::AddProperty(isolate(), async_disposable_stack_prototype,
5904 factory->async_dispose_symbol(), dispose_async,
5905 DONT_ENUM);
5906 SimpleInstallFunction(isolate(), async_disposable_stack_prototype, "adopt",
5907 Builtin::kAsyncDisposableStackPrototypeAdopt, 2,
5908 kAdapt);
5909 SimpleInstallFunction(isolate(), async_disposable_stack_prototype, "defer",
5910 Builtin::kAsyncDisposableStackPrototypeDefer, 1,
5911 kAdapt);
5912 SimpleInstallFunction(isolate(), async_disposable_stack_prototype, "move",
5913 Builtin::kAsyncDisposableStackPrototypeMove, 0, kAdapt);
5914
5915 InstallToStringTag(isolate(), async_disposable_stack_prototype,
5916 "AsyncDisposableStack");
5917 SimpleInstallGetter(
5918 isolate(), async_disposable_stack_prototype, factory->disposed_string(),
5919 Builtin::kAsyncDisposableStackPrototypeGetDisposed, kAdapt);
5920
5921 // Add symbols to iterator prototypes
5922 DirectHandle<JSObject> iterator_prototype(
5923 native_context()->initial_iterator_prototype(), isolate());
5924 InstallFunctionAtSymbol(isolate(), iterator_prototype,
5925 factory->dispose_symbol(), "[Symbol.dispose]",
5926 Builtin::kIteratorPrototypeDispose, 0, kAdapt);
5927
5928 DirectHandle<JSObject> async_iterator_prototype(
5929 native_context()->initial_async_iterator_prototype(), isolate());
5930 InstallFunctionAtSymbol(
5931 isolate(), async_iterator_prototype, factory->async_dispose_symbol(),
5932 "[Symbol.asyncDispose]", Builtin::kAsyncIteratorPrototypeAsyncDispose, 0,
5933 kAdapt);
5934}
5935
5936void Genesis::InitializeGlobal_js_float16array() {
5937 if (!v8_flags.js_float16array) return;
5938
5939 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
5940 isolate());
5941 DirectHandle<JSObject> math = Cast<JSObject>(
5942 JSReceiver::GetProperty(isolate(), global, "Math").ToHandleChecked());
5943
5944 SimpleInstallFunction(isolate_, math, "f16round", Builtin::kMathF16round, 1,
5945 kAdapt);
5946
5947 DirectHandle<JSObject> dataview_prototype(
5948 Cast<JSObject>(native_context()->data_view_fun()->instance_prototype()),
5949 isolate());
5950
5951 SimpleInstallFunction(isolate_, dataview_prototype, "getFloat16",
5952 Builtin::kDataViewPrototypeGetFloat16, 1, kDontAdapt);
5953 SimpleInstallFunction(isolate_, dataview_prototype, "setFloat16",
5954 Builtin::kDataViewPrototypeSetFloat16, 2, kDontAdapt);
5955
5956 DirectHandle<JSFunction> fun = InstallTypedArray(
5957 "Float16Array", FLOAT16_ELEMENTS, FLOAT16_TYPED_ARRAY_CONSTRUCTOR_TYPE,
5958 Context::RAB_GSAB_FLOAT16_ARRAY_MAP_INDEX);
5959
5961 Context::FLOAT16_ARRAY_FUN_INDEX);
5962}
5963
5964void Genesis::InitializeGlobal_js_regexp_escape() {
5965 if (!v8_flags.js_regexp_escape) return;
5966
5967 DirectHandle<JSFunction> regexp_fun(native_context()->regexp_function(),
5968 isolate());
5969 SimpleInstallFunction(isolate(), regexp_fun, "escape", Builtin::kRegExpEscape,
5970 1, kAdapt);
5971}
5972
5973void Genesis::InitializeGlobal_js_source_phase_imports() {
5974 if (!v8_flags.js_source_phase_imports) return;
5975 Factory* factory = isolate()->factory();
5976 // -- %AbstractModuleSource%
5977 // #sec-%abstractmodulesource%
5978 // https://tc39.es/proposal-source-phase-imports/#sec-%abstractmodulesource%
5979 DirectHandle<JSFunction> abstract_module_source_fun =
5980 CreateFunction(isolate_, "AbstractModuleSource", JS_OBJECT_TYPE,
5981 JSObject::kHeaderSize, 0, factory->the_hole_value(),
5982 Builtin::kIllegalInvocationThrower, 0, kDontAdapt);
5983
5984 native_context()->set_abstract_module_source_function(
5985 *abstract_module_source_fun);
5986
5987 // Setup %AbstractModuleSourcePrototype%.
5988 DirectHandle<JSObject> abstract_module_source_prototype(
5989 Cast<JSObject>(abstract_module_source_fun->instance_prototype()),
5990 isolate());
5991 native_context()->set_abstract_module_source_prototype(
5992 *abstract_module_source_prototype);
5993
5994 SimpleInstallGetter(isolate(), abstract_module_source_prototype,
5995 isolate()->factory()->to_string_tag_symbol(),
5996 Builtin::kAbstractModuleSourceToStringTag, kAdapt);
5997}
5998
5999void Genesis::InitializeGlobal_js_base_64() {
6000 if (!v8_flags.js_base_64) return;
6001
6002 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
6003 isolate());
6004 DirectHandle<JSObject> uint8_array_function =
6005 Cast<JSObject>(JSReceiver::GetProperty(isolate(), global, "Uint8Array")
6006 .ToHandleChecked());
6007 SimpleInstallFunction(isolate(), uint8_array_function, "fromBase64",
6008 Builtin::kUint8ArrayFromBase64, 1, kDontAdapt);
6009 SimpleInstallFunction(isolate(), uint8_array_function, "fromHex",
6010 Builtin::kUint8ArrayFromHex, 1, kDontAdapt);
6011
6012 DirectHandle<JSObject> uint8_array_prototype(
6014 Cast<JSFunction>(uint8_array_function)->instance_prototype()),
6015 isolate());
6016 SimpleInstallFunction(isolate(), uint8_array_prototype, "toBase64",
6017 Builtin::kUint8ArrayPrototypeToBase64, 0, kDontAdapt);
6018 SimpleInstallFunction(isolate(), uint8_array_prototype, "toHex",
6019 Builtin::kUint8ArrayPrototypeToHex, 0, kDontAdapt);
6020}
6021
6023 if (!v8_flags.enable_experimental_regexp_engine) return;
6024
6025 DirectHandle<JSFunction> regexp_fun(native_context()->regexp_function(),
6026 isolate());
6027 DirectHandle<JSObject> regexp_prototype(
6028 Cast<JSObject>(regexp_fun->instance_prototype()), isolate());
6029 SimpleInstallGetter(isolate(), regexp_prototype,
6030 isolate()->factory()->linear_string(),
6031 Builtin::kRegExpPrototypeLinearGetter, kAdapt);
6032
6033 // Store regexp prototype map again after change.
6034 native_context()->set_regexp_prototype_map(regexp_prototype->map());
6035}
6036
6037void Genesis::InitializeGlobal_harmony_temporal() {
6038 if (!v8_flags.harmony_temporal) return;
6039
6040 // The Temporal object is set up lazily upon first access.
6041 {
6042 DirectHandle<JSGlobalObject> global(native_context()->global_object(),
6043 isolate());
6046 isolate(), name, LazyInitializeGlobalThisTemporal, nullptr);
6047 accessor->set_replace_on_access(true);
6048 JSObject::SetAccessor(global, name, accessor, DONT_ENUM).Check();
6049 }
6050
6051 // Likewise Date.toTemporalInstant.
6052 {
6053 DirectHandle<JSFunction> date_func(native_context()->date_function(),
6054 isolate());
6055 DirectHandle<JSObject> date_prototype(
6056 Cast<JSObject>(date_func->instance_prototype()), isolate());
6057 DirectHandle<String> name =
6058 factory()->InternalizeUtf8String("toTemporalInstant");
6059 DirectHandle<AccessorInfo> accessor = Accessors::MakeAccessor(
6060 isolate(), name, LazyInitializeDateToTemporalInstant, nullptr);
6061 accessor->set_replace_on_access(true);
6062 JSObject::SetAccessor(date_prototype, name, accessor, DONT_ENUM).Check();
6063 }
6064}
6065
6067 DirectHandle<String> name, ArrayBufferKind array_buffer_kind) {
6068 // Create the %ArrayBufferPrototype%
6069 // Setup the {prototype} with the given {name} for @@toStringTag.
6071 isolate()->object_function(), AllocationType::kOld);
6072 InstallToStringTag(isolate(), prototype, name);
6073
6074 // Allocate the constructor with the given {prototype}.
6075 DirectHandle<JSFunction> array_buffer_fun =
6076 CreateFunction(isolate(), name, JS_ARRAY_BUFFER_TYPE,
6078 Builtin::kArrayBufferConstructor, 1, kAdapt);
6079
6080 // Install the "constructor" property on the {prototype}.
6081 JSObject::AddProperty(isolate(), prototype, factory()->constructor_string(),
6082 array_buffer_fun, DONT_ENUM);
6083
6084 switch (array_buffer_kind) {
6085 case ARRAY_BUFFER:
6086 InstallFunctionWithBuiltinId(isolate(), array_buffer_fun, "isView",
6087 Builtin::kArrayBufferIsView, 1, kAdapt);
6088
6089 // Install the "byteLength" getter on the {prototype}.
6090 SimpleInstallGetter(isolate(), prototype, factory()->byte_length_string(),
6091 Builtin::kArrayBufferPrototypeGetByteLength, kAdapt);
6092 SimpleInstallFunction(isolate(), prototype, "slice",
6093 Builtin::kArrayBufferPrototypeSlice, 2, kAdapt);
6094 break;
6095
6097 // Install the "byteLength" getter on the {prototype}.
6098 SimpleInstallGetter(isolate(), prototype, factory()->byte_length_string(),
6099 Builtin::kSharedArrayBufferPrototypeGetByteLength,
6100 kDontAdapt);
6101 SimpleInstallFunction(isolate(), prototype, "slice",
6102 Builtin::kSharedArrayBufferPrototypeSlice, 2,
6103 kAdapt);
6104 break;
6105 }
6106
6107 return array_buffer_fun;
6108}
6109
6110// TODO(jgruber): Refactor this into some kind of meaningful organization. There
6111// is likely no reason remaining for these objects to be installed here. For
6112// example, global object setup done in this function could likely move to
6113// InitializeGlobal.
6115 HandleScope scope(isolate());
6116
6117 auto fast_template_instantiations_cache =
6120 native_context()->set_fast_template_instantiations_cache(
6121 *fast_template_instantiations_cache);
6122
6123 auto slow_template_instantiations_cache =
6124 EphemeronHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize);
6125 native_context()->set_slow_template_instantiations_cache(
6126 *slow_template_instantiations_cache);
6127
6128 auto wasm_debug_maps = isolate()->factory()->empty_fixed_array();
6129 native_context()->set_wasm_debug_maps(*wasm_debug_maps);
6130
6131 // Store the map for the %ObjectPrototype% after the natives has been compiled
6132 // and the Object function has been set up.
6133 {
6134 DirectHandle<JSFunction> object_function(
6135 native_context()->object_function(), isolate());
6136 DCHECK(Cast<JSObject>(object_function->initial_map()->prototype())
6137 ->HasFastProperties());
6138 native_context()->set_object_function_prototype(
6139 Cast<JSObject>(object_function->initial_map()->prototype()));
6140 native_context()->set_object_function_prototype_map(
6141 Cast<HeapObject>(object_function->initial_map()->prototype())->map());
6142 }
6143
6144 // Store the map for the %StringPrototype% after the natives has been compiled
6145 // and the String function has been set up.
6146 DirectHandle<JSFunction> string_function(native_context()->string_function(),
6147 isolate());
6148 Tagged<JSObject> string_function_prototype =
6149 Cast<JSObject>(string_function->initial_map()->prototype());
6150 DCHECK(string_function_prototype->HasFastProperties());
6151 native_context()->set_string_function_prototype_map(
6152 string_function_prototype->map());
6153
6154 DirectHandle<JSGlobalObject> global_object(native_context()->global_object(),
6155 isolate());
6156
6157 // Install Global.decodeURI.
6158 InstallFunctionWithBuiltinId(isolate(), global_object, "decodeURI",
6159 Builtin::kGlobalDecodeURI, 1, kDontAdapt);
6160
6161 // Install Global.decodeURIComponent.
6162 InstallFunctionWithBuiltinId(isolate(), global_object, "decodeURIComponent",
6163 Builtin::kGlobalDecodeURIComponent, 1,
6164 kDontAdapt);
6165
6166 // Install Global.encodeURI.
6167 InstallFunctionWithBuiltinId(isolate(), global_object, "encodeURI",
6168 Builtin::kGlobalEncodeURI, 1, kDontAdapt);
6169
6170 // Install Global.encodeURIComponent.
6171 InstallFunctionWithBuiltinId(isolate(), global_object, "encodeURIComponent",
6172 Builtin::kGlobalEncodeURIComponent, 1,
6173 kDontAdapt);
6174
6175 // Install Global.escape.
6176 InstallFunctionWithBuiltinId(isolate(), global_object, "escape",
6177 Builtin::kGlobalEscape, 1, kDontAdapt);
6178
6179 // Install Global.unescape.
6180 InstallFunctionWithBuiltinId(isolate(), global_object, "unescape",
6181 Builtin::kGlobalUnescape, 1, kDontAdapt);
6182
6183 // Install Global.eval.
6184 {
6186 isolate(), global_object, "eval", Builtin::kGlobalEval, 1, kDontAdapt);
6187 native_context()->set_global_eval_fun(*eval);
6188 }
6189
6190 // Install Global.isFinite
6191 InstallFunctionWithBuiltinId(isolate(), global_object, "isFinite",
6192 Builtin::kGlobalIsFinite, 1, kAdapt);
6193
6194 // Install Global.isNaN
6195 InstallFunctionWithBuiltinId(isolate(), global_object, "isNaN",
6196 Builtin::kGlobalIsNaN, 1, kAdapt);
6197
6198 // Install Array builtin functions.
6199 {
6200 DirectHandle<JSFunction> array_constructor(
6201 native_context()->array_function(), isolate());
6202 DirectHandle<JSArray> proto(Cast<JSArray>(array_constructor->prototype()),
6203 isolate());
6204
6205 // Verification of important array prototype properties.
6206 Tagged<Object> length = proto->length();
6207 CHECK(IsSmi(length));
6208 CHECK_EQ(Smi::ToInt(length), 0);
6209 CHECK(proto->HasSmiOrObjectElements());
6210 // This is necessary to enable fast checks for absence of elements
6211 // on Array.prototype and below.
6212 proto->set_elements(ReadOnlyRoots(heap()).empty_fixed_array());
6213 }
6214
6215 // Create a map for accessor property descriptors (a variant of JSObject
6216 // that predefines four properties get, set, configurable and enumerable).
6217 {
6218 // AccessorPropertyDescriptor initial map.
6220 JS_OBJECT_TYPE, JSAccessorPropertyDescriptor::kSize,
6222 // Create the descriptor array for the property descriptor object.
6224
6225 { // get
6226 Descriptor d =
6227 Descriptor::DataField(isolate(), factory()->get_string(),
6228 JSAccessorPropertyDescriptor::kGetIndex, NONE,
6230 map->AppendDescriptor(isolate(), &d);
6231 }
6232 { // set
6233 Descriptor d =
6234 Descriptor::DataField(isolate(), factory()->set_string(),
6237 map->AppendDescriptor(isolate(), &d);
6238 }
6239 { // enumerable
6240 Descriptor d =
6241 Descriptor::DataField(isolate(), factory()->enumerable_string(),
6244 map->AppendDescriptor(isolate(), &d);
6245 }
6246 { // configurable
6248 isolate(), factory()->configurable_string(),
6251 map->AppendDescriptor(isolate(), &d);
6252 }
6253
6254 Map::SetPrototype(isolate(), map, isolate()->initial_object_prototype());
6255 map->SetConstructor(native_context()->object_function());
6256
6257 native_context()->set_accessor_property_descriptor_map(*map);
6258 }
6259
6260 // Create a map for data property descriptors (a variant of JSObject
6261 // that predefines four properties value, writable, configurable and
6262 // enumerable).
6263 {
6264 // DataPropertyDescriptor initial map.
6266 JS_OBJECT_TYPE, JSDataPropertyDescriptor::kSize,
6268 // Create the descriptor array for the property descriptor object.
6270
6271 { // value
6272 Descriptor d =
6273 Descriptor::DataField(isolate(), factory()->value_string(),
6274 JSDataPropertyDescriptor::kValueIndex, NONE,
6276 map->AppendDescriptor(isolate(), &d);
6277 }
6278 { // writable
6279 Descriptor d =
6280 Descriptor::DataField(isolate(), factory()->writable_string(),
6283 map->AppendDescriptor(isolate(), &d);
6284 }
6285 { // enumerable
6286 Descriptor d =
6287 Descriptor::DataField(isolate(), factory()->enumerable_string(),
6290 map->AppendDescriptor(isolate(), &d);
6291 }
6292 { // configurable
6293 Descriptor d =
6294 Descriptor::DataField(isolate(), factory()->configurable_string(),
6297 map->AppendDescriptor(isolate(), &d);
6298 }
6299
6300 Map::SetPrototype(isolate(), map, isolate()->initial_object_prototype());
6301 map->SetConstructor(native_context()->object_function());
6302
6303 native_context()->set_data_property_descriptor_map(*map);
6304 }
6305
6306 {
6307 // -- TemplateLiteral JSArray Map
6308 DirectHandle<JSFunction> array_function(native_context()->array_function(),
6309 isolate());
6310 DirectHandle<Map> template_map(array_function->initial_map(), isolate_);
6311 template_map = Map::CopyAsElementsKind(isolate_, template_map,
6313 DCHECK_GE(TemplateLiteralObject::kHeaderSize,
6314 template_map->instance_size());
6315 template_map->set_instance_size(TemplateLiteralObject::kHeaderSize);
6316 // Temporarily instantiate a full template_literal_object to get the final
6317 // map.
6318 auto template_object =
6319 Cast<JSArray>(factory()->NewJSObjectFromMap(template_map));
6320 {
6322 Tagged<JSArray> raw = *template_object;
6323 raw->set_elements(ReadOnlyRoots(isolate()).empty_fixed_array());
6324 raw->set_length(Smi::FromInt(0));
6325 }
6326
6327 // Install a "raw" data property for {raw_object} on {template_object}.
6328 // See ES#sec-gettemplateobject.
6329 PropertyDescriptor raw_desc;
6330 // Use arbrirary object {template_object} as ".raw" value.
6331 raw_desc.set_value(template_object);
6332 raw_desc.set_configurable(false);
6333 raw_desc.set_enumerable(false);
6334 raw_desc.set_writable(false);
6335 JSArray::DefineOwnProperty(isolate(), template_object,
6336 factory()->raw_string(), &raw_desc,
6338 .ToChecked();
6339 // Install private symbol fields for function_literal_id and slot_id.
6340 raw_desc.set_value(direct_handle(Smi::zero(), isolate()));
6342 isolate(), template_object,
6343 factory()->template_literal_function_literal_id_symbol(), &raw_desc,
6345 .ToChecked();
6346 JSArray::DefineOwnProperty(isolate(), template_object,
6347 factory()->template_literal_slot_id_symbol(),
6348 &raw_desc, Just(kThrowOnError))
6349 .ToChecked();
6350
6351 // Freeze the {template_object} as well.
6352 JSObject::SetIntegrityLevel(isolate(), template_object, FROZEN,
6354 .ToChecked();
6355 {
6358 template_object->map()->instance_descriptors();
6359 {
6360 // Verify TemplateLiteralObject::kRawOffset
6361 InternalIndex descriptor_index = desc->Search(
6362 *factory()->raw_string(), desc->number_of_descriptors());
6363 FieldIndex index =
6364 FieldIndex::ForDescriptor(template_object->map(), descriptor_index);
6365 CHECK(index.is_inobject());
6366 CHECK_EQ(index.offset(), TemplateLiteralObject::kRawOffset);
6367 }
6368
6369 {
6370 // Verify TemplateLiteralObject::kFunctionLiteralIdOffset
6371 InternalIndex descriptor_index = desc->Search(
6372 *factory()->template_literal_function_literal_id_symbol(),
6373 desc->number_of_descriptors());
6374 FieldIndex index =
6375 FieldIndex::ForDescriptor(template_object->map(), descriptor_index);
6376 CHECK(index.is_inobject());
6377 CHECK_EQ(index.offset(),
6378 TemplateLiteralObject::kFunctionLiteralIdOffset);
6379 }
6380
6381 {
6382 // Verify TemplateLiteralObject::kSlotIdOffset
6383 InternalIndex descriptor_index =
6384 desc->Search(*factory()->template_literal_slot_id_symbol(),
6385 desc->number_of_descriptors());
6386 FieldIndex index =
6387 FieldIndex::ForDescriptor(template_object->map(), descriptor_index);
6388 CHECK(index.is_inobject());
6389 CHECK_EQ(index.offset(), TemplateLiteralObject::kSlotIdOffset);
6390 }
6391 }
6392
6393 native_context()->set_js_array_template_literal_object_map(
6394 template_object->map());
6395 }
6396
6397 // Create a constructor for RegExp results (a variant of Array that
6398 // predefines the properties index, input, and groups).
6399 {
6400 // JSRegExpResult initial map.
6401 // Add additional slack to the initial map in case regexp_match_indices
6402 // are enabled to account for the additional descriptor.
6404 JSRegExpResult::kSize, JSRegExpResult::kInObjectPropertyCount);
6405
6406 // index descriptor.
6407 {
6408 Descriptor d = Descriptor::DataField(isolate(), factory()->index_string(),
6411 initial_map->AppendDescriptor(isolate(), &d);
6412 }
6413
6414 // input descriptor.
6415 {
6416 Descriptor d = Descriptor::DataField(isolate(), factory()->input_string(),
6419 initial_map->AppendDescriptor(isolate(), &d);
6420 }
6421
6422 // groups descriptor.
6423 {
6425 isolate(), factory()->groups_string(), JSRegExpResult::kGroupsIndex,
6427 initial_map->AppendDescriptor(isolate(), &d);
6428 }
6429
6430 // Private internal only fields. All of the remaining fields have special
6431 // symbols to prevent their use in Javascript.
6432 {
6433 PropertyAttributes attribs = DONT_ENUM;
6434
6435 // names descriptor.
6436 {
6438 isolate(), factory()->regexp_result_names_symbol(),
6440 initial_map->AppendDescriptor(isolate(), &d);
6441 }
6442
6443 // regexp_input_index descriptor.
6444 {
6446 isolate(), factory()->regexp_result_regexp_input_symbol(),
6449 initial_map->AppendDescriptor(isolate(), &d);
6450 }
6451
6452 // regexp_last_index descriptor.
6453 {
6455 isolate(), factory()->regexp_result_regexp_last_index_symbol(),
6458 initial_map->AppendDescriptor(isolate(), &d);
6459 }
6460 }
6461
6462 // Set up the map for RegExp results objects for regexps with the /d flag.
6463 DirectHandle<Map> initial_with_indices_map =
6464 Map::Copy(isolate(), initial_map, "JSRegExpResult with indices");
6465 initial_with_indices_map->set_instance_size(
6466 JSRegExpResultWithIndices::kSize);
6467 DCHECK_EQ(initial_with_indices_map->GetInObjectProperties(),
6469
6470 // indices descriptor
6471 {
6472 Descriptor d =
6473 Descriptor::DataField(isolate(), factory()->indices_string(),
6476 Map::EnsureDescriptorSlack(isolate(), initial_with_indices_map, 1);
6477 initial_with_indices_map->AppendDescriptor(isolate(), &d);
6478 }
6479
6480 native_context()->set_regexp_result_map(*initial_map);
6481 native_context()->set_regexp_result_with_indices_map(
6482 *initial_with_indices_map);
6483 }
6484
6485 // Create a constructor for JSRegExpResultIndices (a variant of Array that
6486 // predefines the groups property).
6487 {
6488 // JSRegExpResultIndices initial map.
6490 JSRegExpResultIndices::kSize,
6492
6493 // groups descriptor.
6494 {
6496 isolate(), factory()->groups_string(),
6498 initial_map->AppendDescriptor(isolate(), &d);
6499 DCHECK_EQ(initial_map->LastAdded().as_int(),
6501 }
6502
6503 native_context()->set_regexp_result_indices_map(*initial_map);
6504 }
6505
6506 // Add @@iterator method to the arguments object maps.
6507 {
6508 PropertyAttributes attribs = DONT_ENUM;
6509 DirectHandle<AccessorInfo> arguments_iterator =
6510 factory()->arguments_iterator_accessor();
6511 {
6512 Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
6513 arguments_iterator, attribs);
6514 DirectHandle<Map> map(native_context()->sloppy_arguments_map(),
6515 isolate());
6517 map->AppendDescriptor(isolate(), &d);
6518 }
6519 {
6520 Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
6521 arguments_iterator, attribs);
6522 DirectHandle<Map> map(native_context()->fast_aliased_arguments_map(),
6523 isolate());
6525 map->AppendDescriptor(isolate(), &d);
6526 }
6527 {
6528 Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
6529 arguments_iterator, attribs);
6530 DirectHandle<Map> map(native_context()->slow_aliased_arguments_map(),
6531 isolate());
6533 map->AppendDescriptor(isolate(), &d);
6534 }
6535 {
6536 Descriptor d = Descriptor::AccessorConstant(factory()->iterator_symbol(),
6537 arguments_iterator, attribs);
6538 DirectHandle<Map> map(native_context()->strict_arguments_map(),
6539 isolate());
6541 map->AppendDescriptor(isolate(), &d);
6542 }
6543 }
6544 {
6546 OrderedHashSet::Allocate(isolate(), 0).ToHandleChecked();
6547 native_context()->set_atomics_waitasync_promises(*promises);
6548 }
6549
6550 return true;
6551}
6552
6554 HandleScope scope(isolate());
6555
6557
6558 // binding.isTraceCategoryEnabled(category)
6559 SimpleInstallFunction(isolate(), extras_binding, "isTraceCategoryEnabled",
6560 Builtin::kIsTraceCategoryEnabled, 1, kAdapt);
6561
6562 // binding.trace(phase, category, name, id, data)
6563 SimpleInstallFunction(isolate(), extras_binding, "trace", Builtin::kTrace, 5,
6564 kAdapt);
6565
6566#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
6567 // binding.getContinuationPreservedEmbedderData()
6569 isolate(), extras_binding, "getContinuationPreservedEmbedderData",
6570 Builtin::kGetContinuationPreservedEmbedderData, 0, kAdapt);
6571
6572 // binding.setContinuationPreservedEmbedderData(value)
6574 isolate(), extras_binding, "setContinuationPreservedEmbedderData",
6575 Builtin::kSetContinuationPreservedEmbedderData, 1, kAdapt);
6576#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
6577
6578 InitializeConsole(extras_binding);
6579
6580 native_context()->set_extras_binding_object(*extras_binding);
6581
6582 return true;
6583}
6584
6586 {
6588 native_context()->set_normalized_map_cache(*cache);
6589 }
6590
6591 {
6594
6596 for (int i = 0; i < JSObject::kMapCacheSize; i++) {
6597 cache->set(i, ClearedValue(isolate()));
6598 }
6599 native_context()->set_map_cache(*cache);
6600 Tagged<Map> initial = native_context()->object_function()->initial_map();
6601 cache->set(0, MakeWeak(initial));
6602 cache->set(initial->GetInObjectProperties(), MakeWeak(initial));
6603 }
6604}
6605
6607 v8::ExtensionConfiguration* extensions) {
6608 // Don't install extensions into the snapshot.
6609 if (isolate_->serializer_enabled()) return true;
6610 BootstrapperActive active(this);
6611 v8::Context::Scope context_scope(Utils::ToLocal(native_context));
6612 return Genesis::InstallExtensions(isolate_, native_context, extensions) &&
6614}
6615
6618 HandleScope scope(isolate);
6619
6620 // Error.stackTraceLimit.
6621 {
6622 DirectHandle<JSObject> Error = isolate->error_function();
6623 DirectHandle<String> name = isolate->factory()->stackTraceLimit_string();
6624 DirectHandle<Smi> stack_trace_limit(
6625 Smi::FromInt(v8_flags.stack_trace_limit), isolate);
6626 JSObject::AddProperty(isolate, Error, name, stack_trace_limit, NONE);
6627 }
6628
6629#if V8_ENABLE_WEBASSEMBLY
6630 WasmJs::Install(isolate);
6631#endif // V8_ENABLE_WEBASSEMBLY
6632
6633#ifdef V8_ENABLE_MEMORY_CORRUPTION_API
6634 if (v8_flags.expose_memory_corruption_api) {
6635 SandboxTesting::InstallMemoryCorruptionApi(isolate);
6636 }
6637#endif // V8_ENABLE_MEMORY_CORRUPTION_API
6638
6639 return true;
6640}
6641
6645
6647
6651 if (entry == nullptr) {
6652 return UNVISITED;
6653 }
6654 return static_cast<ExtensionTraversalState>(
6655 reinterpret_cast<intptr_t>(entry->value));
6656}
6657
6660 map_.LookupOrInsert(extension, Hash(extension))->value =
6661 reinterpret_cast<void*>(static_cast<intptr_t>(state));
6662}
6663
6666 v8::ExtensionConfiguration* extensions) {
6667 ExtensionStates extension_states; // All extensions have state UNVISITED.
6668 return InstallAutoExtensions(isolate, &extension_states) &&
6669 (!v8_flags.expose_gc ||
6670 InstallExtension(isolate, "v8/gc", &extension_states)) &&
6671 (!v8_flags.expose_externalize_string ||
6672 InstallExtension(isolate, "v8/externalize", &extension_states)) &&
6673 (!(v8_flags.expose_statistics ||
6675 InstallExtension(isolate, "v8/statistics", &extension_states)) &&
6676 (!v8_flags.expose_trigger_failure ||
6677 InstallExtension(isolate, "v8/trigger-failure", &extension_states)) &&
6678 (!v8_flags.expose_ignition_statistics ||
6679 InstallExtension(isolate, "v8/ignition-statistics",
6680 &extension_states)) &&
6682 InstallExtension(isolate, "v8/cpumark", &extension_states)) &&
6683#ifdef V8_FUZZILLI
6684 InstallExtension(isolate, "v8/fuzzilli", &extension_states) &&
6685#endif
6686#ifdef ENABLE_VTUNE_TRACEMARK
6687 (!v8_flags.enable_vtune_domain_support ||
6688 InstallExtension(isolate, "v8/vtunedomain", &extension_states)) &&
6689#endif // ENABLE_VTUNE_TRACEMARK
6690 InstallRequestedExtensions(isolate, extensions, &extension_states);
6691}
6692
6694 ExtensionStates* extension_states) {
6696 it != nullptr; it = it->next()) {
6697 if (it->extension()->auto_enable() &&
6698 !InstallExtension(isolate, it, extension_states)) {
6699 return false;
6700 }
6701 }
6702 return true;
6703}
6704
6706 v8::ExtensionConfiguration* extensions,
6707 ExtensionStates* extension_states) {
6708 for (const char** it = extensions->begin(); it != extensions->end(); ++it) {
6709 if (!InstallExtension(isolate, *it, extension_states)) return false;
6710 }
6711 return true;
6712}
6713
6714// Installs a named extension. This methods is unoptimized and does
6715// not scale well if we want to support a large number of extensions.
6716bool Genesis::InstallExtension(Isolate* isolate, const char* name,
6717 ExtensionStates* extension_states) {
6719 it != nullptr; it = it->next()) {
6720 if (strcmp(name, it->extension()->name()) == 0) {
6721 return InstallExtension(isolate, it, extension_states);
6722 }
6723 }
6724 return Utils::ApiCheck(false, "v8::Context::New()",
6725 "Cannot find required extension");
6726}
6727
6729 v8::RegisteredExtension* current,
6730 ExtensionStates* extension_states) {
6731 HandleScope scope(isolate);
6732
6733 if (extension_states->get_state(current) == INSTALLED) return true;
6734 // The current node has already been visited so there must be a
6735 // cycle in the dependency graph; fail.
6736 if (!Utils::ApiCheck(extension_states->get_state(current) != VISITED,
6737 "v8::Context::New()", "Circular extension dependency")) {
6738 return false;
6739 }
6740 DCHECK(extension_states->get_state(current) == UNVISITED);
6741 extension_states->set_state(current, VISITED);
6742 v8::Extension* extension = current->extension();
6743 // Install the extension's dependencies
6744 for (int i = 0; i < extension->dependency_count(); i++) {
6745 if (!InstallExtension(isolate, extension->dependencies()[i],
6746 extension_states)) {
6747 return false;
6748 }
6749 }
6750 if (!CompileExtension(isolate, extension)) {
6751 // We print out the name of the extension that fail to install.
6752 // When an error is thrown during bootstrapping we automatically print
6753 // the line number at which this happened to the console in the isolate
6754 // error throwing functionality.
6755 base::OS::PrintError("Error installing extension '%s'.\n",
6756 current->extension()->name());
6757 return false;
6758 }
6759
6760 DCHECK(!isolate->has_exception());
6761 extension_states->set_state(current, INSTALLED);
6762 return true;
6763}
6764
6766 v8::Local<v8::ObjectTemplate> global_proxy_template) {
6768 isolate());
6769 DirectHandle<JSObject> global_object(native_context()->global_object(),
6770 isolate());
6771
6772 if (!global_proxy_template.IsEmpty()) {
6773 // Configure the global proxy object.
6774 DirectHandle<ObjectTemplateInfo> global_proxy_data =
6775 v8::Utils::OpenDirectHandle(*global_proxy_template);
6776 if (!ConfigureApiObject(global_proxy, global_proxy_data)) {
6777 base::OS::PrintError("V8 Error: Failed to configure global_proxy_data\n");
6778 return false;
6779 }
6780
6781 // Configure the global object.
6782 DirectHandle<FunctionTemplateInfo> proxy_constructor(
6783 Cast<FunctionTemplateInfo>(global_proxy_data->constructor()),
6784 isolate());
6785 if (!IsUndefined(proxy_constructor->GetPrototypeTemplate(), isolate())) {
6786 DirectHandle<ObjectTemplateInfo> global_object_data(
6787 Cast<ObjectTemplateInfo>(proxy_constructor->GetPrototypeTemplate()),
6788 isolate());
6789 if (!ConfigureApiObject(global_object, global_object_data)) {
6790 base::OS::PrintError(
6791 "V8 Error: Failed to configure global_object_data\n");
6792 return false;
6793 }
6794 }
6795 }
6796
6798
6799 native_context()->set_array_buffer_map(
6800 native_context()->array_buffer_fun()->initial_map());
6801
6802 return true;
6803}
6804
6807 DirectHandle<ObjectTemplateInfo> object_template) {
6808 DCHECK(!object_template.is_null());
6809 DCHECK(Cast<FunctionTemplateInfo>(object_template->constructor())
6810 ->IsTemplateFor(object->map()));
6811
6812 MaybeDirectHandle<JSObject> maybe_obj =
6813 ApiNatives::InstantiateObject(object->GetIsolate(), object_template);
6814 DirectHandle<JSObject> instantiated_template;
6815 if (!maybe_obj.ToHandle(&instantiated_template)) {
6816 DCHECK(isolate()->has_exception());
6817
6818 DirectHandle<String> message =
6821 .ToHandleChecked();
6822 base::OS::PrintError(
6823 "V8 Error: Exception in Genesis::ConfigureApiObject: %s\n",
6824 message->ToCString().get());
6825
6827 return false;
6828 }
6829 TransferObject(instantiated_template, object);
6830 return true;
6831}
6832
6837 return it.IsFound();
6838}
6839
6842 // If JSObject::AddProperty asserts due to already existing property,
6843 // it is likely due to both global objects sharing property name(s).
6844 // Merging those two global objects is impossible.
6845 // The global template must not create properties that already exist
6846 // in the snapshotted global object.
6847 if (from->HasFastProperties()) {
6849 from->map()->instance_descriptors(isolate()), isolate());
6850 for (InternalIndex i : from->map()->IterateOwnDescriptors()) {
6851 PropertyDetails details = descs->GetDetails(i);
6852 if (details.location() == PropertyLocation::kField) {
6853 if (details.kind() == PropertyKind::kData) {
6854 HandleScope inner(isolate());
6855 DirectHandle<Name> key(descs->GetKey(i), isolate());
6856 // If the property is already there we skip it.
6857 if (PropertyAlreadyExists(isolate(), to, key)) continue;
6858 FieldIndex index = FieldIndex::ForDetails(from->map(), details);
6860 isolate(), from, details.representation(), index);
6861 JSObject::AddProperty(isolate(), to, key, value,
6862 details.attributes());
6863 } else {
6865 UNREACHABLE();
6866 }
6867
6868 } else {
6871 DirectHandle<Name> key(descs->GetKey(i), isolate());
6872 // If the property is already there we skip it.
6873 if (PropertyAlreadyExists(isolate(), to, key)) continue;
6874 HandleScope inner(isolate());
6875 DCHECK(!to->HasFastProperties());
6876 // Add to dictionary.
6877 DirectHandle<Object> value(descs->GetStrongValue(i), isolate());
6880 JSObject::SetNormalizedProperty(to, key, value, d);
6881 }
6882 }
6883 } else if (IsJSGlobalObject(*from)) {
6884 // Copy all keys and values in enumeration order.
6886 Cast<JSGlobalObject>(*from)->global_dictionary(kAcquireLoad),
6887 isolate());
6888 DirectHandle<FixedArray> indices =
6889 GlobalDictionary::IterationIndices(isolate(), properties);
6890 for (int i = 0; i < indices->length(); i++) {
6891 InternalIndex index(Smi::ToInt(indices->get(i)));
6892 DirectHandle<PropertyCell> cell(properties->CellAt(index), isolate());
6893 DirectHandle<Name> key(cell->name(), isolate());
6894 // If the property is already there we skip it.
6895 if (PropertyAlreadyExists(isolate(), to, key)) continue;
6896 // Set the property.
6897 DirectHandle<Object> value(cell->value(), isolate());
6898 if (IsTheHole(*value, isolate())) continue;
6899 PropertyDetails details = cell->property_details();
6900 if (details.kind() == PropertyKind::kData) {
6901 JSObject::AddProperty(isolate(), to, key, value, details.attributes());
6902 } else {
6904 DCHECK(!to->HasFastProperties());
6907 JSObject::SetNormalizedProperty(to, key, value, d);
6908 }
6909 }
6910
6912 // Copy all keys and values in enumeration order.
6914 from->property_dictionary_swiss(), isolate());
6915 ReadOnlyRoots roots(isolate());
6916 for (InternalIndex entry : properties->IterateEntriesOrdered()) {
6917 Tagged<Object> raw_key;
6918 if (!properties->ToKey(roots, entry, &raw_key)) continue;
6919
6920 DCHECK(IsName(raw_key));
6922 // If the property is already there we skip it.
6923 if (PropertyAlreadyExists(isolate(), to, key)) continue;
6924 // Set the property.
6925 DirectHandle<Object> value(properties->ValueAt(entry), isolate());
6926 DCHECK(!IsCell(*value));
6927 DCHECK(!IsTheHole(*value, isolate()));
6928 PropertyDetails details = properties->DetailsAt(entry);
6930 JSObject::AddProperty(isolate(), to, key, value, details.attributes());
6931 }
6932 } else {
6933 // Copy all keys and values in enumeration order.
6934 DirectHandle<NameDictionary> properties(from->property_dictionary(),
6935 isolate());
6936 DirectHandle<FixedArray> key_indices =
6937 NameDictionary::IterationIndices(isolate(), properties);
6938 ReadOnlyRoots roots(isolate());
6939 for (int i = 0; i < key_indices->length(); i++) {
6940 InternalIndex key_index(Smi::ToInt(key_indices->get(i)));
6941 Tagged<Object> raw_key = properties->KeyAt(key_index);
6942 DCHECK(properties->IsKey(roots, raw_key));
6943 DCHECK(IsName(raw_key));
6945 // If the property is already there we skip it.
6946 if (PropertyAlreadyExists(isolate(), to, key)) continue;
6947 // Set the property.
6948 DirectHandle<Object> value(properties->ValueAt(key_index), isolate());
6949 DCHECK(!IsCell(*value));
6950 DCHECK(!IsTheHole(*value, isolate()));
6951 PropertyDetails details = properties->DetailsAt(key_index);
6953 JSObject::AddProperty(isolate(), to, key, value, details.attributes());
6954 }
6955 }
6956}
6957
6960 // Cloning the elements array is sufficient.
6961 Handle<FixedArray> from_elements(Cast<FixedArray>(from->elements()),
6962 isolate());
6963 DirectHandle<FixedArray> to_elements =
6964 factory()->CopyFixedArray(from_elements);
6965 to->set_elements(*to_elements);
6966}
6967
6970 HandleScope outer(isolate());
6971
6972 DCHECK(!IsJSArray(*from));
6973 DCHECK(!IsJSArray(*to));
6974
6975 TransferNamedProperties(from, to);
6976 TransferIndexedProperties(from, to);
6977
6978 // Transfer the prototype (new map is needed).
6979 DirectHandle<JSPrototype> proto(from->map()->prototype(), isolate());
6981}
6982
6984 int size, int inobject_properties) {
6985 // Find global.Array.prototype to inherit from.
6986 DirectHandle<JSFunction> array_constructor(native_context()->array_function(),
6987 isolate());
6988 DirectHandle<JSObject> array_prototype(
6989 native_context()->initial_array_prototype(), isolate());
6990
6991 // Add initial map.
6993 JS_ARRAY_TYPE, size, TERMINAL_FAST_ELEMENTS_KIND, inobject_properties);
6994 initial_map->SetConstructor(*array_constructor);
6995
6996 // Set prototype on map.
6997 initial_map->set_has_non_instance_prototype(false);
6998 Map::SetPrototype(isolate(), initial_map, array_prototype);
6999
7000 // Update map with length accessor from Array.
7001 static constexpr int kTheLengthAccessor = 1;
7002 Map::EnsureDescriptorSlack(isolate(), initial_map,
7003 inobject_properties + kTheLengthAccessor);
7004
7005 // length descriptor.
7006 {
7007 Tagged<JSFunction> array_function = native_context()->array_function();
7008 DirectHandle<DescriptorArray> array_descriptors(
7009 array_function->initial_map()->instance_descriptors(isolate()),
7010 isolate());
7011 DirectHandle<String> length = factory()->length_string();
7012 InternalIndex old = array_descriptors->SearchWithCache(
7013 isolate(), *length, array_function->initial_map());
7014 DCHECK(old.is_found());
7016 length,
7017 direct_handle(array_descriptors->GetStrongValue(old), isolate()),
7018 array_descriptors->GetDetails(old).attributes());
7019 initial_map->AppendDescriptor(isolate(), &d);
7020 }
7021 return initial_map;
7022}
7023
7025 MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
7026 v8::Local<v8::ObjectTemplate> global_proxy_template,
7027 size_t context_snapshot_index,
7028 DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
7030 : isolate_(isolate), active_(isolate->bootstrapper()) {
7031 RCS_SCOPE(isolate, RuntimeCallCounterId::kGenesis);
7032 result_ = {};
7033 global_proxy_ = {};
7034
7035 // Before creating the roots we must save the context and restore it
7036 // on all function exits.
7037 SaveContext saved_context(isolate);
7038
7039 // The deserializer needs to hook up references to the global proxy.
7040 // Create an uninitialized global proxy now if we don't have one
7041 // and initialize it later in CreateNewGlobals.
7043 if (!maybe_global_proxy.ToHandle(&global_proxy)) {
7044 int instance_size = 0;
7045 if (context_snapshot_index > 0) {
7046 // The global proxy function to reinitialize this global proxy is in the
7047 // context that is yet to be deserialized. We need to prepare a global
7048 // proxy of the correct size.
7049 Tagged<Object> size =
7050 isolate->heap()->serialized_global_proxy_sizes()->get(
7051 static_cast<int>(context_snapshot_index) -
7053 instance_size = Smi::ToInt(size);
7054 } else {
7056 global_proxy_template.IsEmpty()
7057 ? 0
7058 : global_proxy_template->InternalFieldCount());
7059 }
7060 global_proxy =
7061 isolate->factory()->NewUninitializedJSGlobalProxy(instance_size);
7062 }
7063
7064 // We can only de-serialize a context if the isolate was initialized from
7065 // a snapshot. Otherwise we have to build the context from scratch.
7066 // Also create a context from scratch to expose natives, if required by flag.
7067 DCHECK(native_context_.is_null());
7068 if (isolate->initialized_from_snapshot()) {
7071 context_snapshot_index,
7072 embedder_fields_deserializer)
7073 .ToHandle(&context)) {
7075 }
7076 }
7077
7078 if (!native_context().is_null()) {
7080 isolate->set_context(*native_context());
7081
7082 // If no global proxy template was passed in, simply use the global in the
7083 // snapshot. If a global proxy template was passed in it's used to recreate
7084 // the global object and its prototype chain, and the data and the accessor
7085 // properties from the deserialized global are copied onto it.
7086 if (context_snapshot_index == 0 && !global_proxy_template.IsEmpty()) {
7087 DirectHandle<JSGlobalObject> global_object =
7088 CreateNewGlobals(global_proxy_template, global_proxy);
7089 HookUpGlobalObject(global_object);
7090 if (!ConfigureGlobalObject(global_proxy_template)) return;
7091 } else {
7092 // The global proxy needs to be integrated into the native context.
7094 }
7095 DCHECK_EQ(global_proxy->GetCreationContext(), *native_context());
7096 DCHECK(!global_proxy->IsDetachedFrom(native_context()->global_object()));
7097 } else {
7098 DCHECK(native_context().is_null());
7099
7100 Isolate::EnableRoAllocationForSnapshotScope enable_ro_allocation(isolate);
7101
7102 base::ElapsedTimer timer;
7103 if (v8_flags.profile_deserialization) timer.Start();
7104 DCHECK_EQ(0u, context_snapshot_index);
7105 // We get here if there was no context snapshot.
7106 CreateRoots();
7109 CreateSloppyModeFunctionMaps(empty_function);
7110 CreateStrictModeFunctionMaps(empty_function);
7111 CreateObjectFunction(empty_function);
7112 CreateIteratorMaps(empty_function);
7113 CreateAsyncIteratorMaps(empty_function);
7114 CreateAsyncFunctionMaps(empty_function);
7115 DirectHandle<JSGlobalObject> global_object =
7116 CreateNewGlobals(global_proxy_template, global_proxy);
7118 InitializeGlobal(global_object, empty_function);
7121
7122 if (!InstallABunchOfRandomThings()) return;
7123 if (!InstallExtrasBindings()) return;
7124 if (!ConfigureGlobalObject(global_proxy_template)) return;
7125
7126#ifdef V8_ENABLE_WEBASSEMBLY
7128#endif // V8_ENABLE_WEBASSEMBLY
7129
7130 if (v8_flags.profile_deserialization) {
7131 double ms = timer.Elapsed().InMillisecondsF();
7132 PrintF("[Initializing context from scratch took %0.3f ms]\n", ms);
7133 }
7134 }
7135
7136 native_context()->set_microtask_queue(
7137 isolate, microtask_queue ? static_cast<MicrotaskQueue*>(microtask_queue)
7138 : isolate->default_microtask_queue());
7139
7140 // Install experimental natives. Do not include them into the
7141 // snapshot as we should be able to turn them off at runtime. Re-installing
7142 // them after they have already been deserialized would also fail.
7143 if (!isolate->serializer_enabled()) {
7145
7146 // Store String.prototype's map again in case it has been changed by
7147 // experimental natives.
7148 DirectHandle<JSFunction> string_function(
7149 native_context()->string_function(), isolate);
7150 Tagged<JSObject> string_function_prototype =
7151 Cast<JSObject>(string_function->initial_map()->prototype());
7152 DCHECK(string_function_prototype->HasFastProperties());
7153 native_context()->set_string_function_prototype_map(
7154 string_function_prototype->map());
7155 }
7156
7157 if (v8_flags.disallow_code_generation_from_strings) {
7158 native_context()->set_allow_code_gen_from_strings(
7159 ReadOnlyRoots(isolate).false_value());
7160 }
7161
7162 // We created new functions, which may require debug instrumentation.
7163 if (isolate->debug()->is_active()) {
7164 isolate->debug()->InstallDebugBreakTrampoline();
7165 }
7166
7167 native_context()->ResetErrorsThrown();
7169}
7170
7172 MaybeDirectHandle<JSGlobalProxy> maybe_global_proxy,
7173 v8::Local<v8::ObjectTemplate> global_proxy_template)
7174 : isolate_(isolate), active_(isolate->bootstrapper()) {
7175 result_ = {};
7176 global_proxy_ = {};
7177
7178 // Before creating the roots we must save the context and restore it
7179 // on all function exits.
7180 SaveContext saved_context(isolate);
7181
7182 const int proxy_size = JSGlobalProxy::SizeWithEmbedderFields(
7183 global_proxy_template->InternalFieldCount());
7184
7186 if (maybe_global_proxy.ToHandle(&global_proxy)) {
7187 global_proxy->map()->set_map(isolate, ReadOnlyRoots(isolate).meta_map());
7188 } else {
7190 }
7191
7192 // Create a remote object as the global object.
7193 DirectHandle<ObjectTemplateInfo> global_proxy_data =
7194 Utils::OpenDirectHandle(*global_proxy_template);
7195 DirectHandle<FunctionTemplateInfo> global_constructor(
7196 Cast<FunctionTemplateInfo>(global_proxy_data->constructor()), isolate);
7197
7198 DirectHandle<ObjectTemplateInfo> global_object_template(
7199 Cast<ObjectTemplateInfo>(global_constructor->GetPrototypeTemplate()),
7200 isolate);
7201 DirectHandle<JSObject> global_object =
7202 ApiNatives::InstantiateRemoteObject(global_object_template)
7203 .ToHandleChecked();
7204
7205 // (Re)initialize the global proxy object.
7206 DCHECK_EQ(global_proxy_data->embedder_field_count(),
7207 global_proxy_template->InternalFieldCount());
7208 DirectHandle<Map> global_proxy_map = factory()->NewContextlessMap(
7209 JS_GLOBAL_PROXY_TYPE, proxy_size, TERMINAL_FAST_ELEMENTS_KIND);
7210 global_proxy_map->set_is_access_check_needed(true);
7211 global_proxy_map->set_may_have_interesting_properties(true);
7212
7213 // Configure the hidden prototype chain of the global proxy.
7214 JSObject::ForceSetPrototype(isolate, global_proxy, global_object);
7215 global_proxy->map()->SetConstructor(*global_constructor);
7216
7218}
7219
7220// Support for thread preemption.
7221
7222// Reserve space for statics needing saving and restoring.
7224
7225// Archive statics that are thread-local.
7227 *reinterpret_cast<NestingCounterType*>(to) = nesting_;
7228 nesting_ = 0;
7229 return to + sizeof(NestingCounterType);
7230}
7231
7232// Restore statics that are thread-local.
7234 nesting_ = *reinterpret_cast<NestingCounterType*>(from);
7235 return from + sizeof(NestingCounterType);
7236}
7237
7238// Called when the top-level V8 mutex is destroyed.
7240
7241} // namespace internal
7242} // namespace v8
Isolate * isolate_
#define PLAIN_DATE_TIME_FUNC_LIST(V)
#define INSTALL_TEMPORAL_FUNC(T, name, N, arg)
#define INSTALL_ITERATOR_HELPER(lowercase_name, Capitalized_name, ALL_CAPS_NAME, argc)
#define INSTALL_ZONED_DATE_TIME_FUNC(p, N, min)
#define INSTALL_TIME_ZONE_FUNC(p, N, min)
#define INSTALL_CAPTURE_GETTER(i)
#define PLAIN_TIME_GETTER_LIST(V)
#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id)
#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype)
#define PLAIN_YEAR_MONTH_GETTER_LIST(V)
#define INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE(N, U, NUM_ARGS)
#define INSTALL_DURATION_GETTER_FUNC(p, N)
#define FEATURE_INITIALIZE_GLOBAL(id, descr)
#define ITERATOR_HELPERS(V)
#define INSTALL_PLAIN_YEAR_MONTH_GETTER_FUNC(p, N)
ThreadLocalTop * top
#define INSTALL_ZONED_DATE_TIME_GETTER_FUNC(p, N)
#define PLAIN_DATE_FUNC_LIST(V)
#define ZONED_DATE_TIME_FUNC_LIST(V)
#define TIME_ZONE_FUNC_LIST(V)
#define INSTALL_INSTANT_GETTER_FUNC(p, N)
#define PLAIN_DATE_TIME_GETTER_LIST(V)
#define INSTALL_PLAIN_DATE_FUNC(p, N, min)
#define INSTALL_PLAIN_TIME_GETTER_FUNC(p, N)
#define PLAIN_TIME_FUNC_LIST(V)
#define INSTALL_PLAIN_DATE_TIME_GETTER_FUNC(p, N)
#define INSTALL_DURATION_FUNC(p, N, min)
#define INSTALL_PLAIN_DATE_TIME_FUNC(p, N, min)
#define INSTALL_NOW_FUNC(p, N, n)
#define INSTALL_INSTANT_FUNC(p, N, min)
#define INSTALL_PLAIN_TIME_FUNC(p, N, min)
#define INSTANT_GETTER_LIST(V)
#define INSTANT_FUNC_LIST(V)
#define ZONED_DATE_TIME_GETTER_LIST(V)
#define INSTALL_PLAIN_MONTH_DAY_FUNC(p, N, min)
#define INSTALL_CALENDAR_FUNC(p, N, min, adapt)
#define DURATION_FUNC_LIST(V)
#define DURATION_GETTER_LIST(V)
#define PLAIN_MONTH_DAY_FUNC_LIST(V)
#define PLAIN_DATE_GETTER_LIST(V)
#define DECLARE_FEATURE_INITIALIZATION(id, descr)
#define INSTALL_PLAIN_DATE_GETTER_FUNC(p, N)
Address previous_stack_height_
#define PLAIN_MONTH_DAY_GETTER_LIST(V)
#define INSTALL_PLAIN_YEAR_MONTH_FUNC(p, N, min)
#define NOW_LIST(V)
#define INSTALL_PLAIN_MONTH_DAY_GETTER_FUNC(p, N)
#define PLAIN_YEAR_MONTH_FUNC_LIST(V)
#define CALENDAR_FUNC_LIST(V)
const char * name
Definition builtins.cc:39
Builtins::Kind kind
Definition builtins.cc:40
PropertyT * getter
static RegisteredExtension * first_extension()
Definition api.h:84
RegisteredExtension * next() const
Definition api.h:83
static v8::internal::DirectHandle< To > OpenDirectHandle(v8::Local< From > handle)
Definition api.h:279
static V8_INLINE bool ApiCheck(bool condition, const char *location, const char *message)
Definition api.h:214
static V8_EXPORT_PRIVATE DirectHandle< AccessorInfo > MakeAccessor(Isolate *isolate, DirectHandle< Name > name, AccessorNameGetterCallback getter, AccessorNameBooleanSetterCallback setter)
Definition accessors.cc:29
static Handle< JSFunction > CreateApiFunction(Isolate *isolate, DirectHandle< NativeContext > native_context, DirectHandle< FunctionTemplateInfo > obj, DirectHandle< Object > prototype, InstanceType type, MaybeDirectHandle< Name > name={})
static V8_WARN_UNUSED_RESULT MaybeHandle< JSObject > InstantiateRemoteObject(DirectHandle< ObjectTemplateInfo > data)
static V8_WARN_UNUSED_RESULT MaybeHandle< JSObject > InstantiateObject(Isolate *isolate, DirectHandle< ObjectTemplateInfo > data, DirectHandle< JSReceiver > new_target={})
static const int kInitialFunctionCacheSize
Definition api-natives.h:24
char * RestoreState(char *from)
DirectHandle< NativeContext > CreateEnvironment(MaybeDirectHandle< JSGlobalProxy > maybe_global_proxy, v8::Local< v8::ObjectTemplate > global_object_template, v8::ExtensionConfiguration *extensions, size_t context_snapshot_index, DeserializeEmbedderFieldsCallback embedder_fields_deserializer, v8::MicrotaskQueue *microtask_queue)
void Iterate(RootVisitor *v)
void Initialize(bool create_heap_objects)
Bootstrapper(const Bootstrapper &)=delete
SourceCodeCache extensions_cache_
NestingCounterType nesting_
DirectHandle< JSGlobalProxy > NewRemoteContext(MaybeDirectHandle< JSGlobalProxy > maybe_global_proxy, v8::Local< v8::ObjectTemplate > global_object_template)
bool InstallExtensions(DirectHandle< NativeContext > native_context, v8::ExtensionConfiguration *extensions)
char * ArchiveState(char *to)
static void InitializeOncePerProcess()
static V8_EXPORT_PRIVATE bool HasJSLinkage(Builtin builtin)
Definition builtins.cc:220
static MaybeDirectHandle< SharedFunctionInfo > GetSharedFunctionInfoForScriptWithExtension(Isolate *isolate, Handle< String > source, const ScriptDetails &script_details, v8::Extension *extension, ScriptCompiler::CompileOptions compile_options, NativesFlag is_natives_code, ScriptCompiler::CompilationDetails *compilation_details)
Definition compiler.cc:4074
static int ArrayMapIndex(ElementsKind elements_kind)
Definition contexts.h:676
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 V8_EXPORT_PRIVATE MaybeHandle< String > ToString(Isolate *isolate, DirectHandle< Object > recv, ToStringMessageSource message_source=ToStringMessageSource::kCurrentMessageProperty)
Definition messages.cc:658
static V8_EXPORT_PRIVATE MaybeDirectHandle< Object > TryCallScript(Isolate *isolate, DirectHandle< JSFunction > script_function, DirectHandle< Object > receiver, DirectHandle< FixedArray > host_defined_options)
Definition execution.cc:573
MaybeHandle< String > NewStringFromOneByte(base::Vector< const uint8_t > string, AllocationType allocation=AllocationType::kYoung)
Handle< AccessorPair > NewAccessorPair()
Handle< WeakFixedArray > NewWeakFixedArray(int length, AllocationType allocation=AllocationType::kYoung)
Handle< FixedArray > NewFixedArrayWithHoles(int length, AllocationType allocation=AllocationType::kYoung)
Handle< Script > NewScript(DirectHandle< UnionOf< String, Undefined > > source, ScriptEventType event_type=ScriptEventType::kCreate)
Handle< Number > NewNumber(double value)
Handle< FixedArray > NewFixedArray(int length, AllocationType allocation=AllocationType::kYoung)
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
Handle< JSGlobalObject > NewJSGlobalObject(DirectHandle< JSFunction > constructor)
Definition factory.cc:3012
Handle< SharedFunctionInfo > NewSharedFunctionInfoForBuiltin(MaybeDirectHandle< String > name, Builtin builtin, int len, AdaptArguments adapt, FunctionKind kind=FunctionKind::kNormalFunction)
Definition factory.cc:3904
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< 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 > NewJSObjectWithNullProto()
Definition factory.cc:3004
DirectHandle< PropertyCell > NewProtector()
Definition factory.cc:2251
DirectHandle< JSObject > NewFunctionPrototype(DirectHandle< JSFunction > function)
Definition factory.cc:2867
Handle< JSObject > NewJSObject(DirectHandle< JSFunction > constructor, AllocationType allocation=AllocationType::kYoung, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
Definition factory.cc:2985
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
void ReinitializeJSGlobalProxy(DirectHandle< JSGlobalProxy > global, DirectHandle< JSFunction > constructor)
Definition factory.cc:3814
V8_WARN_UNUSED_RESULT MaybeHandle< String > NewStringFromUtf8(base::Vector< const char > str, AllocationType allocation=AllocationType::kYoung)
Definition factory.cc:753
Handle< NativeContext > NewNativeContext()
Definition factory.cc:1295
DirectHandle< Map > CreateClassFunctionMap(DirectHandle< JSFunction > empty_function)
Definition factory.cc:4470
Handle< ScriptContextTable > NewScriptContextTable()
Definition factory.cc:1359
DirectHandle< Map > CreateSloppyFunctionMap(FunctionMode function_mode, MaybeDirectHandle< JSFunction > maybe_empty_function)
Definition factory.cc:4296
DirectHandle< EmbedderDataArray > NewEmbedderDataArray(int length)
Definition factory.cc:483
Handle< String > InternalizeString(base::Vector< const char > str, bool convert_encoding=false)
Definition factory.h:216
Handle< String > InternalizeUtf8String(base::Vector< const char > str)
Definition factory.cc:608
static FieldIndex ForDetails(Tagged< Map > map, PropertyDetails details)
static FieldIndex ForDescriptor(Tagged< Map > map, InternalIndex descriptor_index)
static V8_EXPORT_PRIVATE Tagged< FieldType > Any()
Definition field-type.cc:22
void CopyElements(Isolate *isolate, int dst_index, Tagged< FixedArray > src, int src_index, int len, WriteBarrierMode mode)
void set_state(RegisteredExtension *extension, ExtensionTraversalState state)
ExtensionStates & operator=(const ExtensionStates &)=delete
ExtensionTraversalState get_state(RegisteredExtension *extension)
ExtensionStates(const ExtensionStates &)=delete
Builtins * builtins() const
BootstrapperActive active_
void CreateStrictModeFunctionMaps(DirectHandle< JSFunction > empty)
DirectHandle< JSFunction > CreateArrayBuffer(DirectHandle< String > name, ArrayBufferKind array_buffer_kind)
bool ConfigureGlobalObject(v8::Local< v8::ObjectTemplate > global_proxy_template)
void InitializeGlobal_sharedarraybuffer()
DirectHandle< NativeContext > native_context()
Factory * factory() const
void TransferObject(DirectHandle< JSObject > from, DirectHandle< JSObject > to)
DirectHandle< JSFunction > CreateEmptyFunction()
static bool InstallRequestedExtensions(Isolate *isolate, v8::ExtensionConfiguration *extensions, ExtensionStates *extension_states)
DirectHandle< NativeContext > result_
Isolate * isolate() const
DirectHandle< JSGlobalProxy > global_proxy_
DirectHandle< NativeContext > native_context_
bool ConfigureApiObject(DirectHandle< JSObject > object, DirectHandle< ObjectTemplateInfo > object_template)
void CreateIteratorMaps(DirectHandle< JSFunction > empty)
DirectHandle< JSFunction > InstallTypedArray(const char *name, ElementsKind elements_kind, InstanceType constructor_type, int rab_gsab_initial_map_index)
void CreateObjectFunction(DirectHandle< JSFunction > empty)
void CreateAsyncFunctionMaps(DirectHandle< JSFunction > empty)
static bool InstallExtension(Isolate *isolate, const char *name, ExtensionStates *extension_states)
void InitializeConsole(DirectHandle< JSObject > extras_binding)
DirectHandle< JSFunction > restricted_properties_thrower_
void TransferNamedProperties(DirectHandle< JSObject > from, DirectHandle< JSObject > to)
DirectHandle< JSFunction > GetThrowTypeErrorIntrinsic()
void InitializeGlobal_regexp_linear_flag()
void HookUpGlobalObject(DirectHandle< JSGlobalObject > global_object)
DirectHandle< JSGlobalProxy > global_proxy()
static bool InstallSpecialObjects(Isolate *isolate, DirectHandle< NativeContext > native_context)
DirectHandle< Map > CreateInitialMapForArraySubclass(int size, int inobject_properties)
void HookUpGlobalProxy(DirectHandle< JSGlobalProxy > global_proxy)
DirectHandle< NativeContext > result()
void InitializeGlobal(DirectHandle< JSGlobalObject > global_object, DirectHandle< JSFunction > empty_function)
void AddRestrictedFunctionProperties(DirectHandle< JSFunction > empty)
void TransferIndexedProperties(DirectHandle< JSObject > from, DirectHandle< JSObject > to)
Genesis(Isolate *isolate, MaybeDirectHandle< JSGlobalProxy > maybe_global_proxy, v8::Local< v8::ObjectTemplate > global_proxy_template, size_t context_snapshot_index, DeserializeEmbedderFieldsCallback embedder_fields_deserializer, v8::MicrotaskQueue *microtask_queue)
void CreateSloppyModeFunctionMaps(DirectHandle< JSFunction > empty)
static bool InstallAutoExtensions(Isolate *isolate, ExtensionStates *extension_states)
void CreateAsyncIteratorMaps(DirectHandle< JSFunction > empty)
DirectHandle< JSGlobalObject > CreateNewGlobals(v8::Local< v8::ObjectTemplate > global_proxy_template, DirectHandle< JSGlobalProxy > global_proxy)
static bool InstallExtensions(Isolate *isolate, DirectHandle< Context > native_context, v8::ExtensionConfiguration *extensions)
static bool CompileExtension(Isolate *isolate, v8::Extension *extension)
HandleType< T > CloseAndEscape(HandleType< T > handle_value)
void NotifyBootstrapComplete()
Definition heap.cc:5993
bool serializer_enabled() const
Definition isolate.h:1549
void set_context(Tagged< Context > context)
Definition isolate-inl.h:43
bool initialized_from_snapshot()
Definition isolate.h:1562
Tagged< Object > exception()
Handle< NativeContext > native_context()
Definition isolate-inl.h:48
Builtins * builtins()
Definition isolate.h:1443
v8::internal::Factory * factory()
Definition isolate.h:1527
static constexpr int kSizeWithEmbedderFields
static const int kLengthDescriptorIndex
Definition js-array.h:124
static V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty(Isolate *isolate, DirectHandle< JSArray > o, DirectHandle< Object > name, PropertyDescriptor *desc, Maybe< ShouldThrow > should_throw)
Definition objects.cc:3120
static const int kAddFunctionDescriptorIndex
static void SetPrototype(DirectHandle< JSFunction > function, DirectHandle< Object > value)
static constexpr int kSizeWithPrototype
static void SetInitialMap(Isolate *isolate, DirectHandle< JSFunction > function, DirectHandle< Map > map, DirectHandle< JSPrototype > prototype)
static int SizeWithEmbedderFields(int embedder_field_count)
static constexpr int kSize
Definition module.h:159
static V8_EXPORT_PRIVATE DirectHandle< NumberDictionary > NormalizeElements(DirectHandle< JSObject > object)
static V8_EXPORT_PRIVATE void AddProperty(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static V8_EXPORT_PRIVATE void MigrateSlowToFast(DirectHandle< JSObject > object, int unused_property_fields, const char *reason)
static Handle< JSAny > FastPropertyAt(Isolate *isolate, DirectHandle< JSObject > object, Representation representation, FieldIndex index)
static void ForceSetPrototype(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< JSPrototype > proto)
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 V8_WARN_UNUSED_RESULT Maybe< bool > SetPrototype(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Object > value, bool from_javascript, ShouldThrow should_throw)
static const int kInitialGlobalObjectUnusedPropertiesCount
Definition js-objects.h:943
static void SetNormalizedProperty(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyDetails details)
static void MakePrototypesFast(DirectHandle< Object > receiver, WhereToStart where_to_start, Isolate *isolate)
static V8_EXPORT_PRIVATE MaybeDirectHandle< Object > DefineOwnAccessorIgnoreAttributes(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > getter, DirectHandle< Object > setter, PropertyAttributes attributes)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > SetAccessor(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< AccessorInfo > info, PropertyAttributes attributes)
static V8_WARN_UNUSED_RESULT Maybe< bool > PreventExtensions(Isolate *isolate, DirectHandle< JSObject > object, ShouldThrow should_throw)
static const int kSizeWithEmbedderFields
Definition js-promise.h:75
static const int kRawJsonInitialIndex
Definition js-raw-json.h:29
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > SetPrototype(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Object > value, bool from_javascript, ShouldThrow should_throw)
static V8_WARN_UNUSED_RESULT MaybeHandle< Object > GetProperty(Isolate *isolate, DirectHandle< JSReceiver > receiver, const char *key)
static constexpr int kGroupsDescriptorIndex
Definition js-regexp.h:365
static constexpr int kInObjectPropertyCount
Definition js-regexp.h:362
static constexpr int kGroupsIndex
Definition js-regexp.h:361
static constexpr int kInObjectPropertyCount
Definition js-regexp.h:341
static constexpr int kInputIndex
Definition js-regexp.h:319
static constexpr int kNamesIndex
Definition js-regexp.h:323
static constexpr int kGroupsIndex
Definition js-regexp.h:320
static constexpr int kInObjectPropertyCount
Definition js-regexp.h:326
static constexpr int kRegExpInputIndex
Definition js-regexp.h:324
static constexpr int kRegExpLastIndex
Definition js-regexp.h:325
static constexpr int kIndexIndex
Definition js-regexp.h:318
static constexpr int kLastIndexFieldIndex
Definition js-regexp.h:114
static constexpr int kSymbolMatchAllFunctionDescriptorIndex
Definition js-regexp.h:124
static constexpr int kSymbolReplaceFunctionDescriptorIndex
Definition js-regexp.h:125
static constexpr int kExecFunctionDescriptorIndex
Definition js-regexp.h:122
static constexpr int kSymbolSearchFunctionDescriptorIndex
Definition js-regexp.h:126
static constexpr int kInObjectFieldCount
Definition js-regexp.h:115
static constexpr int kSymbolSplitFunctionDescriptorIndex
Definition js-regexp.h:127
static constexpr int kSymbolMatchFunctionDescriptorIndex
Definition js-regexp.h:123
static constexpr int kSizeWithEmbedderFields
static const int kAddFunctionDescriptorIndex
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 void SetShouldBeFastPrototypeMap(DirectHandle< Map > map, bool value, Isolate *isolate)
Definition map.cc:2408
static Handle< Map > Copy(Isolate *isolate, DirectHandle< Map > map, const char *reason, TransitionKindFlag kind=SPECIAL_TRANSITION)
Definition map.cc:1811
static Handle< Map > CopyAsElementsKind(Isolate *isolate, DirectHandle< Map > map, ElementsKind kind, TransitionFlag flag)
Definition map.cc:1688
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 DirectHandle< Map > CopyInitialMapNormalized(Isolate *isolate, DirectHandle< Map > map, PropertyNormalizationMode mode=CLEAR_INOBJECT_PROPERTIES)
Definition map.cc:1448
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Map > CopyWithField(Isolate *isolate, DirectHandle< Map > map, DirectHandle< Name > name, DirectHandle< FieldType > type, PropertyAttributes attributes, PropertyConstness constness, Representation representation, TransitionFlag flag)
Definition map.cc:504
static void InitializeContext(Isolate *isolate, DirectHandle< Context > native_context)
V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(DirectHandle< S > *out) const
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > ToFunctionName(Isolate *isolate, DirectHandle< Name > name)
Definition objects.cc:4049
static NEVER_READ_ONLY_SPACE DirectHandle< NormalizedMapCache > New(Isolate *isolate)
Definition map.cc:2529
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it, bool is_global_reference=false)
Definition objects.cc:1248
static MaybeHandle< OrderedHashSet > Allocate(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
void set_value(DirectHandle< JSAny > value)
void set_configurable(bool configurable)
PropertyAttributes attributes() const
PropertyLocation location() const
Representation representation() const
Tagged< T > GetCurrent() const
Definition prototype.h:52
static constexpr int kMinCapacity
static V8_EXPORT_PRIVATE DirectHandle< RegExpMatchInfo > New(Isolate *isolate, int capture_count, AllocationType allocation=AllocationType::kYoung)
static constexpr Representation Tagged()
virtual void Synchronize(VisitorSynchronization::SyncTag tag)
Definition visitors.h:112
virtual void VisitRootPointer(Root root, const char *description, FullObjectSlot p)
Definition visitors.h:75
V8_WARN_UNUSED_RESULT static V8_EXPORT_PRIVATE Handle< ScriptContextTable > Add(Isolate *isolate, Handle< ScriptContextTable > table, DirectHandle< Context > script_context, bool ignore_duplicates)
Definition contexts.cc:76
static constexpr int ToInt(const Tagged< Object > object)
Definition smi.h:33
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
static constexpr Tagged< Smi > zero()
Definition smi.h:99
static constexpr size_t kFirstAddtlContextIndex
Definition snapshot.h:188
static MaybeDirectHandle< Context > NewContextFromSnapshot(Isolate *isolate, DirectHandle< JSGlobalProxy > global_proxy, size_t context_index, DeserializeEmbedderFieldsCallback embedder_fields_deserializer)
Definition snapshot.cc:203
Tagged< FixedArray > cache_
void Initialize(Isolate *isolate, bool create_heap_objects)
void Iterate(RootVisitor *v)
bool Lookup(Isolate *isolate, base::Vector< const char > name, DirectHandle< SharedFunctionInfo > *handle)
void Add(Isolate *isolate, base::Vector< const char > name, DirectHandle< SharedFunctionInfo > shared)
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
static const int kFastTemplateInstantiationsCacheSize
Definition templates.h:33
static V8_EXPORT_PRIVATE void Install(Isolate *isolate)
Definition wasm-js.cc:3601
static V8_EXPORT_PRIVATE void PrepareForSnapshot(Isolate *isolate)
Definition wasm-js.cc:3378
#define V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL
Definition globals.h:242
#define V8_INFINITY
Definition globals.h:23
const MapRef map_
bool active_
Definition cpp-heap.cc:596
Handle< SharedFunctionInfo > info
#define TYPED_ARRAYS_BASE(V)
MicrotaskQueue * microtask_queue
Definition execution.cc:77
#define JAVASCRIPT_INPROGRESS_FEATURES(V)
#define HARMONY_SHIPPING(V)
#define JAVASCRIPT_STAGED_FEATURES(V)
#define HARMONY_INPROGRESS(V)
#define JAVASCRIPT_SHIPPING_FEATURES(V)
#define HARMONY_STAGED(V)
Isolate * isolate
std::string extension
TNode< Context > context
TNode< Object > receiver
std::map< const std::string, const std::string > map
ZoneVector< RpoNumber > & result
LiftoffAssembler::CacheState state
ZoneVector< Entry > entries
Point from
Point to
#define LOG(isolate, Call)
Definition log.h:78
double log(double x)
Definition ieee754.cc:1638
double log2(double x)
Definition ieee754.cc:1973
double exp(double x)
Definition ieee754.cc:1447
double log10(double x)
Definition ieee754.cc:2079
Vector< const char > CStrVector(const char *data)
Definition vector.h:331
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
constexpr int kFastElementsKindCount
Handle< JSFunction > SimpleInstallFunction(Isolate *isolate, DirectHandle< JSObject > base, const char *name, Builtin call, int len, AdaptArguments adapt, PropertyAttributes attrs)
constexpr int kTaggedSize
Definition globals.h:542
constexpr double kMaxSafeInteger
Definition globals.h:1985
ElementsKind GetFastElementsKindFromSequenceIndex(int sequence_number)
static bool PropertyAlreadyExists(Isolate *isolate, DirectHandle< JSObject > to, DirectHandle< Name > key)
@ UPDATE_WRITE_BARRIER
Definition objects.h:55
void PrintF(const char *format,...)
Definition utils.cc:39
@ INSERT_TRANSITION
Definition objects.h:66
@ OMIT_TRANSITION
Definition objects.h:66
Tagged(T object) -> Tagged< T >
ElementsKind GetCorrespondingRabGsabElementsKind(ElementsKind typed_array_kind)
bool IsResumableFunction(FunctionKind kind)
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:665
constexpr uint16_t kDontAdaptArgumentsSentinel
Definition globals.h:2779
constexpr int N
constexpr bool IsObjectElementsKind(ElementsKind kind)
kStaticElementsTemplateOffset kInstancePropertiesTemplateOffset Tagged< FixedArray >
@ TERMINAL_FAST_ELEMENTS_KIND
@ SLOW_SLOPPY_ARGUMENTS_ELEMENTS
@ FAST_SLOPPY_ARGUMENTS_ELEMENTS
@ FAST_STRING_WRAPPER_ELEMENTS
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
const int kVariableSizeSentinel
Definition objects.h:84
static void AddToWeakNativeContextList(Isolate *isolate, Tagged< Context > context)
uint32_t ComputePointerHash(void *ptr)
Definition utils.h:301
int GetSequenceIndexFromFastElementsKind(ElementsKind elements_kind)
constexpr int ElementsKindToShiftSize(ElementsKind elements_kind)
DONT_OVERRIDE DISABLE_ALLOCATION_SITES HOLEY_ELEMENTS
static const char * GCFunctionName()
constexpr AdaptArguments kDontAdapt
Definition globals.h:2776
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
static uint32_t Hash(RegisteredExtension *extension)
Tagged< MaybeWeak< T > > MakeWeak(Tagged< T > value)
Definition tagged.h:893
static bool isValidCpuTraceMarkFunctionName()
static void InstallWithIntrinsicDefaultProto(Isolate *isolate, DirectHandle< JSFunction > function, int context_index)
Tagged< ClearedWeakValue > ClearedValue(PtrComprCageBase cage_base)
constexpr AdaptArguments kAdapt
Definition globals.h:2775
V8_EXPORT_PRIVATE FlagValues v8_flags
return value
Definition map-inl.h:893
constexpr double kMinSafeInteger
Definition globals.h:1987
void InstallError(Isolate *isolate, DirectHandle< JSObject > global, DirectHandle< String > name, int context_index, Builtin error_constructor, int error_function_length)
ElementsKind GetInitialFastElementsKind()
@ FUNCTION_WITH_READONLY_PROTOTYPE
Definition factory.h:129
@ FUNCTION_WITH_NAME_AND_WRITEABLE_PROTOTYPE
Definition factory.h:125
@ METHOD_WITH_NAME
Definition factory.h:121
@ FUNCTION_WITHOUT_PROTOTYPE
Definition factory.h:120
@ FUNCTION_WITH_WRITEABLE_PROTOTYPE
Definition factory.h:124
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset prototype
Definition map-inl.h:69
!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
static constexpr ReleaseStoreTag kReleaseStore
Definition globals.h:2910
Local< T > Handle
void RegisterExtension(std::unique_ptr< Extension > extension)
Definition api.cc:486
static constexpr AcquireLoadTag kAcquireLoad
Definition globals.h:2908
Maybe< T > Just(const T &t)
Definition v8-maybe.h:117
uint32_t compare
#define RCS_SCOPE(...)
int Compare(const T &a, const T &b)
#define CHECK(condition)
Definition logging.h:124
#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_EQ(v1, v2)
Definition logging.h:485
static bool is_gc_stats_enabled()
#define V8_NOINLINE
Definition v8config.h:586