5 #include "src/arguments-inl.h" 6 #include "src/bootstrapper.h" 7 #include "src/counters.h" 8 #include "src/debug/debug.h" 9 #include "src/isolate-inl.h" 10 #include "src/message-template.h" 11 #include "src/objects/hash-table-inl.h" 12 #include "src/objects/js-array-inl.h" 13 #include "src/objects/property-descriptor-object.h" 14 #include "src/property-descriptor.h" 15 #include "src/runtime/runtime-utils.h" 16 #include "src/runtime/runtime.h" 21 MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
22 Handle<Object>
object,
25 if (object->IsNullOrUndefined(isolate)) {
26 if (*key == ReadOnlyRoots(isolate).iterator_symbol()) {
27 return Runtime::ThrowIteratorError(isolate,
object);
31 NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key,
object),
37 LookupIterator::PropertyOrElement(isolate,
object, key, &success);
38 if (!success)
return MaybeHandle<Object>();
40 MaybeHandle<Object> result = Object::GetProperty(&it);
41 if (is_found_out) *is_found_out = it.IsFound();
43 if (!it.IsFound() && key->IsSymbol() &&
44 Symbol::cast(*key)->is_private_name()) {
47 NewTypeError(MessageTemplate::kInvalidPrivateFieldAccess, key,
object),
55 bool DeleteObjectPropertyFast(Isolate* isolate, Handle<JSReceiver> receiver,
56 Handle<Object> raw_key) {
57 DisallowHeapAllocation no_allocation;
63 Map map = receiver->map();
64 if (map->IsSpecialReceiverMap())
return false;
65 if (!raw_key->IsUniqueName())
return false;
66 Handle<Name> key = Handle<Name>::cast(raw_key);
68 int nof = map->NumberOfOwnDescriptors();
69 if (nof == 0)
return false;
70 int descriptor = nof - 1;
71 DescriptorArray* descriptors = map->instance_descriptors();
72 if (descriptors->GetKey(descriptor) != *key)
return false;
74 PropertyDetails details = descriptors->GetDetails(descriptor);
75 if (!details.IsConfigurable())
return false;
77 Object* backpointer = map->GetBackPointer();
78 if (!backpointer->IsMap())
return false;
81 if (Map::cast(backpointer)->NumberOfOwnDescriptors() != nof - 1)
return false;
87 if (details.location() == kField) {
88 isolate->heap()->NotifyObjectLayoutChange(*receiver, map->instance_size(),
90 FieldIndex index = FieldIndex::ForPropertyIndex(map, details.field_index());
92 if (!index.is_inobject() && index.outobject_array_index() == 0) {
93 DCHECK(!Map::cast(backpointer)->HasOutOfObjectProperties());
95 receiver->SetProperties(ReadOnlyRoots(isolate).empty_fixed_array());
97 Object* filler = ReadOnlyRoots(isolate).one_pointer_filler_map();
98 JSObject::cast(*receiver)->RawFastPropertyAtPut(index, filler);
103 if (index.is_inobject() && !map->IsUnboxedDoubleField(index)) {
104 isolate->heap()->ClearRecordedSlot(
105 *receiver, HeapObject::RawField(*receiver, index.offset()));
113 map->NotifyLeafMapLayoutChange(isolate);
115 receiver->synchronized_set_map(Map::cast(backpointer));
117 receiver->HeapObjectVerify(isolate);
118 receiver->property_array()->PropertyArrayVerify(isolate);
125 Maybe<bool> Runtime::DeleteObjectProperty(Isolate* isolate,
126 Handle<JSReceiver> receiver,
128 LanguageMode language_mode) {
129 if (DeleteObjectPropertyFast(isolate, receiver, key))
return Just(
true);
131 bool success =
false;
132 LookupIterator it = LookupIterator::PropertyOrElement(
133 isolate, receiver, key, &success, LookupIterator::OWN);
134 if (!success)
return Nothing<bool>();
136 return JSReceiver::DeleteProperty(&it, language_mode);
140 RUNTIME_FUNCTION(Runtime_ObjectKeys) {
141 HandleScope scope(isolate);
142 Handle<Object>
object = args.at(0);
145 Handle<JSReceiver> receiver;
146 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
147 Object::ToObject(isolate,
object));
150 Handle<FixedArray> keys;
151 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
153 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly,
155 GetKeysConversion::kConvertToString));
160 RUNTIME_FUNCTION(Runtime_ObjectGetOwnPropertyNames) {
161 HandleScope scope(isolate);
162 Handle<Object>
object = args.at(0);
165 Handle<JSReceiver> receiver;
166 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
167 Object::ToObject(isolate,
object));
170 Handle<FixedArray> keys;
171 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
173 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly,
175 GetKeysConversion::kConvertToString));
179 RUNTIME_FUNCTION(Runtime_ObjectGetOwnPropertyNamesTryFast) {
180 HandleScope scope(isolate);
181 Handle<Object>
object = args.at(0);
184 Handle<JSReceiver> receiver;
185 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
186 Object::ToObject(isolate,
object));
188 Handle<Map> map(receiver->map(), isolate);
190 int nod = map->NumberOfOwnDescriptors();
191 Handle<FixedArray> keys;
192 if (nod != 0 && map->NumberOfEnumerableProperties() == nod) {
193 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
195 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly,
197 GetKeysConversion::kConvertToString));
199 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
201 KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly,
203 GetKeysConversion::kConvertToString));
210 RUNTIME_FUNCTION(Runtime_ObjectHasOwnProperty) {
211 HandleScope scope(isolate);
212 Handle<Object>
property = args.at(1);
216 bool key_is_array_index =
property->ToArrayIndex(&index);
218 if (!key_is_array_index) {
219 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
220 Object::ToName(isolate, property));
221 key_is_array_index = key->AsArrayIndex(&index);
224 Handle<Object>
object = args.at(0);
226 if (object->IsJSModuleNamespace()) {
228 DCHECK(key_is_array_index);
230 return ReadOnlyRoots(isolate).false_value();
234 JSReceiver::HasOwnProperty(Handle<JSReceiver>::cast(
object), key);
235 if (!result.IsJust())
return ReadOnlyRoots(isolate).exception();
236 return isolate->heap()->ToBoolean(result.FromJust());
238 }
else if (object->IsJSObject()) {
239 Handle<JSObject> js_obj = Handle<JSObject>::cast(
object);
246 LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR;
248 key_is_array_index ? LookupIterator(isolate, js_obj, index, js_obj, c)
249 : LookupIterator(js_obj, key, js_obj, c);
250 Maybe<bool> maybe = JSReceiver::HasProperty(&it);
251 if (maybe.IsNothing())
return ReadOnlyRoots(isolate).exception();
252 DCHECK(!isolate->has_pending_exception());
253 if (maybe.FromJust())
return ReadOnlyRoots(isolate).true_value();
256 Map map = js_obj->map();
257 if (!map->has_hidden_prototype() &&
258 (key_is_array_index ? !map->has_indexed_interceptor()
259 : !map->has_named_interceptor())) {
260 return ReadOnlyRoots(isolate).false_value();
264 LookupIterator::Configuration c = LookupIterator::OWN;
265 LookupIterator it = key_is_array_index
266 ? LookupIterator(isolate, js_obj, index, js_obj, c)
267 : LookupIterator(js_obj, key, js_obj, c);
269 Maybe<bool> maybe = JSReceiver::HasProperty(&it);
270 if (maybe.IsNothing())
return ReadOnlyRoots(isolate).exception();
271 DCHECK(!isolate->has_pending_exception());
272 return isolate->heap()->ToBoolean(maybe.FromJust());
274 }
else if (object->IsJSProxy()) {
276 DCHECK(key_is_array_index);
277 key = isolate->factory()->Uint32ToString(index);
281 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(
object), key);
282 if (result.IsNothing())
return ReadOnlyRoots(isolate).exception();
283 return isolate->heap()->ToBoolean(result.FromJust());
285 }
else if (object->IsString()) {
286 return isolate->heap()->ToBoolean(
288 ? index < static_cast<uint32_t>(String::cast(*object)->length())
289 : key->Equals(ReadOnlyRoots(isolate).length_string()));
290 }
else if (object->IsNullOrUndefined(isolate)) {
291 THROW_NEW_ERROR_RETURN_FAILURE(
292 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject));
295 return ReadOnlyRoots(isolate).false_value();
298 RUNTIME_FUNCTION(Runtime_AddDictionaryProperty) {
299 HandleScope scope(isolate);
300 Handle<JSObject> receiver = args.at<JSObject>(0);
301 Handle<Name> name = args.at<Name>(1);
302 Handle<Object> value = args.at(2);
304 DCHECK(name->IsUniqueName());
306 Handle<NameDictionary> dictionary(receiver->property_dictionary(), isolate);
307 PropertyDetails property_details(kData, NONE, PropertyCellType::kNoCell);
309 NameDictionary::Add(isolate, dictionary, name, value, property_details);
310 receiver->SetProperties(*dictionary);
317 RUNTIME_FUNCTION(Runtime_ObjectCreate) {
318 HandleScope scope(isolate);
319 Handle<Object> prototype = args.at(0);
320 Handle<Object> properties = args.at(1);
321 Handle<JSObject> obj;
323 if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) {
324 THROW_NEW_ERROR_RETURN_FAILURE(
325 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype));
328 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
329 isolate, obj, JSObject::ObjectCreate(isolate, prototype));
332 if (!properties->IsUndefined(isolate)) {
335 RETURN_RESULT_OR_FAILURE(
336 isolate, JSReceiver::DefineProperties(isolate, obj, properties));
342 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
343 Handle<Object>
object,
345 Handle<Object> value,
346 LanguageMode language_mode,
347 StoreOrigin store_origin) {
348 if (object->IsNullOrUndefined(isolate)) {
351 NewTypeError(MessageTemplate::kNonObjectPropertyStore, key,
object),
356 bool success =
false;
358 LookupIterator::PropertyOrElement(isolate,
object, key, &success);
359 if (!success)
return MaybeHandle<Object>();
361 if (!it.IsFound() && key->IsSymbol() &&
362 Symbol::cast(*key)->is_private_name()) {
365 NewTypeError(MessageTemplate::kInvalidPrivateFieldAccess, key,
object),
370 Object::SetProperty(&it, value, language_mode, store_origin));
376 RUNTIME_FUNCTION(Runtime_InternalSetPrototype) {
377 HandleScope scope(isolate);
378 DCHECK_EQ(2, args.length());
379 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0);
380 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
381 if (prototype->IsJSFunction()) {
382 Handle<JSFunction>
function = Handle<JSFunction>::cast(prototype);
383 if (!function->shared()->HasSharedName()) {
384 Handle<Map> function_map(function->map(), isolate);
385 if (!JSFunction::SetName(
function, isolate->factory()->proto_string(),
386 isolate->factory()->empty_string())) {
387 return ReadOnlyRoots(isolate).exception();
389 CHECK_EQ(*function_map, function->map());
392 MAYBE_RETURN(JSReceiver::SetPrototype(obj, prototype,
false, kThrowOnError),
393 ReadOnlyRoots(isolate).exception());
397 RUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) {
398 HandleScope scope(isolate);
399 DCHECK_EQ(2, args.length());
400 CONVERT_ARG_HANDLE_CHECKED(JSObject,
object, 0);
401 CONVERT_SMI_ARG_CHECKED(properties, 1);
403 if (properties > 100000)
return isolate->ThrowIllegalOperation();
404 if (object->HasFastProperties() && !
object->IsJSGlobalProxy()) {
405 JSObject::NormalizeProperties(
object, KEEP_INOBJECT_PROPERTIES, properties,
406 "OptimizeForAdding");
411 RUNTIME_FUNCTION(Runtime_ObjectValues) {
412 HandleScope scope(isolate);
413 DCHECK_EQ(1, args.length());
415 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
417 Handle<FixedArray> values;
418 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
420 JSReceiver::GetOwnValues(receiver, PropertyFilter::ENUMERABLE_STRINGS,
422 return *isolate->factory()->NewJSArrayWithElements(values);
425 RUNTIME_FUNCTION(Runtime_ObjectValuesSkipFastPath) {
426 HandleScope scope(isolate);
427 DCHECK_EQ(1, args.length());
429 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
431 Handle<FixedArray> value;
432 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
434 JSReceiver::GetOwnValues(receiver, PropertyFilter::ENUMERABLE_STRINGS,
436 return *isolate->factory()->NewJSArrayWithElements(value);
439 RUNTIME_FUNCTION(Runtime_ObjectEntries) {
440 HandleScope scope(isolate);
441 DCHECK_EQ(1, args.length());
443 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
445 Handle<FixedArray> entries;
446 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
448 JSReceiver::GetOwnEntries(receiver, PropertyFilter::ENUMERABLE_STRINGS,
450 return *isolate->factory()->NewJSArrayWithElements(entries);
453 RUNTIME_FUNCTION(Runtime_ObjectEntriesSkipFastPath) {
454 HandleScope scope(isolate);
455 DCHECK_EQ(1, args.length());
457 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
459 Handle<FixedArray> entries;
460 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
462 JSReceiver::GetOwnEntries(receiver, PropertyFilter::ENUMERABLE_STRINGS,
464 return *isolate->factory()->NewJSArrayWithElements(entries);
467 RUNTIME_FUNCTION(Runtime_GetProperty) {
468 HandleScope scope(isolate);
469 DCHECK_EQ(2, args.length());
470 CONVERT_ARG_HANDLE_CHECKED(Object, receiver_obj, 0);
471 CONVERT_ARG_HANDLE_CHECKED(Object, key_obj, 1);
488 if (key_obj->IsString() && String::cast(*key_obj)->AsArrayIndex(&index)) {
489 key_obj = isolate->factory()->NewNumberFromUint(index);
491 if (receiver_obj->IsJSObject()) {
492 if (!receiver_obj->IsJSGlobalProxy() &&
493 !receiver_obj->IsAccessCheckNeeded() && key_obj->IsName()) {
494 Handle<JSObject> receiver = Handle<JSObject>::cast(receiver_obj);
495 Handle<Name> key = Handle<Name>::cast(key_obj);
496 key_obj = key = isolate->factory()->InternalizeName(key);
498 DisallowHeapAllocation no_allocation;
499 if (receiver->IsJSGlobalObject()) {
501 GlobalDictionary dictionary =
502 JSGlobalObject::cast(*receiver)->global_dictionary();
503 int entry = dictionary->FindEntry(isolate, key);
504 if (entry != GlobalDictionary::kNotFound) {
505 PropertyCell* cell = dictionary->CellAt(entry);
506 if (cell->property_details().kind() == kData) {
507 Object* value = cell->value();
508 if (!value->IsTheHole(isolate))
return value;
512 }
else if (!receiver->HasFastProperties()) {
514 NameDictionary dictionary = receiver->property_dictionary();
515 int entry = dictionary->FindEntry(isolate, key);
516 if ((entry != NameDictionary::kNotFound) &&
517 (dictionary->DetailsAt(entry).kind() == kData)) {
518 return dictionary->ValueAt(entry);
521 }
else if (key_obj->IsSmi()) {
528 Handle<JSObject> js_object = Handle<JSObject>::cast(receiver_obj);
529 ElementsKind elements_kind = js_object->GetElementsKind();
530 if (IsDoubleElementsKind(elements_kind)) {
531 if (Smi::ToInt(*key_obj) >= js_object->elements()->length()) {
532 elements_kind = IsHoleyElementsKind(elements_kind) ? HOLEY_ELEMENTS
534 JSObject::TransitionElementsKind(js_object, elements_kind);
537 DCHECK(IsSmiOrObjectElementsKind(elements_kind) ||
538 !IsFastElementsKind(elements_kind));
541 }
else if (receiver_obj->IsString() && key_obj->IsSmi()) {
543 Handle<String> str = Handle<String>::cast(receiver_obj);
544 int index = Handle<Smi>::cast(key_obj)->value();
545 if (index >= 0 && index < str->length()) {
546 Factory* factory = isolate->factory();
547 return *factory->LookupSingleCharacterStringFromCode(
548 String::Flatten(isolate, str)->Get(index));
553 RETURN_RESULT_OR_FAILURE(
554 isolate, Runtime::GetObjectProperty(isolate, receiver_obj, key_obj));
557 RUNTIME_FUNCTION(Runtime_AddNamedProperty) {
558 HandleScope scope(isolate);
559 DCHECK_EQ(4, args.length());
561 CONVERT_ARG_HANDLE_CHECKED(JSObject,
object, 0);
562 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
563 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
564 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
568 DCHECK(!name->ToArrayIndex(&index));
569 LookupIterator it(
object, name,
object, LookupIterator::OWN_SKIP_INTERCEPTOR);
570 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
571 if (maybe.IsNothing())
return ReadOnlyRoots(isolate).exception();
572 DCHECK(!it.IsFound());
575 RETURN_RESULT_OR_FAILURE(isolate, JSObject::SetOwnPropertyIgnoreAttributes(
576 object, name, value, attrs));
582 RUNTIME_FUNCTION(Runtime_AddElement) {
583 HandleScope scope(isolate);
584 DCHECK_EQ(3, args.length());
586 CONVERT_ARG_HANDLE_CHECKED(JSObject,
object, 0);
587 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
588 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
591 CHECK(key->ToArrayIndex(&index));
594 LookupIterator it(isolate,
object, index,
object,
595 LookupIterator::OWN_SKIP_INTERCEPTOR);
596 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
597 if (maybe.IsNothing())
return ReadOnlyRoots(isolate).exception();
598 DCHECK(!it.IsFound());
600 if (object->IsJSArray()) {
601 Handle<JSArray> array = Handle<JSArray>::cast(
object);
602 DCHECK(!JSArray::WouldChangeReadOnlyLength(array, index));
606 RETURN_RESULT_OR_FAILURE(isolate, JSObject::SetOwnElementIgnoreAttributes(
607 object, index, value, NONE));
610 RUNTIME_FUNCTION(Runtime_SetKeyedProperty) {
611 HandleScope scope(isolate);
612 DCHECK_EQ(4, args.length());
614 CONVERT_ARG_HANDLE_CHECKED(Object,
object, 0);
615 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
616 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
617 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 3);
619 RETURN_RESULT_OR_FAILURE(
621 Runtime::SetObjectProperty(isolate,
object, key, value, language_mode,
622 StoreOrigin::kMaybeKeyed));
625 RUNTIME_FUNCTION(Runtime_SetNamedProperty) {
626 HandleScope scope(isolate);
627 DCHECK_EQ(4, args.length());
629 CONVERT_ARG_HANDLE_CHECKED(Object,
object, 0);
630 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
631 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
632 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 3);
634 RETURN_RESULT_OR_FAILURE(
635 isolate, Runtime::SetObjectProperty(isolate,
object, key, value,
636 language_mode, StoreOrigin::kNamed));
643 RUNTIME_FUNCTION(Runtime_StoreDataPropertyInLiteral) {
644 HandleScope scope(isolate);
645 DCHECK_EQ(3, args.length());
647 CONVERT_ARG_HANDLE_CHECKED(JSReceiver,
object, 0);
648 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
649 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
652 LookupIterator it = LookupIterator::PropertyOrElement(
653 isolate,
object, key, &success, LookupIterator::OWN);
656 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE, kDontThrow);
657 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
658 DCHECK(result.IsJust());
667 Object* DeleteProperty(Isolate* isolate, Handle<Object>
object,
668 Handle<Object> key, LanguageMode language_mode) {
669 Handle<JSReceiver> receiver;
670 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
671 Object::ToObject(isolate,
object));
673 Runtime::DeleteObjectProperty(isolate, receiver, key, language_mode);
674 MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
675 return isolate->heap()->ToBoolean(result.FromJust());
680 RUNTIME_FUNCTION(Runtime_DeleteProperty) {
681 HandleScope scope(isolate);
682 DCHECK_EQ(3, args.length());
683 CONVERT_ARG_HANDLE_CHECKED(Object,
object, 0);
684 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
685 CONVERT_SMI_ARG_CHECKED(language_mode, 2);
686 return DeleteProperty(isolate,
object, key,
687 static_cast<LanguageMode>(language_mode));
690 RUNTIME_FUNCTION(Runtime_ShrinkPropertyDictionary) {
691 HandleScope scope(isolate);
692 DCHECK_EQ(1, args.length());
693 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
694 Handle<NameDictionary> dictionary(receiver->property_dictionary(), isolate);
695 Handle<NameDictionary> new_properties =
696 NameDictionary::Shrink(isolate, dictionary);
697 receiver->SetProperties(*new_properties);
702 RUNTIME_FUNCTION(Runtime_HasProperty) {
703 HandleScope scope(isolate);
704 DCHECK_EQ(2, args.length());
705 CONVERT_ARG_HANDLE_CHECKED(Object,
object, 0);
706 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
709 if (!object->IsJSReceiver()) {
710 THROW_NEW_ERROR_RETURN_FAILURE(
712 NewTypeError(MessageTemplate::kInvalidInOperatorUse, key,
object));
714 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(
object);
718 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name,
719 Object::ToName(isolate, key));
722 Maybe<bool> maybe = JSReceiver::HasProperty(receiver, name);
723 if (maybe.IsNothing())
return ReadOnlyRoots(isolate).exception();
724 return isolate->heap()->ToBoolean(maybe.FromJust());
728 RUNTIME_FUNCTION(Runtime_GetOwnPropertyKeys) {
729 HandleScope scope(isolate);
730 DCHECK_EQ(2, args.length());
731 CONVERT_ARG_HANDLE_CHECKED(JSReceiver,
object, 0);
732 CONVERT_SMI_ARG_CHECKED(filter_value, 1);
735 Handle<FixedArray> keys;
736 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
738 KeyAccumulator::GetKeys(
object, KeyCollectionMode::kOwnOnly, filter,
739 GetKeysConversion::kConvertToString));
741 return *isolate->factory()->NewJSArrayWithElements(keys);
745 RUNTIME_FUNCTION(Runtime_ToFastProperties) {
746 HandleScope scope(isolate);
747 DCHECK_EQ(1, args.length());
748 CONVERT_ARG_HANDLE_CHECKED(Object,
object, 0);
749 if (object->IsJSObject() && !
object->IsJSGlobalObject()) {
750 JSObject::MigrateSlowToFast(Handle<JSObject>::cast(
object), 0,
751 "RuntimeToFastProperties");
757 RUNTIME_FUNCTION(Runtime_AllocateHeapNumber) {
758 HandleScope scope(isolate);
759 DCHECK_EQ(0, args.length());
760 return *isolate->factory()->NewHeapNumber(0);
764 RUNTIME_FUNCTION(Runtime_NewObject) {
765 HandleScope scope(isolate);
766 DCHECK_EQ(2, args.length());
767 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
768 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, new_target, 1);
769 RETURN_RESULT_OR_FAILURE(
771 JSObject::New(target, new_target, Handle<AllocationSite>::null()));
774 RUNTIME_FUNCTION(Runtime_CompleteInobjectSlackTrackingForMap) {
775 DisallowHeapAllocation no_gc;
776 HandleScope scope(isolate);
777 DCHECK_EQ(1, args.length());
779 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0);
780 initial_map->CompleteInobjectSlackTracking(isolate);
782 return ReadOnlyRoots(isolate).undefined_value();
786 RUNTIME_FUNCTION(Runtime_TryMigrateInstance) {
787 HandleScope scope(isolate);
788 DCHECK_EQ(1, args.length());
789 CONVERT_ARG_HANDLE_CHECKED(Object,
object, 0);
790 if (!object->IsJSObject())
return Smi::kZero;
791 Handle<JSObject> js_object = Handle<JSObject>::cast(
object);
793 if (!js_object->map()->is_deprecated())
return Smi::kZero;
798 if (!JSObject::TryMigrateInstance(js_object))
return Smi::kZero;
803 static bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) {
804 return obj->IsNullOrUndefined(isolate) || obj->IsCallable();
814 RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) {
815 HandleScope scope(isolate);
816 DCHECK_EQ(5, args.length());
817 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
818 CHECK(!obj->IsNull(isolate));
819 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
820 CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2);
821 CHECK(IsValidAccessor(isolate, getter));
822 CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3);
823 CHECK(IsValidAccessor(isolate, setter));
824 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 4);
826 RETURN_FAILURE_ON_EXCEPTION(
827 isolate, JSObject::DefineAccessor(obj, name, getter, setter, attrs));
828 return ReadOnlyRoots(isolate).undefined_value();
832 RUNTIME_FUNCTION(Runtime_DefineDataPropertyInLiteral) {
833 HandleScope scope(isolate);
834 DCHECK_EQ(6, args.length());
835 CONVERT_ARG_HANDLE_CHECKED(JSObject,
object, 0);
836 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
837 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
838 CONVERT_SMI_ARG_CHECKED(flag, 3);
839 CONVERT_ARG_HANDLE_CHECKED(FeedbackVector, vector, 4);
840 CONVERT_SMI_ARG_CHECKED(index, 5);
842 FeedbackNexus nexus(vector, FeedbackVector::ToSlot(index));
843 if (nexus.ic_state() == UNINITIALIZED) {
844 if (name->IsUniqueName()) {
845 nexus.ConfigureMonomorphic(name, handle(object->map(), isolate),
846 MaybeObjectHandle());
848 nexus.ConfigureMegamorphic(PROPERTY);
850 }
else if (nexus.ic_state() == MONOMORPHIC) {
851 if (nexus.FindFirstMap() !=
object->map() ||
852 nexus.GetFeedbackExtra() != MaybeObject::FromObject(*name)) {
853 nexus.ConfigureMegamorphic(PROPERTY);
857 DataPropertyInLiteralFlags flags =
858 static_cast<DataPropertyInLiteralFlag
>(flag);
860 PropertyAttributes attrs = (flags & DataPropertyInLiteralFlag::kDontEnum)
861 ? PropertyAttributes::DONT_ENUM
862 : PropertyAttributes::NONE;
864 if (flags & DataPropertyInLiteralFlag::kSetFunctionName) {
865 DCHECK(value->IsJSFunction());
866 Handle<JSFunction>
function = Handle<JSFunction>::cast(value);
867 DCHECK(!function->shared()->HasSharedName());
868 Handle<Map> function_map(function->map(), isolate);
869 if (!JSFunction::SetName(
function, name,
870 isolate->factory()->empty_string())) {
871 return ReadOnlyRoots(isolate).exception();
874 CHECK_IMPLIES(!IsClassConstructor(function->shared()->kind()),
875 *function_map == function->map());
878 LookupIterator it = LookupIterator::PropertyOrElement(
879 isolate,
object, name,
object, LookupIterator::OWN);
883 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attrs, kDontThrow)
888 RUNTIME_FUNCTION(Runtime_CollectTypeProfile) {
889 HandleScope scope(isolate);
890 DCHECK_EQ(3, args.length());
891 CONVERT_ARG_HANDLE_CHECKED(Smi, position, 0);
892 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
893 CONVERT_ARG_HANDLE_CHECKED(FeedbackVector, vector, 2);
895 Handle<String> type = Object::TypeOf(isolate, value);
896 if (value->IsJSReceiver()) {
897 Handle<JSReceiver>
object = Handle<JSReceiver>::cast(value);
898 type = JSReceiver::GetConstructorName(
object);
899 }
else if (value->IsNull(isolate)) {
902 type = Handle<String>(ReadOnlyRoots(isolate).null_string(), isolate);
905 DCHECK(vector->metadata()->HasTypeProfileSlot());
906 FeedbackNexus nexus(vector, vector->GetTypeProfileSlot());
907 nexus.Collect(type, position->value());
909 return ReadOnlyRoots(isolate).undefined_value();
912 RUNTIME_FUNCTION(Runtime_HasFastPackedElements) {
913 SealHandleScope shs(isolate);
914 DCHECK_EQ(1, args.length());
915 CONVERT_ARG_CHECKED(HeapObject, obj, 0);
916 return isolate->heap()->ToBoolean(
917 IsFastPackedElementsKind(obj->map()->elements_kind()));
921 RUNTIME_FUNCTION(Runtime_IsJSReceiver) {
922 SealHandleScope shs(isolate);
923 DCHECK_EQ(1, args.length());
924 CONVERT_ARG_CHECKED(Object, obj, 0);
925 return isolate->heap()->ToBoolean(obj->IsJSReceiver());
929 RUNTIME_FUNCTION(Runtime_ClassOf) {
930 SealHandleScope shs(isolate);
931 DCHECK_EQ(1, args.length());
932 CONVERT_ARG_CHECKED(Object, obj, 0);
933 if (!obj->IsJSReceiver())
return ReadOnlyRoots(isolate).null_value();
934 return JSReceiver::cast(obj)->class_name();
937 RUNTIME_FUNCTION(Runtime_GetFunctionName) {
938 HandleScope scope(isolate);
939 DCHECK_EQ(1, args.length());
940 CONVERT_ARG_HANDLE_CHECKED(JSFunction,
function, 0);
941 return *JSFunction::GetName(isolate,
function);
944 RUNTIME_FUNCTION(Runtime_DefineGetterPropertyUnchecked) {
945 HandleScope scope(isolate);
946 DCHECK_EQ(4, args.length());
947 CONVERT_ARG_HANDLE_CHECKED(JSObject,
object, 0);
948 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
949 CONVERT_ARG_HANDLE_CHECKED(JSFunction, getter, 2);
950 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
952 if (String::cast(getter->shared()->Name())->length() == 0) {
953 Handle<Map> getter_map(getter->map(), isolate);
954 if (!JSFunction::SetName(getter, name, isolate->factory()->get_string())) {
955 return ReadOnlyRoots(isolate).exception();
957 CHECK_EQ(*getter_map, getter->map());
960 RETURN_FAILURE_ON_EXCEPTION(
962 JSObject::DefineAccessor(
object, name, getter,
963 isolate->factory()->null_value(), attrs));
964 return ReadOnlyRoots(isolate).undefined_value();
967 RUNTIME_FUNCTION(Runtime_SetDataProperties) {
968 HandleScope scope(isolate);
969 DCHECK_EQ(2, args.length());
970 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0);
971 CONVERT_ARG_HANDLE_CHECKED(Object, source, 1);
974 if (source->IsUndefined(isolate) || source->IsNull(isolate)) {
975 return ReadOnlyRoots(isolate).undefined_value();
978 MAYBE_RETURN(JSReceiver::SetOrCopyDataProperties(isolate, target, source),
979 ReadOnlyRoots(isolate).exception());
980 return ReadOnlyRoots(isolate).undefined_value();
983 RUNTIME_FUNCTION(Runtime_CopyDataProperties) {
984 HandleScope scope(isolate);
985 DCHECK_EQ(2, args.length());
986 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
987 CONVERT_ARG_HANDLE_CHECKED(Object, source, 1);
990 if (source->IsUndefined(isolate) || source->IsNull(isolate)) {
991 return ReadOnlyRoots(isolate).undefined_value();
994 MAYBE_RETURN(JSReceiver::SetOrCopyDataProperties(isolate, target, source,
996 ReadOnlyRoots(isolate).exception());
997 return ReadOnlyRoots(isolate).undefined_value();
1000 RUNTIME_FUNCTION(Runtime_CopyDataPropertiesWithExcludedProperties) {
1001 HandleScope scope(isolate);
1002 DCHECK_LE(1, args.length());
1003 CONVERT_ARG_HANDLE_CHECKED(Object, source, 0);
1006 if (source->IsUndefined(isolate) || source->IsNull(isolate)) {
1007 return ReadOnlyRoots(isolate).undefined_value();
1010 ScopedVector<Handle<Object>> excluded_properties(args.length() - 1);
1011 for (
int i = 1;
i < args.length();
i++) {
1012 Handle<Object>
property = args.at(
i);
1018 if (property->IsString() &&
1019 String::cast(*property)->AsArrayIndex(&property_num)) {
1020 property = isolate->factory()->NewNumberFromUint(property_num);
1023 excluded_properties[
i - 1] = property;
1026 Handle<JSObject> target =
1027 isolate->factory()->NewJSObject(isolate->object_function());
1028 MAYBE_RETURN(JSReceiver::SetOrCopyDataProperties(isolate, target, source,
1029 &excluded_properties,
false),
1030 ReadOnlyRoots(isolate).exception());
1036 inline void TrySetNative(Handle<Object> maybe_func) {
1037 if (!maybe_func->IsJSFunction())
return;
1038 JSFunction::cast(*maybe_func)->shared()->set_native(
true);
1041 inline void TrySetNativeAndLength(Handle<Object> maybe_func,
int length) {
1042 if (!maybe_func->IsJSFunction())
return;
1043 SharedFunctionInfo* shared = JSFunction::cast(*maybe_func)->shared();
1044 shared->set_native(
true);
1046 shared->set_length(length);
1052 RUNTIME_FUNCTION(Runtime_DefineMethodsInternal) {
1053 HandleScope scope(isolate);
1054 DCHECK_EQ(3, args.length());
1055 CHECK(isolate->bootstrapper()->IsActive());
1056 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
1057 CONVERT_ARG_HANDLE_CHECKED(JSFunction, source_class, 1);
1058 CONVERT_SMI_ARG_CHECKED(length, 2);
1060 DCHECK(source_class->prototype()->IsJSObject());
1061 Handle<JSObject> source(JSObject::cast(source_class->prototype()), isolate);
1063 Handle<FixedArray> keys;
1064 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1066 KeyAccumulator::GetKeys(source, KeyCollectionMode::kOwnOnly,
1068 GetKeysConversion::kConvertToString));
1070 for (
int i = 0;
i < keys->length(); ++
i) {
1071 Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys,
i, isolate));
1072 if (*key == ReadOnlyRoots(isolate).constructor_string())
continue;
1074 PropertyDescriptor descriptor;
1075 Maybe<bool> did_get_descriptor =
1076 JSReceiver::GetOwnPropertyDescriptor(isolate, source, key, &descriptor);
1077 CHECK(did_get_descriptor.FromJust());
1078 if (descriptor.has_value()) {
1079 TrySetNativeAndLength(descriptor.value(), length);
1081 if (descriptor.has_get()) TrySetNative(descriptor.get());
1082 if (descriptor.has_set()) TrySetNative(descriptor.set());
1085 Maybe<bool> success = JSReceiver::DefineOwnProperty(
1086 isolate, target, key, &descriptor, kDontThrow);
1087 CHECK(success.FromJust());
1089 return ReadOnlyRoots(isolate).undefined_value();
1092 RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) {
1093 HandleScope scope(isolate);
1094 DCHECK_EQ(4, args.length());
1095 CONVERT_ARG_HANDLE_CHECKED(JSObject,
object, 0);
1096 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
1097 CONVERT_ARG_HANDLE_CHECKED(JSFunction, setter, 2);
1098 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
1100 if (String::cast(setter->shared()->Name())->length() == 0) {
1101 Handle<Map> setter_map(setter->map(), isolate);
1102 if (!JSFunction::SetName(setter, name, isolate->factory()->set_string())) {
1103 return ReadOnlyRoots(isolate).exception();
1105 CHECK_EQ(*setter_map, setter->map());
1108 RETURN_FAILURE_ON_EXCEPTION(
1110 JSObject::DefineAccessor(
object, name, isolate->factory()->null_value(),
1112 return ReadOnlyRoots(isolate).undefined_value();
1115 RUNTIME_FUNCTION(Runtime_ToObject) {
1121 RUNTIME_FUNCTION(Runtime_ToNumber) {
1122 HandleScope scope(isolate);
1123 DCHECK_EQ(1, args.length());
1124 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1125 RETURN_RESULT_OR_FAILURE(isolate, Object::ToNumber(isolate, input));
1128 RUNTIME_FUNCTION(Runtime_ToNumeric) {
1129 HandleScope scope(isolate);
1130 DCHECK_EQ(1, args.length());
1131 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1132 RETURN_RESULT_OR_FAILURE(isolate, Object::ToNumeric(isolate, input));
1136 RUNTIME_FUNCTION(Runtime_ToLength) {
1137 HandleScope scope(isolate);
1138 DCHECK_EQ(1, args.length());
1139 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1140 RETURN_RESULT_OR_FAILURE(isolate, Object::ToLength(isolate, input));
1144 RUNTIME_FUNCTION(Runtime_ToString) {
1145 HandleScope scope(isolate);
1146 DCHECK_EQ(1, args.length());
1147 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1148 RETURN_RESULT_OR_FAILURE(isolate, Object::ToString(isolate, input));
1152 RUNTIME_FUNCTION(Runtime_ToName) {
1153 HandleScope scope(isolate);
1154 DCHECK_EQ(1, args.length());
1155 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
1156 RETURN_RESULT_OR_FAILURE(isolate, Object::ToName(isolate, input));
1159 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) {
1160 HandleScope scope(isolate);
1161 DCHECK_EQ(2, args.length());
1162 CONVERT_ARG_HANDLE_CHECKED(Object,
object, 0);
1163 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
1164 if (!object->IsJSReceiver())
return ReadOnlyRoots(isolate).false_value();
1165 Maybe<bool> result = JSReceiver::HasInPrototypeChain(
1166 isolate, Handle<JSReceiver>::cast(
object), prototype);
1167 MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
1168 return isolate->heap()->ToBoolean(result.FromJust());
1173 RUNTIME_FUNCTION(Runtime_CreateIterResultObject) {
1174 HandleScope scope(isolate);
1175 DCHECK_EQ(2, args.length());
1176 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
1177 CONVERT_ARG_HANDLE_CHECKED(Object, done, 1);
1178 return *isolate->factory()->NewJSIteratorResult(value,
1179 done->BooleanValue(isolate));
1182 RUNTIME_FUNCTION(Runtime_CreateDataProperty) {
1183 HandleScope scope(isolate);
1184 DCHECK_EQ(3, args.length());
1185 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, o, 0);
1186 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
1187 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
1189 LookupIterator it = LookupIterator::PropertyOrElement(
1190 isolate, o, key, &success, LookupIterator::OWN);
1191 if (!success)
return ReadOnlyRoots(isolate).exception();
1192 MAYBE_RETURN(JSReceiver::CreateDataProperty(&it, value, kThrowOnError),
1193 ReadOnlyRoots(isolate).exception());
1197 RUNTIME_FUNCTION(Runtime_GetOwnPropertyDescriptor) {
1198 HandleScope scope(isolate);
1200 DCHECK_EQ(2, args.length());
1201 CONVERT_ARG_HANDLE_CHECKED(JSReceiver,
object, 0);
1202 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
1204 PropertyDescriptor desc;
1206 JSReceiver::GetOwnPropertyDescriptor(isolate,
object, name, &desc);
1207 MAYBE_RETURN(found, ReadOnlyRoots(isolate).exception());
1209 if (!found.FromJust())
return ReadOnlyRoots(isolate).undefined_value();
1210 return *desc.ToPropertyDescriptorObject(isolate);
1213 RUNTIME_FUNCTION(Runtime_AddPrivateField) {
1214 HandleScope scope(isolate);
1215 DCHECK_EQ(3, args.length());
1216 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, o, 0);
1217 CONVERT_ARG_HANDLE_CHECKED(Symbol, key, 1);
1218 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
1219 DCHECK(key->is_private_name());
1222 LookupIterator::PropertyOrElement(isolate, o, key, LookupIterator::OWN);
1225 THROW_NEW_ERROR_RETURN_FAILURE(
1226 isolate, NewTypeError(MessageTemplate::kVarRedeclaration, key));
1229 CHECK(Object::AddDataProperty(&it, value, NONE, kDontThrow,
1230 StoreOrigin::kMaybeKeyed)
1232 return ReadOnlyRoots(isolate).undefined_value();