11cb0ef41Sopenharmony_ci// Copyright 2014 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "src/ast/prettyprinter.h" 61cb0ef41Sopenharmony_ci#include "src/base/macros.h" 71cb0ef41Sopenharmony_ci#include "src/builtins/builtins.h" 81cb0ef41Sopenharmony_ci#include "src/common/globals.h" 91cb0ef41Sopenharmony_ci#include "src/common/message-template.h" 101cb0ef41Sopenharmony_ci#include "src/debug/debug.h" 111cb0ef41Sopenharmony_ci#include "src/execution/arguments-inl.h" 121cb0ef41Sopenharmony_ci#include "src/execution/frames.h" 131cb0ef41Sopenharmony_ci#include "src/execution/isolate-inl.h" 141cb0ef41Sopenharmony_ci#include "src/execution/messages.h" 151cb0ef41Sopenharmony_ci#include "src/handles/maybe-handles.h" 161cb0ef41Sopenharmony_ci#include "src/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop. 171cb0ef41Sopenharmony_ci#include "src/heap/memory-chunk.h" 181cb0ef41Sopenharmony_ci#include "src/init/bootstrapper.h" 191cb0ef41Sopenharmony_ci#include "src/logging/counters.h" 201cb0ef41Sopenharmony_ci#include "src/objects/hash-table-inl.h" 211cb0ef41Sopenharmony_ci#include "src/objects/js-array-inl.h" 221cb0ef41Sopenharmony_ci#include "src/objects/map-updater.h" 231cb0ef41Sopenharmony_ci#include "src/objects/property-descriptor-object.h" 241cb0ef41Sopenharmony_ci#include "src/objects/property-descriptor.h" 251cb0ef41Sopenharmony_ci#include "src/objects/property-details.h" 261cb0ef41Sopenharmony_ci#include "src/objects/swiss-name-dictionary-inl.h" 271cb0ef41Sopenharmony_ci#include "src/runtime/runtime-utils.h" 281cb0ef41Sopenharmony_ci#include "src/runtime/runtime.h" 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cinamespace v8 { 311cb0ef41Sopenharmony_cinamespace internal { 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciMaybeHandle<Object> Runtime::GetObjectProperty( 341cb0ef41Sopenharmony_ci Isolate* isolate, Handle<Object> lookup_start_object, Handle<Object> key, 351cb0ef41Sopenharmony_ci Handle<Object> receiver, bool* is_found) { 361cb0ef41Sopenharmony_ci if (receiver.is_null()) { 371cb0ef41Sopenharmony_ci receiver = lookup_start_object; 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci if (lookup_start_object->IsNullOrUndefined(isolate)) { 401cb0ef41Sopenharmony_ci ErrorUtils::ThrowLoadFromNullOrUndefined(isolate, lookup_start_object, key); 411cb0ef41Sopenharmony_ci return MaybeHandle<Object>(); 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci bool success = false; 451cb0ef41Sopenharmony_ci PropertyKey lookup_key(isolate, key, &success); 461cb0ef41Sopenharmony_ci if (!success) return MaybeHandle<Object>(); 471cb0ef41Sopenharmony_ci LookupIterator it = 481cb0ef41Sopenharmony_ci LookupIterator(isolate, receiver, lookup_key, lookup_start_object); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci MaybeHandle<Object> result = Object::GetProperty(&it); 511cb0ef41Sopenharmony_ci if (result.is_null()) { 521cb0ef41Sopenharmony_ci return result; 531cb0ef41Sopenharmony_ci } 541cb0ef41Sopenharmony_ci if (is_found) *is_found = it.IsFound(); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci if (!it.IsFound() && key->IsSymbol() && 571cb0ef41Sopenharmony_ci Symbol::cast(*key).is_private_name()) { 581cb0ef41Sopenharmony_ci MessageTemplate message = 591cb0ef41Sopenharmony_ci Symbol::cast(*key).IsPrivateBrand() 601cb0ef41Sopenharmony_ci ? MessageTemplate::kInvalidPrivateBrandInstance 611cb0ef41Sopenharmony_ci : MessageTemplate::kInvalidPrivateMemberRead; 621cb0ef41Sopenharmony_ci THROW_NEW_ERROR(isolate, NewTypeError(message, key, lookup_start_object), 631cb0ef41Sopenharmony_ci Object); 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci return result; 661cb0ef41Sopenharmony_ci} 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ciMaybeHandle<Object> Runtime::HasProperty(Isolate* isolate, 691cb0ef41Sopenharmony_ci Handle<Object> object, 701cb0ef41Sopenharmony_ci Handle<Object> key) { 711cb0ef41Sopenharmony_ci // Check that {object} is actually a receiver. 721cb0ef41Sopenharmony_ci if (!object->IsJSReceiver()) { 731cb0ef41Sopenharmony_ci THROW_NEW_ERROR( 741cb0ef41Sopenharmony_ci isolate, 751cb0ef41Sopenharmony_ci NewTypeError(MessageTemplate::kInvalidInOperatorUse, key, object), 761cb0ef41Sopenharmony_ci Object); 771cb0ef41Sopenharmony_ci } 781cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci // Convert the {key} to a name. 811cb0ef41Sopenharmony_ci Handle<Name> name; 821cb0ef41Sopenharmony_ci ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key), 831cb0ef41Sopenharmony_ci Object); 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci // Lookup the {name} on {receiver}. 861cb0ef41Sopenharmony_ci Maybe<bool> maybe = JSReceiver::HasProperty(isolate, receiver, name); 871cb0ef41Sopenharmony_ci if (maybe.IsNothing()) return MaybeHandle<Object>(); 881cb0ef41Sopenharmony_ci return maybe.FromJust() ? ReadOnlyRoots(isolate).true_value_handle() 891cb0ef41Sopenharmony_ci : ReadOnlyRoots(isolate).false_value_handle(); 901cb0ef41Sopenharmony_ci} 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_cinamespace { 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci// This function sets the sentinel value in a deleted field. Thes sentinel has 951cb0ef41Sopenharmony_ci// to look like a proper standalone object because the slack tracking may 961cb0ef41Sopenharmony_ci// complete at any time. For this reason we use the filler map word. 971cb0ef41Sopenharmony_ci// If V8_MAP_PACKING is enabled, then the filler map word is a packed filler 981cb0ef41Sopenharmony_ci// map. Otherwise, the filler map word is the same as the filler map. 991cb0ef41Sopenharmony_ciinline void ClearField(Isolate* isolate, JSObject object, FieldIndex index) { 1001cb0ef41Sopenharmony_ci if (index.is_inobject()) { 1011cb0ef41Sopenharmony_ci MapWord filler_map_word = 1021cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).one_pointer_filler_map_word(); 1031cb0ef41Sopenharmony_ci#ifndef V8_MAP_PACKING 1041cb0ef41Sopenharmony_ci DCHECK_EQ(filler_map_word.ToMap(), 1051cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).one_pointer_filler_map()); 1061cb0ef41Sopenharmony_ci#endif 1071cb0ef41Sopenharmony_ci int offset = index.offset(); 1081cb0ef41Sopenharmony_ci TaggedField<MapWord>::Release_Store(object, offset, filler_map_word); 1091cb0ef41Sopenharmony_ci } else { 1101cb0ef41Sopenharmony_ci object.property_array().set( 1111cb0ef41Sopenharmony_ci index.outobject_array_index(), 1121cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).one_pointer_filler_map()); 1131cb0ef41Sopenharmony_ci } 1141cb0ef41Sopenharmony_ci} 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_civoid GeneralizeAllTransitionsToFieldAsMutable(Isolate* isolate, Handle<Map> map, 1171cb0ef41Sopenharmony_ci Handle<Name> name) { 1181cb0ef41Sopenharmony_ci InternalIndex descriptor(map->NumberOfOwnDescriptors()); 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ci Handle<Map> target_maps[kPropertyAttributesCombinationsCount]; 1211cb0ef41Sopenharmony_ci int target_maps_count = 0; 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci // Collect all outgoing field transitions. 1241cb0ef41Sopenharmony_ci { 1251cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1261cb0ef41Sopenharmony_ci TransitionsAccessor transitions(isolate, *map); 1271cb0ef41Sopenharmony_ci transitions.ForEachTransitionTo( 1281cb0ef41Sopenharmony_ci *name, 1291cb0ef41Sopenharmony_ci [&](Map target) { 1301cb0ef41Sopenharmony_ci DCHECK_EQ(descriptor, target.LastAdded()); 1311cb0ef41Sopenharmony_ci DCHECK_EQ(*name, target.GetLastDescriptorName(isolate)); 1321cb0ef41Sopenharmony_ci PropertyDetails details = target.GetLastDescriptorDetails(isolate); 1331cb0ef41Sopenharmony_ci // Currently, we track constness only for fields. 1341cb0ef41Sopenharmony_ci if (details.kind() == PropertyKind::kData && 1351cb0ef41Sopenharmony_ci details.constness() == PropertyConstness::kConst) { 1361cb0ef41Sopenharmony_ci target_maps[target_maps_count++] = handle(target, isolate); 1371cb0ef41Sopenharmony_ci } 1381cb0ef41Sopenharmony_ci DCHECK_IMPLIES(details.kind() == PropertyKind::kAccessor, 1391cb0ef41Sopenharmony_ci details.constness() == PropertyConstness::kConst); 1401cb0ef41Sopenharmony_ci }, 1411cb0ef41Sopenharmony_ci &no_gc); 1421cb0ef41Sopenharmony_ci CHECK_LE(target_maps_count, kPropertyAttributesCombinationsCount); 1431cb0ef41Sopenharmony_ci } 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_ci for (int i = 0; i < target_maps_count; i++) { 1461cb0ef41Sopenharmony_ci Handle<Map> target = target_maps[i]; 1471cb0ef41Sopenharmony_ci PropertyDetails details = 1481cb0ef41Sopenharmony_ci target->instance_descriptors(isolate).GetDetails(descriptor); 1491cb0ef41Sopenharmony_ci Handle<FieldType> field_type( 1501cb0ef41Sopenharmony_ci target->instance_descriptors(isolate).GetFieldType(descriptor), 1511cb0ef41Sopenharmony_ci isolate); 1521cb0ef41Sopenharmony_ci MapUpdater::GeneralizeField(isolate, target, descriptor, 1531cb0ef41Sopenharmony_ci PropertyConstness::kMutable, 1541cb0ef41Sopenharmony_ci details.representation(), field_type); 1551cb0ef41Sopenharmony_ci DCHECK_EQ(PropertyConstness::kMutable, target->instance_descriptors(isolate) 1561cb0ef41Sopenharmony_ci .GetDetails(descriptor) 1571cb0ef41Sopenharmony_ci .constness()); 1581cb0ef41Sopenharmony_ci } 1591cb0ef41Sopenharmony_ci} 1601cb0ef41Sopenharmony_ci 1611cb0ef41Sopenharmony_cibool DeleteObjectPropertyFast(Isolate* isolate, Handle<JSReceiver> receiver, 1621cb0ef41Sopenharmony_ci Handle<Object> raw_key) { 1631cb0ef41Sopenharmony_ci // This implements a special case for fast property deletion: when the 1641cb0ef41Sopenharmony_ci // last property in an object is deleted, then instead of normalizing 1651cb0ef41Sopenharmony_ci // the properties, we can undo the last map transition, with a few 1661cb0ef41Sopenharmony_ci // prerequisites: 1671cb0ef41Sopenharmony_ci // (1) The receiver must be a regular object and the key a unique name. 1681cb0ef41Sopenharmony_ci Handle<Map> receiver_map(receiver->map(), isolate); 1691cb0ef41Sopenharmony_ci if (receiver_map->IsSpecialReceiverMap()) return false; 1701cb0ef41Sopenharmony_ci DCHECK(receiver_map->IsJSObjectMap()); 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ci if (!raw_key->IsUniqueName()) return false; 1731cb0ef41Sopenharmony_ci Handle<Name> key = Handle<Name>::cast(raw_key); 1741cb0ef41Sopenharmony_ci // (2) The property to be deleted must be the last property. 1751cb0ef41Sopenharmony_ci int nof = receiver_map->NumberOfOwnDescriptors(); 1761cb0ef41Sopenharmony_ci if (nof == 0) return false; 1771cb0ef41Sopenharmony_ci InternalIndex descriptor(nof - 1); 1781cb0ef41Sopenharmony_ci Handle<DescriptorArray> descriptors( 1791cb0ef41Sopenharmony_ci receiver_map->instance_descriptors(isolate), isolate); 1801cb0ef41Sopenharmony_ci if (descriptors->GetKey(descriptor) != *key) return false; 1811cb0ef41Sopenharmony_ci // (3) The property to be deleted must be deletable. 1821cb0ef41Sopenharmony_ci PropertyDetails details = descriptors->GetDetails(descriptor); 1831cb0ef41Sopenharmony_ci if (!details.IsConfigurable()) return false; 1841cb0ef41Sopenharmony_ci // (4) The map must have a back pointer. 1851cb0ef41Sopenharmony_ci Handle<Object> backpointer(receiver_map->GetBackPointer(), isolate); 1861cb0ef41Sopenharmony_ci if (!backpointer->IsMap()) return false; 1871cb0ef41Sopenharmony_ci Handle<Map> parent_map = Handle<Map>::cast(backpointer); 1881cb0ef41Sopenharmony_ci // (5) The last transition must have been caused by adding a property 1891cb0ef41Sopenharmony_ci // (and not any kind of special transition). 1901cb0ef41Sopenharmony_ci if (parent_map->NumberOfOwnDescriptors() != nof - 1) return false; 1911cb0ef41Sopenharmony_ci 1921cb0ef41Sopenharmony_ci // Preconditions successful. No more bailouts after this point. 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci // Zap the property to avoid keeping objects alive. Zapping is not necessary 1951cb0ef41Sopenharmony_ci // for properties stored in the descriptor array. 1961cb0ef41Sopenharmony_ci if (details.location() == PropertyLocation::kField) { 1971cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1981cb0ef41Sopenharmony_ci 1991cb0ef41Sopenharmony_ci // Invalidate slots manually later in case we delete an in-object tagged 2001cb0ef41Sopenharmony_ci // property. In this case we might later store an untagged value in the 2011cb0ef41Sopenharmony_ci // recorded slot. 2021cb0ef41Sopenharmony_ci isolate->heap()->NotifyObjectLayoutChange(*receiver, no_gc, 2031cb0ef41Sopenharmony_ci InvalidateRecordedSlots::kNo); 2041cb0ef41Sopenharmony_ci FieldIndex index = 2051cb0ef41Sopenharmony_ci FieldIndex::ForPropertyIndex(*receiver_map, details.field_index()); 2061cb0ef41Sopenharmony_ci // Special case deleting the last out-of object property. 2071cb0ef41Sopenharmony_ci if (!index.is_inobject() && index.outobject_array_index() == 0) { 2081cb0ef41Sopenharmony_ci DCHECK(!parent_map->HasOutOfObjectProperties()); 2091cb0ef41Sopenharmony_ci // Clear out the properties backing store. 2101cb0ef41Sopenharmony_ci receiver->SetProperties(ReadOnlyRoots(isolate).empty_fixed_array()); 2111cb0ef41Sopenharmony_ci } else { 2121cb0ef41Sopenharmony_ci ClearField(isolate, JSObject::cast(*receiver), index); 2131cb0ef41Sopenharmony_ci // We must clear any recorded slot for the deleted property, because 2141cb0ef41Sopenharmony_ci // subsequent object modifications might put a raw double there. 2151cb0ef41Sopenharmony_ci // Slot clearing is the reason why this entire function cannot currently 2161cb0ef41Sopenharmony_ci // be implemented in the DeleteProperty stub. 2171cb0ef41Sopenharmony_ci if (index.is_inobject()) { 2181cb0ef41Sopenharmony_ci // We need to clear the recorded slot in this case because in-object 2191cb0ef41Sopenharmony_ci // slack tracking might not be finished. This ensures that we don't 2201cb0ef41Sopenharmony_ci // have recorded slots in free space. 2211cb0ef41Sopenharmony_ci isolate->heap()->ClearRecordedSlot(*receiver, 2221cb0ef41Sopenharmony_ci receiver->RawField(index.offset())); 2231cb0ef41Sopenharmony_ci if (!FLAG_enable_third_party_heap) { 2241cb0ef41Sopenharmony_ci MemoryChunk* chunk = MemoryChunk::FromHeapObject(*receiver); 2251cb0ef41Sopenharmony_ci chunk->InvalidateRecordedSlots(*receiver); 2261cb0ef41Sopenharmony_ci } 2271cb0ef41Sopenharmony_ci } 2281cb0ef41Sopenharmony_ci } 2291cb0ef41Sopenharmony_ci } 2301cb0ef41Sopenharmony_ci // If the {receiver_map} was marked stable before, then there could be 2311cb0ef41Sopenharmony_ci // optimized code that depends on the assumption that no object that 2321cb0ef41Sopenharmony_ci // reached this {receiver_map} transitions away from it without triggering 2331cb0ef41Sopenharmony_ci // the "deoptimize dependent code" mechanism. 2341cb0ef41Sopenharmony_ci receiver_map->NotifyLeafMapLayoutChange(isolate); 2351cb0ef41Sopenharmony_ci // Finally, perform the map rollback. 2361cb0ef41Sopenharmony_ci receiver->set_map(*parent_map, kReleaseStore); 2371cb0ef41Sopenharmony_ci#if VERIFY_HEAP 2381cb0ef41Sopenharmony_ci receiver->HeapObjectVerify(isolate); 2391cb0ef41Sopenharmony_ci receiver->property_array().PropertyArrayVerify(isolate); 2401cb0ef41Sopenharmony_ci#endif 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_ci // If the {descriptor} was "const" so far, we need to update the 2431cb0ef41Sopenharmony_ci // {receiver_map} here, otherwise we could get the constants wrong, i.e. 2441cb0ef41Sopenharmony_ci // 2451cb0ef41Sopenharmony_ci // o.x = 1; 2461cb0ef41Sopenharmony_ci // [change o.x's attributes or reconfigure property kind] 2471cb0ef41Sopenharmony_ci // delete o.x; 2481cb0ef41Sopenharmony_ci // o.x = 2; 2491cb0ef41Sopenharmony_ci // 2501cb0ef41Sopenharmony_ci // could trick V8 into thinking that `o.x` is still 1 even after the second 2511cb0ef41Sopenharmony_ci // assignment. 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_ci // Step 1: Migrate object to an up-to-date shape. 2541cb0ef41Sopenharmony_ci if (parent_map->is_deprecated()) { 2551cb0ef41Sopenharmony_ci JSObject::MigrateInstance(isolate, Handle<JSObject>::cast(receiver)); 2561cb0ef41Sopenharmony_ci parent_map = handle(receiver->map(), isolate); 2571cb0ef41Sopenharmony_ci } 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ci // Step 2: Mark outgoing transitions from the up-to-date version of the 2601cb0ef41Sopenharmony_ci // parent_map to same property name of any kind or attributes as mutable. 2611cb0ef41Sopenharmony_ci // Also migrate object to the up-to-date map to make the object shapes 2621cb0ef41Sopenharmony_ci // converge sooner. 2631cb0ef41Sopenharmony_ci GeneralizeAllTransitionsToFieldAsMutable(isolate, parent_map, key); 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ci return true; 2661cb0ef41Sopenharmony_ci} 2671cb0ef41Sopenharmony_ci 2681cb0ef41Sopenharmony_ci} // namespace 2691cb0ef41Sopenharmony_ci 2701cb0ef41Sopenharmony_ciMaybe<bool> Runtime::DeleteObjectProperty(Isolate* isolate, 2711cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver, 2721cb0ef41Sopenharmony_ci Handle<Object> key, 2731cb0ef41Sopenharmony_ci LanguageMode language_mode) { 2741cb0ef41Sopenharmony_ci if (DeleteObjectPropertyFast(isolate, receiver, key)) return Just(true); 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ci bool success = false; 2771cb0ef41Sopenharmony_ci PropertyKey lookup_key(isolate, key, &success); 2781cb0ef41Sopenharmony_ci if (!success) return Nothing<bool>(); 2791cb0ef41Sopenharmony_ci LookupIterator it(isolate, receiver, lookup_key, LookupIterator::OWN); 2801cb0ef41Sopenharmony_ci 2811cb0ef41Sopenharmony_ci return JSReceiver::DeleteProperty(&it, language_mode); 2821cb0ef41Sopenharmony_ci} 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_ci// ES #sec-object.keys 2851cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectKeys) { 2861cb0ef41Sopenharmony_ci HandleScope scope(isolate); 2871cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ci // Convert the {object} to a proper {receiver}. 2901cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver; 2911cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 2921cb0ef41Sopenharmony_ci Object::ToObject(isolate, object)); 2931cb0ef41Sopenharmony_ci 2941cb0ef41Sopenharmony_ci // Collect the own keys for the {receiver}. 2951cb0ef41Sopenharmony_ci Handle<FixedArray> keys; 2961cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 2971cb0ef41Sopenharmony_ci isolate, keys, 2981cb0ef41Sopenharmony_ci KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, 2991cb0ef41Sopenharmony_ci ENUMERABLE_STRINGS, 3001cb0ef41Sopenharmony_ci GetKeysConversion::kConvertToString)); 3011cb0ef41Sopenharmony_ci return *keys; 3021cb0ef41Sopenharmony_ci} 3031cb0ef41Sopenharmony_ci 3041cb0ef41Sopenharmony_ci// ES #sec-object.getOwnPropertyNames 3051cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectGetOwnPropertyNames) { 3061cb0ef41Sopenharmony_ci HandleScope scope(isolate); 3071cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 3081cb0ef41Sopenharmony_ci 3091cb0ef41Sopenharmony_ci // Convert the {object} to a proper {receiver}. 3101cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver; 3111cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 3121cb0ef41Sopenharmony_ci Object::ToObject(isolate, object)); 3131cb0ef41Sopenharmony_ci 3141cb0ef41Sopenharmony_ci // Collect the own keys for the {receiver}. 3151cb0ef41Sopenharmony_ci // TODO(v8:9401): We should extend the fast path of KeyAccumulator::GetKeys to 3161cb0ef41Sopenharmony_ci // also use fast path even when filter = SKIP_SYMBOLS. 3171cb0ef41Sopenharmony_ci Handle<FixedArray> keys; 3181cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 3191cb0ef41Sopenharmony_ci isolate, keys, 3201cb0ef41Sopenharmony_ci KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, 3211cb0ef41Sopenharmony_ci SKIP_SYMBOLS, 3221cb0ef41Sopenharmony_ci GetKeysConversion::kConvertToString)); 3231cb0ef41Sopenharmony_ci return *keys; 3241cb0ef41Sopenharmony_ci} 3251cb0ef41Sopenharmony_ci 3261cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectGetOwnPropertyNamesTryFast) { 3271cb0ef41Sopenharmony_ci HandleScope scope(isolate); 3281cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 3291cb0ef41Sopenharmony_ci 3301cb0ef41Sopenharmony_ci // Convert the {object} to a proper {receiver}. 3311cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver; 3321cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 3331cb0ef41Sopenharmony_ci Object::ToObject(isolate, object)); 3341cb0ef41Sopenharmony_ci 3351cb0ef41Sopenharmony_ci Handle<Map> map(receiver->map(), isolate); 3361cb0ef41Sopenharmony_ci 3371cb0ef41Sopenharmony_ci int nod = map->NumberOfOwnDescriptors(); 3381cb0ef41Sopenharmony_ci Handle<FixedArray> keys; 3391cb0ef41Sopenharmony_ci if (nod != 0 && map->NumberOfEnumerableProperties() == nod) { 3401cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 3411cb0ef41Sopenharmony_ci isolate, keys, 3421cb0ef41Sopenharmony_ci KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, 3431cb0ef41Sopenharmony_ci ENUMERABLE_STRINGS, 3441cb0ef41Sopenharmony_ci GetKeysConversion::kConvertToString)); 3451cb0ef41Sopenharmony_ci } else { 3461cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 3471cb0ef41Sopenharmony_ci isolate, keys, 3481cb0ef41Sopenharmony_ci KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, 3491cb0ef41Sopenharmony_ci SKIP_SYMBOLS, 3501cb0ef41Sopenharmony_ci GetKeysConversion::kConvertToString)); 3511cb0ef41Sopenharmony_ci } 3521cb0ef41Sopenharmony_ci 3531cb0ef41Sopenharmony_ci return *keys; 3541cb0ef41Sopenharmony_ci} 3551cb0ef41Sopenharmony_ci 3561cb0ef41Sopenharmony_ci// ES6 19.1.3.2 3571cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectHasOwnProperty) { 3581cb0ef41Sopenharmony_ci HandleScope scope(isolate); 3591cb0ef41Sopenharmony_ci Handle<Object> property = args.at(1); 3601cb0ef41Sopenharmony_ci 3611cb0ef41Sopenharmony_ci // TODO(ishell): To improve performance, consider performing the to-string 3621cb0ef41Sopenharmony_ci // conversion of {property} before calling into the runtime. 3631cb0ef41Sopenharmony_ci bool success; 3641cb0ef41Sopenharmony_ci PropertyKey key(isolate, property, &success); 3651cb0ef41Sopenharmony_ci if (!success) return ReadOnlyRoots(isolate).exception(); 3661cb0ef41Sopenharmony_ci 3671cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 3681cb0ef41Sopenharmony_ci 3691cb0ef41Sopenharmony_ci if (object->IsJSModuleNamespace()) { 3701cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key, LookupIterator::OWN); 3711cb0ef41Sopenharmony_ci PropertyDescriptor desc; 3721cb0ef41Sopenharmony_ci Maybe<bool> result = JSReceiver::GetOwnPropertyDescriptor(&it, &desc); 3731cb0ef41Sopenharmony_ci if (!result.IsJust()) return ReadOnlyRoots(isolate).exception(); 3741cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(result.FromJust()); 3751cb0ef41Sopenharmony_ci 3761cb0ef41Sopenharmony_ci } else if (object->IsJSObject()) { 3771cb0ef41Sopenharmony_ci Handle<JSObject> js_obj = Handle<JSObject>::cast(object); 3781cb0ef41Sopenharmony_ci // Fast case: either the key is a real named property or it is not 3791cb0ef41Sopenharmony_ci // an array index and there are no interceptors or hidden 3801cb0ef41Sopenharmony_ci // prototypes. 3811cb0ef41Sopenharmony_ci // TODO(jkummerow): Make JSReceiver::HasOwnProperty fast enough to 3821cb0ef41Sopenharmony_ci // handle all cases directly (without this custom fast path). 3831cb0ef41Sopenharmony_ci { 3841cb0ef41Sopenharmony_ci LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR; 3851cb0ef41Sopenharmony_ci LookupIterator it(isolate, js_obj, key, js_obj, c); 3861cb0ef41Sopenharmony_ci Maybe<bool> maybe = JSReceiver::HasProperty(&it); 3871cb0ef41Sopenharmony_ci if (maybe.IsNothing()) return ReadOnlyRoots(isolate).exception(); 3881cb0ef41Sopenharmony_ci DCHECK(!isolate->has_pending_exception()); 3891cb0ef41Sopenharmony_ci if (maybe.FromJust()) return ReadOnlyRoots(isolate).true_value(); 3901cb0ef41Sopenharmony_ci } 3911cb0ef41Sopenharmony_ci 3921cb0ef41Sopenharmony_ci Map map = js_obj->map(); 3931cb0ef41Sopenharmony_ci if (!map.IsJSGlobalProxyMap() && 3941cb0ef41Sopenharmony_ci (key.is_element() && key.index() <= JSObject::kMaxElementIndex 3951cb0ef41Sopenharmony_ci ? !map.has_indexed_interceptor() 3961cb0ef41Sopenharmony_ci : !map.has_named_interceptor())) { 3971cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).false_value(); 3981cb0ef41Sopenharmony_ci } 3991cb0ef41Sopenharmony_ci 4001cb0ef41Sopenharmony_ci // Slow case. 4011cb0ef41Sopenharmony_ci LookupIterator it(isolate, js_obj, key, js_obj, LookupIterator::OWN); 4021cb0ef41Sopenharmony_ci Maybe<bool> maybe = JSReceiver::HasProperty(&it); 4031cb0ef41Sopenharmony_ci if (maybe.IsNothing()) return ReadOnlyRoots(isolate).exception(); 4041cb0ef41Sopenharmony_ci DCHECK(!isolate->has_pending_exception()); 4051cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(maybe.FromJust()); 4061cb0ef41Sopenharmony_ci 4071cb0ef41Sopenharmony_ci } else if (object->IsJSProxy()) { 4081cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key, Handle<JSProxy>::cast(object), 4091cb0ef41Sopenharmony_ci LookupIterator::OWN); 4101cb0ef41Sopenharmony_ci Maybe<PropertyAttributes> attributes = 4111cb0ef41Sopenharmony_ci JSReceiver::GetPropertyAttributes(&it); 4121cb0ef41Sopenharmony_ci if (attributes.IsNothing()) return ReadOnlyRoots(isolate).exception(); 4131cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(attributes.FromJust() != ABSENT); 4141cb0ef41Sopenharmony_ci 4151cb0ef41Sopenharmony_ci } else if (object->IsString()) { 4161cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean( 4171cb0ef41Sopenharmony_ci key.is_element() 4181cb0ef41Sopenharmony_ci ? key.index() < static_cast<size_t>(String::cast(*object).length()) 4191cb0ef41Sopenharmony_ci : key.name()->Equals(ReadOnlyRoots(isolate).length_string())); 4201cb0ef41Sopenharmony_ci } else if (object->IsNullOrUndefined(isolate)) { 4211cb0ef41Sopenharmony_ci THROW_NEW_ERROR_RETURN_FAILURE( 4221cb0ef41Sopenharmony_ci isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); 4231cb0ef41Sopenharmony_ci } 4241cb0ef41Sopenharmony_ci 4251cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).false_value(); 4261cb0ef41Sopenharmony_ci} 4271cb0ef41Sopenharmony_ci 4281cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_HasOwnConstDataProperty) { 4291cb0ef41Sopenharmony_ci HandleScope scope(isolate); 4301cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 4311cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 4321cb0ef41Sopenharmony_ci Handle<Object> property = args.at(1); 4331cb0ef41Sopenharmony_ci 4341cb0ef41Sopenharmony_ci bool success; 4351cb0ef41Sopenharmony_ci PropertyKey key(isolate, property, &success); 4361cb0ef41Sopenharmony_ci if (!success) return ReadOnlyRoots(isolate).undefined_value(); 4371cb0ef41Sopenharmony_ci 4381cb0ef41Sopenharmony_ci if (object->IsJSObject()) { 4391cb0ef41Sopenharmony_ci Handle<JSObject> js_obj = Handle<JSObject>::cast(object); 4401cb0ef41Sopenharmony_ci LookupIterator it(isolate, js_obj, key, js_obj, LookupIterator::OWN); 4411cb0ef41Sopenharmony_ci 4421cb0ef41Sopenharmony_ci switch (it.state()) { 4431cb0ef41Sopenharmony_ci case LookupIterator::NOT_FOUND: 4441cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(false); 4451cb0ef41Sopenharmony_ci case LookupIterator::DATA: 4461cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(it.constness() == 4471cb0ef41Sopenharmony_ci PropertyConstness::kConst); 4481cb0ef41Sopenharmony_ci default: 4491cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 4501cb0ef41Sopenharmony_ci } 4511cb0ef41Sopenharmony_ci } 4521cb0ef41Sopenharmony_ci 4531cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 4541cb0ef41Sopenharmony_ci} 4551cb0ef41Sopenharmony_ci 4561cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_IsDictPropertyConstTrackingEnabled) { 4571cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(V8_DICT_PROPERTY_CONST_TRACKING_BOOL); 4581cb0ef41Sopenharmony_ci} 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_AddDictionaryProperty) { 4611cb0ef41Sopenharmony_ci HandleScope scope(isolate); 4621cb0ef41Sopenharmony_ci Handle<JSObject> receiver = args.at<JSObject>(0); 4631cb0ef41Sopenharmony_ci Handle<Name> name = args.at<Name>(1); 4641cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 4651cb0ef41Sopenharmony_ci 4661cb0ef41Sopenharmony_ci DCHECK(name->IsUniqueName()); 4671cb0ef41Sopenharmony_ci 4681cb0ef41Sopenharmony_ci PropertyDetails property_details( 4691cb0ef41Sopenharmony_ci PropertyKind::kData, NONE, 4701cb0ef41Sopenharmony_ci PropertyDetails::kConstIfDictConstnessTracking); 4711cb0ef41Sopenharmony_ci if (V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL) { 4721cb0ef41Sopenharmony_ci Handle<SwissNameDictionary> dictionary( 4731cb0ef41Sopenharmony_ci receiver->property_dictionary_swiss(), isolate); 4741cb0ef41Sopenharmony_ci dictionary = SwissNameDictionary::Add(isolate, dictionary, name, value, 4751cb0ef41Sopenharmony_ci property_details); 4761cb0ef41Sopenharmony_ci receiver->SetProperties(*dictionary); 4771cb0ef41Sopenharmony_ci } else { 4781cb0ef41Sopenharmony_ci Handle<NameDictionary> dictionary(receiver->property_dictionary(), isolate); 4791cb0ef41Sopenharmony_ci dictionary = 4801cb0ef41Sopenharmony_ci NameDictionary::Add(isolate, dictionary, name, value, property_details); 4811cb0ef41Sopenharmony_ci receiver->SetProperties(*dictionary); 4821cb0ef41Sopenharmony_ci } 4831cb0ef41Sopenharmony_ci 4841cb0ef41Sopenharmony_ci return *value; 4851cb0ef41Sopenharmony_ci} 4861cb0ef41Sopenharmony_ci 4871cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_AddPrivateBrand) { 4881cb0ef41Sopenharmony_ci HandleScope scope(isolate); 4891cb0ef41Sopenharmony_ci DCHECK_EQ(args.length(), 4); 4901cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = args.at<JSReceiver>(0); 4911cb0ef41Sopenharmony_ci Handle<Symbol> brand = args.at<Symbol>(1); 4921cb0ef41Sopenharmony_ci Handle<Context> context = args.at<Context>(2); 4931cb0ef41Sopenharmony_ci int depth = args.smi_value_at(3); 4941cb0ef41Sopenharmony_ci DCHECK(brand->is_private_name()); 4951cb0ef41Sopenharmony_ci 4961cb0ef41Sopenharmony_ci LookupIterator it(isolate, receiver, brand, LookupIterator::OWN); 4971cb0ef41Sopenharmony_ci 4981cb0ef41Sopenharmony_ci if (it.IsFound()) { 4991cb0ef41Sopenharmony_ci THROW_NEW_ERROR_RETURN_FAILURE( 5001cb0ef41Sopenharmony_ci isolate, 5011cb0ef41Sopenharmony_ci NewTypeError(MessageTemplate::kInvalidPrivateBrandReinitialization, 5021cb0ef41Sopenharmony_ci brand)); 5031cb0ef41Sopenharmony_ci } 5041cb0ef41Sopenharmony_ci 5051cb0ef41Sopenharmony_ci PropertyAttributes attributes = 5061cb0ef41Sopenharmony_ci static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 5071cb0ef41Sopenharmony_ci 5081cb0ef41Sopenharmony_ci // Look for the context in |depth| in the context chain to store it 5091cb0ef41Sopenharmony_ci // in the instance with the brand variable as key, which is needed by 5101cb0ef41Sopenharmony_ci // the debugger for retrieving names of private methods. 5111cb0ef41Sopenharmony_ci DCHECK_GE(depth, 0); 5121cb0ef41Sopenharmony_ci for (; depth > 0; depth--) { 5131cb0ef41Sopenharmony_ci context = 5141cb0ef41Sopenharmony_ci handle(Context::cast(context->get(Context::PREVIOUS_INDEX)), isolate); 5151cb0ef41Sopenharmony_ci } 5161cb0ef41Sopenharmony_ci DCHECK_EQ(context->scope_info().scope_type(), ScopeType::CLASS_SCOPE); 5171cb0ef41Sopenharmony_ci CHECK(Object::AddDataProperty(&it, context, attributes, Just(kDontThrow), 5181cb0ef41Sopenharmony_ci StoreOrigin::kMaybeKeyed) 5191cb0ef41Sopenharmony_ci .FromJust()); 5201cb0ef41Sopenharmony_ci return *receiver; 5211cb0ef41Sopenharmony_ci} 5221cb0ef41Sopenharmony_ci 5231cb0ef41Sopenharmony_ci// ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) 5241cb0ef41Sopenharmony_ci// TODO(verwaest): Support the common cases with precached map directly in 5251cb0ef41Sopenharmony_ci// an Object.create stub. 5261cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectCreate) { 5271cb0ef41Sopenharmony_ci HandleScope scope(isolate); 5281cb0ef41Sopenharmony_ci Handle<Object> prototype = args.at(0); 5291cb0ef41Sopenharmony_ci Handle<Object> properties = args.at(1); 5301cb0ef41Sopenharmony_ci Handle<JSObject> obj; 5311cb0ef41Sopenharmony_ci // 1. If Type(O) is neither Object nor Null, throw a TypeError exception. 5321cb0ef41Sopenharmony_ci if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) { 5331cb0ef41Sopenharmony_ci THROW_NEW_ERROR_RETURN_FAILURE( 5341cb0ef41Sopenharmony_ci isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); 5351cb0ef41Sopenharmony_ci } 5361cb0ef41Sopenharmony_ci // 2. Let obj be ObjectCreate(O). 5371cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 5381cb0ef41Sopenharmony_ci isolate, obj, JSObject::ObjectCreate(isolate, prototype)); 5391cb0ef41Sopenharmony_ci 5401cb0ef41Sopenharmony_ci // 3. If Properties is not undefined, then 5411cb0ef41Sopenharmony_ci if (!properties->IsUndefined(isolate)) { 5421cb0ef41Sopenharmony_ci // a. Return ? ObjectDefineProperties(obj, Properties). 5431cb0ef41Sopenharmony_ci // Define the properties if properties was specified and is not undefined. 5441cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE( 5451cb0ef41Sopenharmony_ci isolate, JSReceiver::DefineProperties(isolate, obj, properties)); 5461cb0ef41Sopenharmony_ci } 5471cb0ef41Sopenharmony_ci // 4. Return obj. 5481cb0ef41Sopenharmony_ci return *obj; 5491cb0ef41Sopenharmony_ci} 5501cb0ef41Sopenharmony_ci 5511cb0ef41Sopenharmony_ciMaybeHandle<Object> Runtime::SetObjectProperty( 5521cb0ef41Sopenharmony_ci Isolate* isolate, Handle<Object> object, Handle<Object> key, 5531cb0ef41Sopenharmony_ci Handle<Object> value, StoreOrigin store_origin, 5541cb0ef41Sopenharmony_ci Maybe<ShouldThrow> should_throw) { 5551cb0ef41Sopenharmony_ci if (object->IsNullOrUndefined(isolate)) { 5561cb0ef41Sopenharmony_ci MaybeHandle<String> maybe_property = 5571cb0ef41Sopenharmony_ci Object::NoSideEffectsToMaybeString(isolate, key); 5581cb0ef41Sopenharmony_ci Handle<String> property_name; 5591cb0ef41Sopenharmony_ci if (maybe_property.ToHandle(&property_name)) { 5601cb0ef41Sopenharmony_ci THROW_NEW_ERROR( 5611cb0ef41Sopenharmony_ci isolate, 5621cb0ef41Sopenharmony_ci NewTypeError(MessageTemplate::kNonObjectPropertyStoreWithProperty, 5631cb0ef41Sopenharmony_ci object, property_name), 5641cb0ef41Sopenharmony_ci Object); 5651cb0ef41Sopenharmony_ci } else { 5661cb0ef41Sopenharmony_ci THROW_NEW_ERROR( 5671cb0ef41Sopenharmony_ci isolate, 5681cb0ef41Sopenharmony_ci NewTypeError(MessageTemplate::kNonObjectPropertyStore, object), 5691cb0ef41Sopenharmony_ci Object); 5701cb0ef41Sopenharmony_ci } 5711cb0ef41Sopenharmony_ci } 5721cb0ef41Sopenharmony_ci 5731cb0ef41Sopenharmony_ci // Check if the given key is an array index. 5741cb0ef41Sopenharmony_ci bool success = false; 5751cb0ef41Sopenharmony_ci PropertyKey lookup_key(isolate, key, &success); 5761cb0ef41Sopenharmony_ci if (!success) return MaybeHandle<Object>(); 5771cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, lookup_key); 5781cb0ef41Sopenharmony_ci if (key->IsSymbol() && Symbol::cast(*key).is_private_name() && 5791cb0ef41Sopenharmony_ci !JSReceiver::CheckPrivateNameStore(&it, false)) { 5801cb0ef41Sopenharmony_ci return MaybeHandle<Object>(); 5811cb0ef41Sopenharmony_ci } 5821cb0ef41Sopenharmony_ci 5831cb0ef41Sopenharmony_ci MAYBE_RETURN_NULL( 5841cb0ef41Sopenharmony_ci Object::SetProperty(&it, value, store_origin, should_throw)); 5851cb0ef41Sopenharmony_ci 5861cb0ef41Sopenharmony_ci return value; 5871cb0ef41Sopenharmony_ci} 5881cb0ef41Sopenharmony_ci 5891cb0ef41Sopenharmony_ciMaybeHandle<Object> Runtime::DefineObjectOwnProperty(Isolate* isolate, 5901cb0ef41Sopenharmony_ci Handle<Object> object, 5911cb0ef41Sopenharmony_ci Handle<Object> key, 5921cb0ef41Sopenharmony_ci Handle<Object> value, 5931cb0ef41Sopenharmony_ci StoreOrigin store_origin) { 5941cb0ef41Sopenharmony_ci if (object->IsNullOrUndefined(isolate)) { 5951cb0ef41Sopenharmony_ci THROW_NEW_ERROR( 5961cb0ef41Sopenharmony_ci isolate, 5971cb0ef41Sopenharmony_ci NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), 5981cb0ef41Sopenharmony_ci Object); 5991cb0ef41Sopenharmony_ci } 6001cb0ef41Sopenharmony_ci 6011cb0ef41Sopenharmony_ci // Check if the given key is an array index. 6021cb0ef41Sopenharmony_ci bool success = false; 6031cb0ef41Sopenharmony_ci PropertyKey lookup_key(isolate, key, &success); 6041cb0ef41Sopenharmony_ci if (!success) return MaybeHandle<Object>(); 6051cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, lookup_key, LookupIterator::OWN); 6061cb0ef41Sopenharmony_ci 6071cb0ef41Sopenharmony_ci if (key->IsSymbol() && Symbol::cast(*key).is_private_name()) { 6081cb0ef41Sopenharmony_ci if (!JSReceiver::CheckPrivateNameStore(&it, true)) { 6091cb0ef41Sopenharmony_ci return MaybeHandle<Object>(); 6101cb0ef41Sopenharmony_ci } 6111cb0ef41Sopenharmony_ci DCHECK(!it.IsFound()); 6121cb0ef41Sopenharmony_ci MAYBE_RETURN_NULL( 6131cb0ef41Sopenharmony_ci JSReceiver::AddPrivateField(&it, value, Nothing<ShouldThrow>())); 6141cb0ef41Sopenharmony_ci } else { 6151cb0ef41Sopenharmony_ci MAYBE_RETURN_NULL( 6161cb0ef41Sopenharmony_ci JSReceiver::CreateDataProperty(&it, value, Nothing<ShouldThrow>())); 6171cb0ef41Sopenharmony_ci } 6181cb0ef41Sopenharmony_ci 6191cb0ef41Sopenharmony_ci return value; 6201cb0ef41Sopenharmony_ci} 6211cb0ef41Sopenharmony_ci 6221cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_InternalSetPrototype) { 6231cb0ef41Sopenharmony_ci HandleScope scope(isolate); 6241cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 6251cb0ef41Sopenharmony_ci Handle<JSReceiver> obj = args.at<JSReceiver>(0); 6261cb0ef41Sopenharmony_ci Handle<Object> prototype = args.at(1); 6271cb0ef41Sopenharmony_ci MAYBE_RETURN( 6281cb0ef41Sopenharmony_ci JSReceiver::SetPrototype(isolate, obj, prototype, false, kThrowOnError), 6291cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).exception()); 6301cb0ef41Sopenharmony_ci return *obj; 6311cb0ef41Sopenharmony_ci} 6321cb0ef41Sopenharmony_ci 6331cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) { 6341cb0ef41Sopenharmony_ci HandleScope scope(isolate); 6351cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 6361cb0ef41Sopenharmony_ci Handle<JSObject> object = args.at<JSObject>(0); 6371cb0ef41Sopenharmony_ci int properties = args.smi_value_at(1); 6381cb0ef41Sopenharmony_ci // Conservative upper limit to prevent fuzz tests from going OOM. 6391cb0ef41Sopenharmony_ci if (properties > 100000) return isolate->ThrowIllegalOperation(); 6401cb0ef41Sopenharmony_ci if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { 6411cb0ef41Sopenharmony_ci JSObject::NormalizeProperties(isolate, object, KEEP_INOBJECT_PROPERTIES, 6421cb0ef41Sopenharmony_ci properties, "OptimizeForAdding"); 6431cb0ef41Sopenharmony_ci } 6441cb0ef41Sopenharmony_ci return *object; 6451cb0ef41Sopenharmony_ci} 6461cb0ef41Sopenharmony_ci 6471cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectValues) { 6481cb0ef41Sopenharmony_ci HandleScope scope(isolate); 6491cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 6501cb0ef41Sopenharmony_ci 6511cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = args.at<JSReceiver>(0); 6521cb0ef41Sopenharmony_ci 6531cb0ef41Sopenharmony_ci Handle<FixedArray> values; 6541cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 6551cb0ef41Sopenharmony_ci isolate, values, 6561cb0ef41Sopenharmony_ci JSReceiver::GetOwnValues(receiver, PropertyFilter::ENUMERABLE_STRINGS, 6571cb0ef41Sopenharmony_ci true)); 6581cb0ef41Sopenharmony_ci return *isolate->factory()->NewJSArrayWithElements(values); 6591cb0ef41Sopenharmony_ci} 6601cb0ef41Sopenharmony_ci 6611cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectValuesSkipFastPath) { 6621cb0ef41Sopenharmony_ci HandleScope scope(isolate); 6631cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 6641cb0ef41Sopenharmony_ci 6651cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = args.at<JSReceiver>(0); 6661cb0ef41Sopenharmony_ci 6671cb0ef41Sopenharmony_ci Handle<FixedArray> value; 6681cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 6691cb0ef41Sopenharmony_ci isolate, value, 6701cb0ef41Sopenharmony_ci JSReceiver::GetOwnValues(receiver, PropertyFilter::ENUMERABLE_STRINGS, 6711cb0ef41Sopenharmony_ci false)); 6721cb0ef41Sopenharmony_ci return *isolate->factory()->NewJSArrayWithElements(value); 6731cb0ef41Sopenharmony_ci} 6741cb0ef41Sopenharmony_ci 6751cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectEntries) { 6761cb0ef41Sopenharmony_ci HandleScope scope(isolate); 6771cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 6781cb0ef41Sopenharmony_ci 6791cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = args.at<JSReceiver>(0); 6801cb0ef41Sopenharmony_ci 6811cb0ef41Sopenharmony_ci Handle<FixedArray> entries; 6821cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 6831cb0ef41Sopenharmony_ci isolate, entries, 6841cb0ef41Sopenharmony_ci JSReceiver::GetOwnEntries(receiver, PropertyFilter::ENUMERABLE_STRINGS, 6851cb0ef41Sopenharmony_ci true)); 6861cb0ef41Sopenharmony_ci return *isolate->factory()->NewJSArrayWithElements(entries); 6871cb0ef41Sopenharmony_ci} 6881cb0ef41Sopenharmony_ci 6891cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectEntriesSkipFastPath) { 6901cb0ef41Sopenharmony_ci HandleScope scope(isolate); 6911cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 6921cb0ef41Sopenharmony_ci 6931cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = args.at<JSReceiver>(0); 6941cb0ef41Sopenharmony_ci 6951cb0ef41Sopenharmony_ci Handle<FixedArray> entries; 6961cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 6971cb0ef41Sopenharmony_ci isolate, entries, 6981cb0ef41Sopenharmony_ci JSReceiver::GetOwnEntries(receiver, PropertyFilter::ENUMERABLE_STRINGS, 6991cb0ef41Sopenharmony_ci false)); 7001cb0ef41Sopenharmony_ci return *isolate->factory()->NewJSArrayWithElements(entries); 7011cb0ef41Sopenharmony_ci} 7021cb0ef41Sopenharmony_ci 7031cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ObjectIsExtensible) { 7041cb0ef41Sopenharmony_ci HandleScope scope(isolate); 7051cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 7061cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 7071cb0ef41Sopenharmony_ci 7081cb0ef41Sopenharmony_ci Maybe<bool> result = 7091cb0ef41Sopenharmony_ci object->IsJSReceiver() 7101cb0ef41Sopenharmony_ci ? JSReceiver::IsExtensible(Handle<JSReceiver>::cast(object)) 7111cb0ef41Sopenharmony_ci : Just(false); 7121cb0ef41Sopenharmony_ci MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); 7131cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(result.FromJust()); 7141cb0ef41Sopenharmony_ci} 7151cb0ef41Sopenharmony_ci 7161cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_JSReceiverPreventExtensionsThrow) { 7171cb0ef41Sopenharmony_ci HandleScope scope(isolate); 7181cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 7191cb0ef41Sopenharmony_ci Handle<JSReceiver> object = args.at<JSReceiver>(0); 7201cb0ef41Sopenharmony_ci 7211cb0ef41Sopenharmony_ci MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object), 7221cb0ef41Sopenharmony_ci kThrowOnError), 7231cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).exception()); 7241cb0ef41Sopenharmony_ci return *object; 7251cb0ef41Sopenharmony_ci} 7261cb0ef41Sopenharmony_ci 7271cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_JSReceiverPreventExtensionsDontThrow) { 7281cb0ef41Sopenharmony_ci HandleScope scope(isolate); 7291cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 7301cb0ef41Sopenharmony_ci Handle<JSReceiver> object = args.at<JSReceiver>(0); 7311cb0ef41Sopenharmony_ci 7321cb0ef41Sopenharmony_ci Maybe<bool> result = JSReceiver::PreventExtensions( 7331cb0ef41Sopenharmony_ci Handle<JSReceiver>::cast(object), kDontThrow); 7341cb0ef41Sopenharmony_ci MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); 7351cb0ef41Sopenharmony_ci return *isolate->factory()->ToBoolean(result.FromJust()); 7361cb0ef41Sopenharmony_ci} 7371cb0ef41Sopenharmony_ci 7381cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_JSReceiverGetPrototypeOf) { 7391cb0ef41Sopenharmony_ci HandleScope scope(isolate); 7401cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 7411cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = args.at<JSReceiver>(0); 7421cb0ef41Sopenharmony_ci 7431cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE(isolate, 7441cb0ef41Sopenharmony_ci JSReceiver::GetPrototype(isolate, receiver)); 7451cb0ef41Sopenharmony_ci} 7461cb0ef41Sopenharmony_ci 7471cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_JSReceiverSetPrototypeOfThrow) { 7481cb0ef41Sopenharmony_ci HandleScope scope(isolate); 7491cb0ef41Sopenharmony_ci 7501cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 7511cb0ef41Sopenharmony_ci Handle<JSReceiver> object = args.at<JSReceiver>(0); 7521cb0ef41Sopenharmony_ci Handle<Object> proto = args.at(1); 7531cb0ef41Sopenharmony_ci 7541cb0ef41Sopenharmony_ci MAYBE_RETURN( 7551cb0ef41Sopenharmony_ci JSReceiver::SetPrototype(isolate, object, proto, true, kThrowOnError), 7561cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).exception()); 7571cb0ef41Sopenharmony_ci 7581cb0ef41Sopenharmony_ci return *object; 7591cb0ef41Sopenharmony_ci} 7601cb0ef41Sopenharmony_ci 7611cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_JSReceiverSetPrototypeOfDontThrow) { 7621cb0ef41Sopenharmony_ci HandleScope scope(isolate); 7631cb0ef41Sopenharmony_ci 7641cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 7651cb0ef41Sopenharmony_ci Handle<JSReceiver> object = args.at<JSReceiver>(0); 7661cb0ef41Sopenharmony_ci Handle<Object> proto = args.at(1); 7671cb0ef41Sopenharmony_ci 7681cb0ef41Sopenharmony_ci Maybe<bool> result = 7691cb0ef41Sopenharmony_ci JSReceiver::SetPrototype(isolate, object, proto, true, kDontThrow); 7701cb0ef41Sopenharmony_ci MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); 7711cb0ef41Sopenharmony_ci return *isolate->factory()->ToBoolean(result.FromJust()); 7721cb0ef41Sopenharmony_ci} 7731cb0ef41Sopenharmony_ci 7741cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetProperty) { 7751cb0ef41Sopenharmony_ci HandleScope scope(isolate); 7761cb0ef41Sopenharmony_ci DCHECK(args.length() == 3 || args.length() == 2); 7771cb0ef41Sopenharmony_ci Handle<Object> lookup_start_obj = args.at(0); 7781cb0ef41Sopenharmony_ci Handle<Object> key_obj = args.at(1); 7791cb0ef41Sopenharmony_ci Handle<Object> receiver_obj = lookup_start_obj; 7801cb0ef41Sopenharmony_ci if (args.length() == 3) { 7811cb0ef41Sopenharmony_ci receiver_obj = args.at<Object>(2); 7821cb0ef41Sopenharmony_ci } 7831cb0ef41Sopenharmony_ci 7841cb0ef41Sopenharmony_ci // Fast cases for getting named properties of the lookup_start_obj JSObject 7851cb0ef41Sopenharmony_ci // itself. 7861cb0ef41Sopenharmony_ci // 7871cb0ef41Sopenharmony_ci // The global proxy objects has to be excluded since LookupOwn on 7881cb0ef41Sopenharmony_ci // the global proxy object can return a valid result even though the 7891cb0ef41Sopenharmony_ci // global proxy object never has properties. This is the case 7901cb0ef41Sopenharmony_ci // because the global proxy object forwards everything to its hidden 7911cb0ef41Sopenharmony_ci // prototype including own lookups. 7921cb0ef41Sopenharmony_ci // 7931cb0ef41Sopenharmony_ci // Additionally, we need to make sure that we do not cache results 7941cb0ef41Sopenharmony_ci // for objects that require access checks. 7951cb0ef41Sopenharmony_ci 7961cb0ef41Sopenharmony_ci // Convert string-index keys to their number variant to avoid internalization 7971cb0ef41Sopenharmony_ci // below; and speed up subsequent conversion to index. 7981cb0ef41Sopenharmony_ci uint32_t index; 7991cb0ef41Sopenharmony_ci if (key_obj->IsString() && String::cast(*key_obj).AsArrayIndex(&index)) { 8001cb0ef41Sopenharmony_ci key_obj = isolate->factory()->NewNumberFromUint(index); 8011cb0ef41Sopenharmony_ci } 8021cb0ef41Sopenharmony_ci if (lookup_start_obj->IsJSObject()) { 8031cb0ef41Sopenharmony_ci Handle<JSObject> lookup_start_object = 8041cb0ef41Sopenharmony_ci Handle<JSObject>::cast(lookup_start_obj); 8051cb0ef41Sopenharmony_ci if (!lookup_start_object->IsJSGlobalProxy() && 8061cb0ef41Sopenharmony_ci !lookup_start_object->IsAccessCheckNeeded() && key_obj->IsName()) { 8071cb0ef41Sopenharmony_ci Handle<Name> key = Handle<Name>::cast(key_obj); 8081cb0ef41Sopenharmony_ci key_obj = key = isolate->factory()->InternalizeName(key); 8091cb0ef41Sopenharmony_ci 8101cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 8111cb0ef41Sopenharmony_ci if (lookup_start_object->IsJSGlobalObject()) { 8121cb0ef41Sopenharmony_ci // Attempt dictionary lookup. 8131cb0ef41Sopenharmony_ci GlobalDictionary dictionary = JSGlobalObject::cast(*lookup_start_object) 8141cb0ef41Sopenharmony_ci .global_dictionary(kAcquireLoad); 8151cb0ef41Sopenharmony_ci InternalIndex entry = dictionary.FindEntry(isolate, key); 8161cb0ef41Sopenharmony_ci if (entry.is_found()) { 8171cb0ef41Sopenharmony_ci PropertyCell cell = dictionary.CellAt(entry); 8181cb0ef41Sopenharmony_ci if (cell.property_details().kind() == PropertyKind::kData) { 8191cb0ef41Sopenharmony_ci Object value = cell.value(); 8201cb0ef41Sopenharmony_ci if (!value.IsTheHole(isolate)) return value; 8211cb0ef41Sopenharmony_ci // If value is the hole (meaning, absent) do the general lookup. 8221cb0ef41Sopenharmony_ci } 8231cb0ef41Sopenharmony_ci } 8241cb0ef41Sopenharmony_ci } else if (!lookup_start_object->HasFastProperties()) { 8251cb0ef41Sopenharmony_ci // Attempt dictionary lookup. 8261cb0ef41Sopenharmony_ci if (V8_ENABLE_SWISS_NAME_DICTIONARY_BOOL) { 8271cb0ef41Sopenharmony_ci SwissNameDictionary dictionary = 8281cb0ef41Sopenharmony_ci lookup_start_object->property_dictionary_swiss(); 8291cb0ef41Sopenharmony_ci InternalIndex entry = dictionary.FindEntry(isolate, *key); 8301cb0ef41Sopenharmony_ci if (entry.is_found() && 8311cb0ef41Sopenharmony_ci (dictionary.DetailsAt(entry).kind() == PropertyKind::kData)) { 8321cb0ef41Sopenharmony_ci return dictionary.ValueAt(entry); 8331cb0ef41Sopenharmony_ci } 8341cb0ef41Sopenharmony_ci } else { 8351cb0ef41Sopenharmony_ci NameDictionary dictionary = 8361cb0ef41Sopenharmony_ci lookup_start_object->property_dictionary(); 8371cb0ef41Sopenharmony_ci InternalIndex entry = dictionary.FindEntry(isolate, key); 8381cb0ef41Sopenharmony_ci if ((entry.is_found()) && 8391cb0ef41Sopenharmony_ci (dictionary.DetailsAt(entry).kind() == PropertyKind::kData)) { 8401cb0ef41Sopenharmony_ci return dictionary.ValueAt(entry); 8411cb0ef41Sopenharmony_ci } 8421cb0ef41Sopenharmony_ci } 8431cb0ef41Sopenharmony_ci } 8441cb0ef41Sopenharmony_ci } else if (key_obj->IsSmi()) { 8451cb0ef41Sopenharmony_ci // JSObject without a name key. If the key is a Smi, check for a 8461cb0ef41Sopenharmony_ci // definite out-of-bounds access to elements, which is a strong indicator 8471cb0ef41Sopenharmony_ci // that subsequent accesses will also call the runtime. Proactively 8481cb0ef41Sopenharmony_ci // transition elements to FAST_*_ELEMENTS to avoid excessive boxing of 8491cb0ef41Sopenharmony_ci // doubles for those future calls in the case that the elements would 8501cb0ef41Sopenharmony_ci // become PACKED_DOUBLE_ELEMENTS. 8511cb0ef41Sopenharmony_ci ElementsKind elements_kind = lookup_start_object->GetElementsKind(); 8521cb0ef41Sopenharmony_ci if (IsDoubleElementsKind(elements_kind)) { 8531cb0ef41Sopenharmony_ci if (Smi::ToInt(*key_obj) >= lookup_start_object->elements().length()) { 8541cb0ef41Sopenharmony_ci elements_kind = IsHoleyElementsKind(elements_kind) ? HOLEY_ELEMENTS 8551cb0ef41Sopenharmony_ci : PACKED_ELEMENTS; 8561cb0ef41Sopenharmony_ci JSObject::TransitionElementsKind(lookup_start_object, elements_kind); 8571cb0ef41Sopenharmony_ci } 8581cb0ef41Sopenharmony_ci } else { 8591cb0ef41Sopenharmony_ci DCHECK(IsSmiOrObjectElementsKind(elements_kind) || 8601cb0ef41Sopenharmony_ci !IsFastElementsKind(elements_kind)); 8611cb0ef41Sopenharmony_ci } 8621cb0ef41Sopenharmony_ci } 8631cb0ef41Sopenharmony_ci } else if (lookup_start_obj->IsString() && key_obj->IsSmi()) { 8641cb0ef41Sopenharmony_ci // Fast case for string indexing using [] with a smi index. 8651cb0ef41Sopenharmony_ci Handle<String> str = Handle<String>::cast(lookup_start_obj); 8661cb0ef41Sopenharmony_ci int smi_index = Handle<Smi>::cast(key_obj)->value(); 8671cb0ef41Sopenharmony_ci if (smi_index >= 0 && smi_index < str->length()) { 8681cb0ef41Sopenharmony_ci Factory* factory = isolate->factory(); 8691cb0ef41Sopenharmony_ci return *factory->LookupSingleCharacterStringFromCode( 8701cb0ef41Sopenharmony_ci String::Flatten(isolate, str)->Get(smi_index)); 8711cb0ef41Sopenharmony_ci } 8721cb0ef41Sopenharmony_ci } 8731cb0ef41Sopenharmony_ci 8741cb0ef41Sopenharmony_ci // Fall back to GetObjectProperty. 8751cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE( 8761cb0ef41Sopenharmony_ci isolate, Runtime::GetObjectProperty(isolate, lookup_start_obj, key_obj, 8771cb0ef41Sopenharmony_ci receiver_obj)); 8781cb0ef41Sopenharmony_ci} 8791cb0ef41Sopenharmony_ci 8801cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SetKeyedProperty) { 8811cb0ef41Sopenharmony_ci HandleScope scope(isolate); 8821cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 8831cb0ef41Sopenharmony_ci 8841cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 8851cb0ef41Sopenharmony_ci Handle<Object> key = args.at(1); 8861cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 8871cb0ef41Sopenharmony_ci 8881cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE( 8891cb0ef41Sopenharmony_ci isolate, Runtime::SetObjectProperty(isolate, object, key, value, 8901cb0ef41Sopenharmony_ci StoreOrigin::kMaybeKeyed)); 8911cb0ef41Sopenharmony_ci} 8921cb0ef41Sopenharmony_ci 8931cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DefineObjectOwnProperty) { 8941cb0ef41Sopenharmony_ci HandleScope scope(isolate); 8951cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 8961cb0ef41Sopenharmony_ci 8971cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 8981cb0ef41Sopenharmony_ci Handle<Object> key = args.at(1); 8991cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 9001cb0ef41Sopenharmony_ci 9011cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE( 9021cb0ef41Sopenharmony_ci isolate, Runtime::DefineObjectOwnProperty(isolate, object, key, value, 9031cb0ef41Sopenharmony_ci StoreOrigin::kMaybeKeyed)); 9041cb0ef41Sopenharmony_ci} 9051cb0ef41Sopenharmony_ci 9061cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SetNamedProperty) { 9071cb0ef41Sopenharmony_ci HandleScope scope(isolate); 9081cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 9091cb0ef41Sopenharmony_ci 9101cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 9111cb0ef41Sopenharmony_ci Handle<Object> key = args.at(1); 9121cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 9131cb0ef41Sopenharmony_ci 9141cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE( 9151cb0ef41Sopenharmony_ci isolate, Runtime::SetObjectProperty(isolate, object, key, value, 9161cb0ef41Sopenharmony_ci StoreOrigin::kNamed)); 9171cb0ef41Sopenharmony_ci} 9181cb0ef41Sopenharmony_ci 9191cb0ef41Sopenharmony_ci// Similar to DefineKeyedOwnPropertyInLiteral, but does not update feedback, and 9201cb0ef41Sopenharmony_ci// and does not have a flags parameter for performing SetFunctionName(). 9211cb0ef41Sopenharmony_ci// 9221cb0ef41Sopenharmony_ci// Currently, this is used for ObjectLiteral spread properties in CloneObjectIC 9231cb0ef41Sopenharmony_ci// and for array literal creations in StoreInArrayLiteralIC. 9241cb0ef41Sopenharmony_ci// TODO(v8:12548): merge this into DefineKeyedOwnPropertyInLiteral. 9251cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DefineKeyedOwnPropertyInLiteral_Simple) { 9261cb0ef41Sopenharmony_ci HandleScope scope(isolate); 9271cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 9281cb0ef41Sopenharmony_ci 9291cb0ef41Sopenharmony_ci Handle<JSReceiver> object = args.at<JSReceiver>(0); 9301cb0ef41Sopenharmony_ci Handle<Object> key = args.at(1); 9311cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 9321cb0ef41Sopenharmony_ci 9331cb0ef41Sopenharmony_ci PropertyKey lookup_key(isolate, key); 9341cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, lookup_key, LookupIterator::OWN); 9351cb0ef41Sopenharmony_ci 9361cb0ef41Sopenharmony_ci Maybe<bool> result = JSObject::DefineOwnPropertyIgnoreAttributes( 9371cb0ef41Sopenharmony_ci &it, value, NONE, Just(kDontThrow)); 9381cb0ef41Sopenharmony_ci RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); 9391cb0ef41Sopenharmony_ci DCHECK(result.IsJust()); 9401cb0ef41Sopenharmony_ci USE(result); 9411cb0ef41Sopenharmony_ci 9421cb0ef41Sopenharmony_ci return *value; 9431cb0ef41Sopenharmony_ci} 9441cb0ef41Sopenharmony_ci 9451cb0ef41Sopenharmony_cinamespace { 9461cb0ef41Sopenharmony_ci 9471cb0ef41Sopenharmony_ci// ES6 section 12.5.4. 9481cb0ef41Sopenharmony_ciObject DeleteProperty(Isolate* isolate, Handle<Object> object, 9491cb0ef41Sopenharmony_ci Handle<Object> key, LanguageMode language_mode) { 9501cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver; 9511cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 9521cb0ef41Sopenharmony_ci Object::ToObject(isolate, object)); 9531cb0ef41Sopenharmony_ci Maybe<bool> result = 9541cb0ef41Sopenharmony_ci Runtime::DeleteObjectProperty(isolate, receiver, key, language_mode); 9551cb0ef41Sopenharmony_ci MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); 9561cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(result.FromJust()); 9571cb0ef41Sopenharmony_ci} 9581cb0ef41Sopenharmony_ci 9591cb0ef41Sopenharmony_ci} // namespace 9601cb0ef41Sopenharmony_ci 9611cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DeleteProperty) { 9621cb0ef41Sopenharmony_ci HandleScope scope(isolate); 9631cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 9641cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 9651cb0ef41Sopenharmony_ci Handle<Object> key = args.at(1); 9661cb0ef41Sopenharmony_ci int language_mode = args.smi_value_at(2); 9671cb0ef41Sopenharmony_ci return DeleteProperty(isolate, object, key, 9681cb0ef41Sopenharmony_ci static_cast<LanguageMode>(language_mode)); 9691cb0ef41Sopenharmony_ci} 9701cb0ef41Sopenharmony_ci 9711cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ShrinkNameDictionary) { 9721cb0ef41Sopenharmony_ci HandleScope scope(isolate); 9731cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 9741cb0ef41Sopenharmony_ci Handle<NameDictionary> dictionary = args.at<NameDictionary>(0); 9751cb0ef41Sopenharmony_ci 9761cb0ef41Sopenharmony_ci return *NameDictionary::Shrink(isolate, dictionary); 9771cb0ef41Sopenharmony_ci} 9781cb0ef41Sopenharmony_ci 9791cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ShrinkSwissNameDictionary) { 9801cb0ef41Sopenharmony_ci HandleScope scope(isolate); 9811cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 9821cb0ef41Sopenharmony_ci Handle<SwissNameDictionary> dictionary = args.at<SwissNameDictionary>(0); 9831cb0ef41Sopenharmony_ci 9841cb0ef41Sopenharmony_ci return *SwissNameDictionary::Shrink(isolate, dictionary); 9851cb0ef41Sopenharmony_ci} 9861cb0ef41Sopenharmony_ci 9871cb0ef41Sopenharmony_ci// ES6 section 12.9.3, operator in. 9881cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_HasProperty) { 9891cb0ef41Sopenharmony_ci HandleScope scope(isolate); 9901cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 9911cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 9921cb0ef41Sopenharmony_ci Handle<Object> key = args.at(1); 9931cb0ef41Sopenharmony_ci 9941cb0ef41Sopenharmony_ci // Check that {object} is actually a receiver. 9951cb0ef41Sopenharmony_ci if (!object->IsJSReceiver()) { 9961cb0ef41Sopenharmony_ci THROW_NEW_ERROR_RETURN_FAILURE( 9971cb0ef41Sopenharmony_ci isolate, 9981cb0ef41Sopenharmony_ci NewTypeError(MessageTemplate::kInvalidInOperatorUse, key, object)); 9991cb0ef41Sopenharmony_ci } 10001cb0ef41Sopenharmony_ci Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); 10011cb0ef41Sopenharmony_ci 10021cb0ef41Sopenharmony_ci // Convert the {key} to a name. 10031cb0ef41Sopenharmony_ci Handle<Name> name; 10041cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, 10051cb0ef41Sopenharmony_ci Object::ToName(isolate, key)); 10061cb0ef41Sopenharmony_ci 10071cb0ef41Sopenharmony_ci // Lookup the {name} on {receiver}. 10081cb0ef41Sopenharmony_ci Maybe<bool> maybe = JSReceiver::HasProperty(isolate, receiver, name); 10091cb0ef41Sopenharmony_ci if (maybe.IsNothing()) return ReadOnlyRoots(isolate).exception(); 10101cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(maybe.FromJust()); 10111cb0ef41Sopenharmony_ci} 10121cb0ef41Sopenharmony_ci 10131cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetOwnPropertyKeys) { 10141cb0ef41Sopenharmony_ci HandleScope scope(isolate); 10151cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 10161cb0ef41Sopenharmony_ci Handle<JSReceiver> object = args.at<JSReceiver>(0); 10171cb0ef41Sopenharmony_ci int filter_value = args.smi_value_at(1); 10181cb0ef41Sopenharmony_ci PropertyFilter filter = static_cast<PropertyFilter>(filter_value); 10191cb0ef41Sopenharmony_ci 10201cb0ef41Sopenharmony_ci Handle<FixedArray> keys; 10211cb0ef41Sopenharmony_ci ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 10221cb0ef41Sopenharmony_ci isolate, keys, 10231cb0ef41Sopenharmony_ci KeyAccumulator::GetKeys(object, KeyCollectionMode::kOwnOnly, filter, 10241cb0ef41Sopenharmony_ci GetKeysConversion::kConvertToString)); 10251cb0ef41Sopenharmony_ci 10261cb0ef41Sopenharmony_ci return *isolate->factory()->NewJSArrayWithElements(keys); 10271cb0ef41Sopenharmony_ci} 10281cb0ef41Sopenharmony_ci 10291cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ToFastProperties) { 10301cb0ef41Sopenharmony_ci HandleScope scope(isolate); 10311cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 10321cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 10331cb0ef41Sopenharmony_ci if (object->IsJSObject() && !object->IsJSGlobalObject()) { 10341cb0ef41Sopenharmony_ci JSObject::MigrateSlowToFast(Handle<JSObject>::cast(object), 0, 10351cb0ef41Sopenharmony_ci "RuntimeToFastProperties"); 10361cb0ef41Sopenharmony_ci } 10371cb0ef41Sopenharmony_ci return *object; 10381cb0ef41Sopenharmony_ci} 10391cb0ef41Sopenharmony_ci 10401cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_AllocateHeapNumber) { 10411cb0ef41Sopenharmony_ci HandleScope scope(isolate); 10421cb0ef41Sopenharmony_ci DCHECK_EQ(0, args.length()); 10431cb0ef41Sopenharmony_ci return *isolate->factory()->NewHeapNumber(0); 10441cb0ef41Sopenharmony_ci} 10451cb0ef41Sopenharmony_ci 10461cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_NewObject) { 10471cb0ef41Sopenharmony_ci HandleScope scope(isolate); 10481cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 10491cb0ef41Sopenharmony_ci Handle<JSFunction> target = args.at<JSFunction>(0); 10501cb0ef41Sopenharmony_ci Handle<JSReceiver> new_target = args.at<JSReceiver>(1); 10511cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE( 10521cb0ef41Sopenharmony_ci isolate, 10531cb0ef41Sopenharmony_ci JSObject::New(target, new_target, Handle<AllocationSite>::null())); 10541cb0ef41Sopenharmony_ci} 10551cb0ef41Sopenharmony_ci 10561cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetDerivedMap) { 10571cb0ef41Sopenharmony_ci HandleScope scope(isolate); 10581cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 10591cb0ef41Sopenharmony_ci Handle<JSFunction> target = args.at<JSFunction>(0); 10601cb0ef41Sopenharmony_ci Handle<JSReceiver> new_target = args.at<JSReceiver>(1); 10611cb0ef41Sopenharmony_ci Handle<Object> rab_gsab = args.at(2); 10621cb0ef41Sopenharmony_ci if (rab_gsab->IsTrue()) { 10631cb0ef41Sopenharmony_ci return *JSFunction::GetDerivedRabGsabMap(isolate, target, new_target); 10641cb0ef41Sopenharmony_ci } else { 10651cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE( 10661cb0ef41Sopenharmony_ci isolate, JSFunction::GetDerivedMap(isolate, target, new_target)); 10671cb0ef41Sopenharmony_ci } 10681cb0ef41Sopenharmony_ci} 10691cb0ef41Sopenharmony_ci 10701cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CompleteInobjectSlackTrackingForMap) { 10711cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 10721cb0ef41Sopenharmony_ci HandleScope scope(isolate); 10731cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 10741cb0ef41Sopenharmony_ci 10751cb0ef41Sopenharmony_ci Handle<Map> initial_map = args.at<Map>(0); 10761cb0ef41Sopenharmony_ci MapUpdater::CompleteInobjectSlackTracking(isolate, *initial_map); 10771cb0ef41Sopenharmony_ci 10781cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 10791cb0ef41Sopenharmony_ci} 10801cb0ef41Sopenharmony_ci 10811cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_TryMigrateInstance) { 10821cb0ef41Sopenharmony_ci HandleScope scope(isolate); 10831cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 10841cb0ef41Sopenharmony_ci Handle<JSObject> js_object = args.at<JSObject>(0); 10851cb0ef41Sopenharmony_ci // It could have been a DCHECK but we call this function directly from tests. 10861cb0ef41Sopenharmony_ci if (!js_object->map().is_deprecated()) return Smi::zero(); 10871cb0ef41Sopenharmony_ci // This call must not cause lazy deopts, because it's called from deferred 10881cb0ef41Sopenharmony_ci // code where we can't handle lazy deopts for lack of a suitable bailout 10891cb0ef41Sopenharmony_ci // ID. So we just try migration and signal failure if necessary, 10901cb0ef41Sopenharmony_ci // which will also trigger a deopt. 10911cb0ef41Sopenharmony_ci if (!JSObject::TryMigrateInstance(isolate, js_object)) return Smi::zero(); 10921cb0ef41Sopenharmony_ci return *js_object; 10931cb0ef41Sopenharmony_ci} 10941cb0ef41Sopenharmony_ci 10951cb0ef41Sopenharmony_cistatic bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) { 10961cb0ef41Sopenharmony_ci return obj->IsNullOrUndefined(isolate) || obj->IsCallable(); 10971cb0ef41Sopenharmony_ci} 10981cb0ef41Sopenharmony_ci 10991cb0ef41Sopenharmony_ci// Implements part of 8.12.9 DefineOwnProperty. 11001cb0ef41Sopenharmony_ci// There are 3 cases that lead here: 11011cb0ef41Sopenharmony_ci// Step 4b - define a new accessor property. 11021cb0ef41Sopenharmony_ci// Steps 9c & 12 - replace an existing data property with an accessor property. 11031cb0ef41Sopenharmony_ci// Step 12 - update an existing accessor property with an accessor or generic 11041cb0ef41Sopenharmony_ci// descriptor. 11051cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { 11061cb0ef41Sopenharmony_ci HandleScope scope(isolate); 11071cb0ef41Sopenharmony_ci DCHECK_EQ(5, args.length()); 11081cb0ef41Sopenharmony_ci Handle<JSObject> obj = args.at<JSObject>(0); 11091cb0ef41Sopenharmony_ci CHECK(!obj->IsNull(isolate)); 11101cb0ef41Sopenharmony_ci Handle<Name> name = args.at<Name>(1); 11111cb0ef41Sopenharmony_ci Handle<Object> getter = args.at(2); 11121cb0ef41Sopenharmony_ci CHECK(IsValidAccessor(isolate, getter)); 11131cb0ef41Sopenharmony_ci Handle<Object> setter = args.at(3); 11141cb0ef41Sopenharmony_ci CHECK(IsValidAccessor(isolate, setter)); 11151cb0ef41Sopenharmony_ci auto attrs = PropertyAttributesFromInt(args.smi_value_at(4)); 11161cb0ef41Sopenharmony_ci 11171cb0ef41Sopenharmony_ci RETURN_FAILURE_ON_EXCEPTION( 11181cb0ef41Sopenharmony_ci isolate, JSObject::DefineAccessor(obj, name, getter, setter, attrs)); 11191cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 11201cb0ef41Sopenharmony_ci} 11211cb0ef41Sopenharmony_ci 11221cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DefineKeyedOwnPropertyInLiteral) { 11231cb0ef41Sopenharmony_ci HandleScope scope(isolate); 11241cb0ef41Sopenharmony_ci DCHECK_EQ(6, args.length()); 11251cb0ef41Sopenharmony_ci Handle<JSObject> object = args.at<JSObject>(0); 11261cb0ef41Sopenharmony_ci Handle<Name> name = args.at<Name>(1); 11271cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 11281cb0ef41Sopenharmony_ci int flag = args.smi_value_at(3); 11291cb0ef41Sopenharmony_ci Handle<HeapObject> maybe_vector = args.at<HeapObject>(4); 11301cb0ef41Sopenharmony_ci int index = args.tagged_index_value_at(5); 11311cb0ef41Sopenharmony_ci 11321cb0ef41Sopenharmony_ci if (!maybe_vector->IsUndefined()) { 11331cb0ef41Sopenharmony_ci DCHECK(maybe_vector->IsFeedbackVector()); 11341cb0ef41Sopenharmony_ci Handle<FeedbackVector> vector = Handle<FeedbackVector>::cast(maybe_vector); 11351cb0ef41Sopenharmony_ci FeedbackNexus nexus(vector, FeedbackVector::ToSlot(index)); 11361cb0ef41Sopenharmony_ci if (nexus.ic_state() == InlineCacheState::UNINITIALIZED) { 11371cb0ef41Sopenharmony_ci if (name->IsUniqueName()) { 11381cb0ef41Sopenharmony_ci nexus.ConfigureMonomorphic(name, handle(object->map(), isolate), 11391cb0ef41Sopenharmony_ci MaybeObjectHandle()); 11401cb0ef41Sopenharmony_ci } else { 11411cb0ef41Sopenharmony_ci nexus.ConfigureMegamorphic(IcCheckType::kProperty); 11421cb0ef41Sopenharmony_ci } 11431cb0ef41Sopenharmony_ci } else if (nexus.ic_state() == InlineCacheState::MONOMORPHIC) { 11441cb0ef41Sopenharmony_ci if (nexus.GetFirstMap() != object->map() || nexus.GetName() != *name) { 11451cb0ef41Sopenharmony_ci nexus.ConfigureMegamorphic(IcCheckType::kProperty); 11461cb0ef41Sopenharmony_ci } 11471cb0ef41Sopenharmony_ci } 11481cb0ef41Sopenharmony_ci } 11491cb0ef41Sopenharmony_ci 11501cb0ef41Sopenharmony_ci DefineKeyedOwnPropertyInLiteralFlags flags(flag); 11511cb0ef41Sopenharmony_ci PropertyAttributes attrs = 11521cb0ef41Sopenharmony_ci (flags & DefineKeyedOwnPropertyInLiteralFlag::kDontEnum) 11531cb0ef41Sopenharmony_ci ? PropertyAttributes::DONT_ENUM 11541cb0ef41Sopenharmony_ci : PropertyAttributes::NONE; 11551cb0ef41Sopenharmony_ci 11561cb0ef41Sopenharmony_ci if (flags & DefineKeyedOwnPropertyInLiteralFlag::kSetFunctionName) { 11571cb0ef41Sopenharmony_ci DCHECK(value->IsJSFunction()); 11581cb0ef41Sopenharmony_ci Handle<JSFunction> function = Handle<JSFunction>::cast(value); 11591cb0ef41Sopenharmony_ci DCHECK(!function->shared().HasSharedName()); 11601cb0ef41Sopenharmony_ci Handle<Map> function_map(function->map(), isolate); 11611cb0ef41Sopenharmony_ci if (!JSFunction::SetName(function, name, 11621cb0ef41Sopenharmony_ci isolate->factory()->empty_string())) { 11631cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).exception(); 11641cb0ef41Sopenharmony_ci } 11651cb0ef41Sopenharmony_ci // Class constructors do not reserve in-object space for name field. 11661cb0ef41Sopenharmony_ci CHECK_IMPLIES(!IsClassConstructor(function->shared().kind()), 11671cb0ef41Sopenharmony_ci *function_map == function->map()); 11681cb0ef41Sopenharmony_ci } 11691cb0ef41Sopenharmony_ci 11701cb0ef41Sopenharmony_ci PropertyKey key(isolate, name); 11711cb0ef41Sopenharmony_ci LookupIterator it(isolate, object, key, object, LookupIterator::OWN); 11721cb0ef41Sopenharmony_ci // Cannot fail since this should only be called when 11731cb0ef41Sopenharmony_ci // creating an object literal. 11741cb0ef41Sopenharmony_ci CHECK(JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attrs, 11751cb0ef41Sopenharmony_ci Just(kDontThrow)) 11761cb0ef41Sopenharmony_ci .IsJust()); 11771cb0ef41Sopenharmony_ci 11781cb0ef41Sopenharmony_ci // Return the value so that 11791cb0ef41Sopenharmony_ci // BaselineCompiler::VisitDefineKeyedOwnPropertyInLiteral doesn't have to 11801cb0ef41Sopenharmony_ci // save the accumulator. 11811cb0ef41Sopenharmony_ci return *value; 11821cb0ef41Sopenharmony_ci} 11831cb0ef41Sopenharmony_ci 11841cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CollectTypeProfile) { 11851cb0ef41Sopenharmony_ci HandleScope scope(isolate); 11861cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 11871cb0ef41Sopenharmony_ci int position = args.smi_value_at(0); 11881cb0ef41Sopenharmony_ci Handle<Object> value = args.at(1); 11891cb0ef41Sopenharmony_ci Handle<HeapObject> maybe_vector = args.at<HeapObject>(2); 11901cb0ef41Sopenharmony_ci 11911cb0ef41Sopenharmony_ci if (maybe_vector->IsUndefined()) { 11921cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 11931cb0ef41Sopenharmony_ci } 11941cb0ef41Sopenharmony_ci Handle<FeedbackVector> vector = args.at<FeedbackVector>(2); 11951cb0ef41Sopenharmony_ci 11961cb0ef41Sopenharmony_ci Handle<String> type = Object::TypeOf(isolate, value); 11971cb0ef41Sopenharmony_ci if (value->IsJSReceiver()) { 11981cb0ef41Sopenharmony_ci Handle<JSReceiver> object = Handle<JSReceiver>::cast(value); 11991cb0ef41Sopenharmony_ci type = JSReceiver::GetConstructorName(isolate, object); 12001cb0ef41Sopenharmony_ci } else if (value->IsNull(isolate)) { 12011cb0ef41Sopenharmony_ci // typeof(null) is object. But it's more user-friendly to annotate 12021cb0ef41Sopenharmony_ci // null as type "null". 12031cb0ef41Sopenharmony_ci type = Handle<String>(ReadOnlyRoots(isolate).null_string(), isolate); 12041cb0ef41Sopenharmony_ci } 12051cb0ef41Sopenharmony_ci 12061cb0ef41Sopenharmony_ci DCHECK(vector->metadata().HasTypeProfileSlot()); 12071cb0ef41Sopenharmony_ci FeedbackNexus nexus(vector, vector->GetTypeProfileSlot()); 12081cb0ef41Sopenharmony_ci nexus.Collect(type, position); 12091cb0ef41Sopenharmony_ci 12101cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 12111cb0ef41Sopenharmony_ci} 12121cb0ef41Sopenharmony_ci 12131cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_HasFastPackedElements) { 12141cb0ef41Sopenharmony_ci SealHandleScope shs(isolate); 12151cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 12161cb0ef41Sopenharmony_ci auto obj = HeapObject::cast(args[0]); 12171cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean( 12181cb0ef41Sopenharmony_ci IsFastPackedElementsKind(obj.map().elements_kind())); 12191cb0ef41Sopenharmony_ci} 12201cb0ef41Sopenharmony_ci 12211cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_IsJSReceiver) { 12221cb0ef41Sopenharmony_ci SealHandleScope shs(isolate); 12231cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 12241cb0ef41Sopenharmony_ci Object obj = args[0]; 12251cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(obj.IsJSReceiver()); 12261cb0ef41Sopenharmony_ci} 12271cb0ef41Sopenharmony_ci 12281cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetFunctionName) { 12291cb0ef41Sopenharmony_ci HandleScope scope(isolate); 12301cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 12311cb0ef41Sopenharmony_ci Handle<JSFunction> function = args.at<JSFunction>(0); 12321cb0ef41Sopenharmony_ci return *JSFunction::GetName(isolate, function); 12331cb0ef41Sopenharmony_ci} 12341cb0ef41Sopenharmony_ci 12351cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DefineGetterPropertyUnchecked) { 12361cb0ef41Sopenharmony_ci HandleScope scope(isolate); 12371cb0ef41Sopenharmony_ci DCHECK_EQ(4, args.length()); 12381cb0ef41Sopenharmony_ci Handle<JSObject> object = args.at<JSObject>(0); 12391cb0ef41Sopenharmony_ci Handle<Name> name = args.at<Name>(1); 12401cb0ef41Sopenharmony_ci Handle<JSFunction> getter = args.at<JSFunction>(2); 12411cb0ef41Sopenharmony_ci auto attrs = PropertyAttributesFromInt(args.smi_value_at(3)); 12421cb0ef41Sopenharmony_ci 12431cb0ef41Sopenharmony_ci if (String::cast(getter->shared().Name()).length() == 0) { 12441cb0ef41Sopenharmony_ci Handle<Map> getter_map(getter->map(), isolate); 12451cb0ef41Sopenharmony_ci if (!JSFunction::SetName(getter, name, isolate->factory()->get_string())) { 12461cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).exception(); 12471cb0ef41Sopenharmony_ci } 12481cb0ef41Sopenharmony_ci CHECK_EQ(*getter_map, getter->map()); 12491cb0ef41Sopenharmony_ci } 12501cb0ef41Sopenharmony_ci 12511cb0ef41Sopenharmony_ci RETURN_FAILURE_ON_EXCEPTION( 12521cb0ef41Sopenharmony_ci isolate, 12531cb0ef41Sopenharmony_ci JSObject::DefineAccessor(object, name, getter, 12541cb0ef41Sopenharmony_ci isolate->factory()->null_value(), attrs)); 12551cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 12561cb0ef41Sopenharmony_ci} 12571cb0ef41Sopenharmony_ci 12581cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SetDataProperties) { 12591cb0ef41Sopenharmony_ci HandleScope scope(isolate); 12601cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 12611cb0ef41Sopenharmony_ci Handle<JSReceiver> target = args.at<JSReceiver>(0); 12621cb0ef41Sopenharmony_ci Handle<Object> source = args.at(1); 12631cb0ef41Sopenharmony_ci 12641cb0ef41Sopenharmony_ci // 2. If source is undefined or null, let keys be an empty List. 12651cb0ef41Sopenharmony_ci if (source->IsUndefined(isolate) || source->IsNull(isolate)) { 12661cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 12671cb0ef41Sopenharmony_ci } 12681cb0ef41Sopenharmony_ci 12691cb0ef41Sopenharmony_ci MAYBE_RETURN(JSReceiver::SetOrCopyDataProperties( 12701cb0ef41Sopenharmony_ci isolate, target, source, 12711cb0ef41Sopenharmony_ci PropertiesEnumerationMode::kEnumerationOrder), 12721cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).exception()); 12731cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 12741cb0ef41Sopenharmony_ci} 12751cb0ef41Sopenharmony_ci 12761cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CopyDataProperties) { 12771cb0ef41Sopenharmony_ci HandleScope scope(isolate); 12781cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 12791cb0ef41Sopenharmony_ci Handle<JSObject> target = args.at<JSObject>(0); 12801cb0ef41Sopenharmony_ci Handle<Object> source = args.at(1); 12811cb0ef41Sopenharmony_ci 12821cb0ef41Sopenharmony_ci // 2. If source is undefined or null, let keys be an empty List. 12831cb0ef41Sopenharmony_ci if (source->IsUndefined(isolate) || source->IsNull(isolate)) { 12841cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 12851cb0ef41Sopenharmony_ci } 12861cb0ef41Sopenharmony_ci 12871cb0ef41Sopenharmony_ci MAYBE_RETURN( 12881cb0ef41Sopenharmony_ci JSReceiver::SetOrCopyDataProperties( 12891cb0ef41Sopenharmony_ci isolate, target, source, 12901cb0ef41Sopenharmony_ci PropertiesEnumerationMode::kPropertyAdditionOrder, nullptr, false), 12911cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).exception()); 12921cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 12931cb0ef41Sopenharmony_ci} 12941cb0ef41Sopenharmony_ci 12951cb0ef41Sopenharmony_cinamespace { 12961cb0ef41Sopenharmony_ci 12971cb0ef41Sopenharmony_ci// Check that the excluded properties are within the stack range of the top of 12981cb0ef41Sopenharmony_ci// the stack, and the start of the JS frame. 12991cb0ef41Sopenharmony_civoid CheckExcludedPropertiesAreOnCallerStack(Isolate* isolate, Address base, 13001cb0ef41Sopenharmony_ci int count) { 13011cb0ef41Sopenharmony_ci#ifdef DEBUG 13021cb0ef41Sopenharmony_ci StackFrameIterator it(isolate); 13031cb0ef41Sopenharmony_ci 13041cb0ef41Sopenharmony_ci // Don't need to check when there's no excluded properties. 13051cb0ef41Sopenharmony_ci if (count == 0) return; 13061cb0ef41Sopenharmony_ci 13071cb0ef41Sopenharmony_ci DCHECK(!it.done()); 13081cb0ef41Sopenharmony_ci 13091cb0ef41Sopenharmony_ci // Properties are pass in order on the stack, which means that their addresses 13101cb0ef41Sopenharmony_ci // are in reverse order in memory (because stacks grow backwards). So, we 13111cb0ef41Sopenharmony_ci // need to check if the _last_ property address is before the stack end... 13121cb0ef41Sopenharmony_ci Address last_property = base - (count - 1) * kSystemPointerSize; 13131cb0ef41Sopenharmony_ci DCHECK_GE(last_property, it.frame()->sp()); 13141cb0ef41Sopenharmony_ci 13151cb0ef41Sopenharmony_ci // ... and for the first JS frame, make sure the _first_ property address is 13161cb0ef41Sopenharmony_ci // after that stack frame's start. 13171cb0ef41Sopenharmony_ci for (; !it.done(); it.Advance()) { 13181cb0ef41Sopenharmony_ci if (it.frame()->is_java_script()) { 13191cb0ef41Sopenharmony_ci DCHECK_LT(base, it.frame()->fp()); 13201cb0ef41Sopenharmony_ci return; 13211cb0ef41Sopenharmony_ci } 13221cb0ef41Sopenharmony_ci } 13231cb0ef41Sopenharmony_ci 13241cb0ef41Sopenharmony_ci // We should always find a JS frame. 13251cb0ef41Sopenharmony_ci UNREACHABLE(); 13261cb0ef41Sopenharmony_ci#endif 13271cb0ef41Sopenharmony_ci} 13281cb0ef41Sopenharmony_ci 13291cb0ef41Sopenharmony_ci} // namespace 13301cb0ef41Sopenharmony_ci 13311cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CopyDataPropertiesWithExcludedPropertiesOnStack) { 13321cb0ef41Sopenharmony_ci HandleScope scope(isolate); 13331cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 13341cb0ef41Sopenharmony_ci Handle<Object> source = args.at(0); 13351cb0ef41Sopenharmony_ci int excluded_property_count = args.smi_value_at(1); 13361cb0ef41Sopenharmony_ci // The excluded_property_base is passed as a raw stack pointer. This is safe 13371cb0ef41Sopenharmony_ci // because the stack pointer is aligned, so it looks like a Smi to the GC. 13381cb0ef41Sopenharmony_ci Address* excluded_property_base = reinterpret_cast<Address*>(args[2].ptr()); 13391cb0ef41Sopenharmony_ci DCHECK(HAS_SMI_TAG(reinterpret_cast<intptr_t>(excluded_property_base))); 13401cb0ef41Sopenharmony_ci // Also make sure that the given base pointer points to to on-stack values. 13411cb0ef41Sopenharmony_ci CheckExcludedPropertiesAreOnCallerStack( 13421cb0ef41Sopenharmony_ci isolate, reinterpret_cast<Address>(excluded_property_base), 13431cb0ef41Sopenharmony_ci excluded_property_count); 13441cb0ef41Sopenharmony_ci 13451cb0ef41Sopenharmony_ci // If source is undefined or null, throw a non-coercible error. 13461cb0ef41Sopenharmony_ci if (source->IsNullOrUndefined(isolate)) { 13471cb0ef41Sopenharmony_ci return ErrorUtils::ThrowLoadFromNullOrUndefined(isolate, source, 13481cb0ef41Sopenharmony_ci MaybeHandle<Object>()); 13491cb0ef41Sopenharmony_ci } 13501cb0ef41Sopenharmony_ci 13511cb0ef41Sopenharmony_ci base::ScopedVector<Handle<Object>> excluded_properties( 13521cb0ef41Sopenharmony_ci excluded_property_count); 13531cb0ef41Sopenharmony_ci for (int i = 0; i < excluded_property_count; i++) { 13541cb0ef41Sopenharmony_ci // Because the excluded properties on stack is from high address 13551cb0ef41Sopenharmony_ci // to low address, so we need to use sub 13561cb0ef41Sopenharmony_ci Handle<Object> property(excluded_property_base - i); 13571cb0ef41Sopenharmony_ci uint32_t property_num; 13581cb0ef41Sopenharmony_ci // We convert string to number if possible, in cases of computed 13591cb0ef41Sopenharmony_ci // properties resolving to numbers, which would've been strings 13601cb0ef41Sopenharmony_ci // instead because of our call to %ToName() in the desugaring for 13611cb0ef41Sopenharmony_ci // computed properties. 13621cb0ef41Sopenharmony_ci if (property->IsString() && 13631cb0ef41Sopenharmony_ci String::cast(*property).AsArrayIndex(&property_num)) { 13641cb0ef41Sopenharmony_ci property = isolate->factory()->NewNumberFromUint(property_num); 13651cb0ef41Sopenharmony_ci } 13661cb0ef41Sopenharmony_ci 13671cb0ef41Sopenharmony_ci excluded_properties[i] = property; 13681cb0ef41Sopenharmony_ci } 13691cb0ef41Sopenharmony_ci 13701cb0ef41Sopenharmony_ci Handle<JSObject> target = 13711cb0ef41Sopenharmony_ci isolate->factory()->NewJSObject(isolate->object_function()); 13721cb0ef41Sopenharmony_ci MAYBE_RETURN(JSReceiver::SetOrCopyDataProperties( 13731cb0ef41Sopenharmony_ci isolate, target, source, 13741cb0ef41Sopenharmony_ci PropertiesEnumerationMode::kPropertyAdditionOrder, 13751cb0ef41Sopenharmony_ci &excluded_properties, false), 13761cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).exception()); 13771cb0ef41Sopenharmony_ci return *target; 13781cb0ef41Sopenharmony_ci} 13791cb0ef41Sopenharmony_ci 13801cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) { 13811cb0ef41Sopenharmony_ci HandleScope scope(isolate); 13821cb0ef41Sopenharmony_ci DCHECK_EQ(4, args.length()); 13831cb0ef41Sopenharmony_ci Handle<JSObject> object = args.at<JSObject>(0); 13841cb0ef41Sopenharmony_ci Handle<Name> name = args.at<Name>(1); 13851cb0ef41Sopenharmony_ci Handle<JSFunction> setter = args.at<JSFunction>(2); 13861cb0ef41Sopenharmony_ci auto attrs = PropertyAttributesFromInt(args.smi_value_at(3)); 13871cb0ef41Sopenharmony_ci 13881cb0ef41Sopenharmony_ci if (String::cast(setter->shared().Name()).length() == 0) { 13891cb0ef41Sopenharmony_ci Handle<Map> setter_map(setter->map(), isolate); 13901cb0ef41Sopenharmony_ci if (!JSFunction::SetName(setter, name, isolate->factory()->set_string())) { 13911cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).exception(); 13921cb0ef41Sopenharmony_ci } 13931cb0ef41Sopenharmony_ci CHECK_EQ(*setter_map, setter->map()); 13941cb0ef41Sopenharmony_ci } 13951cb0ef41Sopenharmony_ci 13961cb0ef41Sopenharmony_ci RETURN_FAILURE_ON_EXCEPTION( 13971cb0ef41Sopenharmony_ci isolate, 13981cb0ef41Sopenharmony_ci JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), 13991cb0ef41Sopenharmony_ci setter, attrs)); 14001cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 14011cb0ef41Sopenharmony_ci} 14021cb0ef41Sopenharmony_ci 14031cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ToObject) { 14041cb0ef41Sopenharmony_ci // Runtime call is implemented in InterpreterIntrinsics and lowered in 14051cb0ef41Sopenharmony_ci // JSIntrinsicLowering. 14061cb0ef41Sopenharmony_ci UNREACHABLE(); 14071cb0ef41Sopenharmony_ci} 14081cb0ef41Sopenharmony_ci 14091cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ToNumber) { 14101cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14111cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 14121cb0ef41Sopenharmony_ci Handle<Object> input = args.at(0); 14131cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE(isolate, Object::ToNumber(isolate, input)); 14141cb0ef41Sopenharmony_ci} 14151cb0ef41Sopenharmony_ci 14161cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ToNumeric) { 14171cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14181cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 14191cb0ef41Sopenharmony_ci Handle<Object> input = args.at(0); 14201cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE(isolate, Object::ToNumeric(isolate, input)); 14211cb0ef41Sopenharmony_ci} 14221cb0ef41Sopenharmony_ci 14231cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ToLength) { 14241cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14251cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 14261cb0ef41Sopenharmony_ci Handle<Object> input = args.at(0); 14271cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE(isolate, Object::ToLength(isolate, input)); 14281cb0ef41Sopenharmony_ci} 14291cb0ef41Sopenharmony_ci 14301cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ToString) { 14311cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14321cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 14331cb0ef41Sopenharmony_ci Handle<Object> input = args.at(0); 14341cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE(isolate, Object::ToString(isolate, input)); 14351cb0ef41Sopenharmony_ci} 14361cb0ef41Sopenharmony_ci 14371cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_ToName) { 14381cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14391cb0ef41Sopenharmony_ci DCHECK_EQ(1, args.length()); 14401cb0ef41Sopenharmony_ci Handle<Object> input = args.at(0); 14411cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE(isolate, Object::ToName(isolate, input)); 14421cb0ef41Sopenharmony_ci} 14431cb0ef41Sopenharmony_ci 14441cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_HasInPrototypeChain) { 14451cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14461cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 14471cb0ef41Sopenharmony_ci Handle<Object> object = args.at(0); 14481cb0ef41Sopenharmony_ci Handle<Object> prototype = args.at(1); 14491cb0ef41Sopenharmony_ci if (!object->IsJSReceiver()) return ReadOnlyRoots(isolate).false_value(); 14501cb0ef41Sopenharmony_ci Maybe<bool> result = JSReceiver::HasInPrototypeChain( 14511cb0ef41Sopenharmony_ci isolate, Handle<JSReceiver>::cast(object), prototype); 14521cb0ef41Sopenharmony_ci MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); 14531cb0ef41Sopenharmony_ci return isolate->heap()->ToBoolean(result.FromJust()); 14541cb0ef41Sopenharmony_ci} 14551cb0ef41Sopenharmony_ci 14561cb0ef41Sopenharmony_ci// ES6 section 7.4.7 CreateIterResultObject ( value, done ) 14571cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CreateIterResultObject) { 14581cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14591cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 14601cb0ef41Sopenharmony_ci Handle<Object> value = args.at(0); 14611cb0ef41Sopenharmony_ci Handle<Object> done = args.at(1); 14621cb0ef41Sopenharmony_ci return *isolate->factory()->NewJSIteratorResult(value, 14631cb0ef41Sopenharmony_ci done->BooleanValue(isolate)); 14641cb0ef41Sopenharmony_ci} 14651cb0ef41Sopenharmony_ci 14661cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CreateDataProperty) { 14671cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14681cb0ef41Sopenharmony_ci DCHECK_EQ(3, args.length()); 14691cb0ef41Sopenharmony_ci Handle<JSReceiver> o = args.at<JSReceiver>(0); 14701cb0ef41Sopenharmony_ci Handle<Object> key = args.at(1); 14711cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 14721cb0ef41Sopenharmony_ci bool success; 14731cb0ef41Sopenharmony_ci PropertyKey lookup_key(isolate, key, &success); 14741cb0ef41Sopenharmony_ci if (!success) return ReadOnlyRoots(isolate).exception(); 14751cb0ef41Sopenharmony_ci LookupIterator it(isolate, o, lookup_key, LookupIterator::OWN); 14761cb0ef41Sopenharmony_ci MAYBE_RETURN(JSReceiver::CreateDataProperty(&it, value, Just(kThrowOnError)), 14771cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).exception()); 14781cb0ef41Sopenharmony_ci return *value; 14791cb0ef41Sopenharmony_ci} 14801cb0ef41Sopenharmony_ci 14811cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SetOwnPropertyIgnoreAttributes) { 14821cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14831cb0ef41Sopenharmony_ci DCHECK_EQ(4, args.length()); 14841cb0ef41Sopenharmony_ci Handle<JSObject> o = args.at<JSObject>(0); 14851cb0ef41Sopenharmony_ci Handle<String> key = args.at<String>(1); 14861cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 14871cb0ef41Sopenharmony_ci int attributes = args.smi_value_at(3); 14881cb0ef41Sopenharmony_ci 14891cb0ef41Sopenharmony_ci RETURN_RESULT_OR_FAILURE(isolate, 14901cb0ef41Sopenharmony_ci JSObject::SetOwnPropertyIgnoreAttributes( 14911cb0ef41Sopenharmony_ci o, key, value, PropertyAttributes(attributes))); 14921cb0ef41Sopenharmony_ci} 14931cb0ef41Sopenharmony_ci 14941cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_GetOwnPropertyDescriptor) { 14951cb0ef41Sopenharmony_ci HandleScope scope(isolate); 14961cb0ef41Sopenharmony_ci 14971cb0ef41Sopenharmony_ci DCHECK_EQ(2, args.length()); 14981cb0ef41Sopenharmony_ci Handle<JSReceiver> object = args.at<JSReceiver>(0); 14991cb0ef41Sopenharmony_ci Handle<Name> name = args.at<Name>(1); 15001cb0ef41Sopenharmony_ci 15011cb0ef41Sopenharmony_ci PropertyDescriptor desc; 15021cb0ef41Sopenharmony_ci Maybe<bool> found = 15031cb0ef41Sopenharmony_ci JSReceiver::GetOwnPropertyDescriptor(isolate, object, name, &desc); 15041cb0ef41Sopenharmony_ci MAYBE_RETURN(found, ReadOnlyRoots(isolate).exception()); 15051cb0ef41Sopenharmony_ci 15061cb0ef41Sopenharmony_ci if (!found.FromJust()) return ReadOnlyRoots(isolate).undefined_value(); 15071cb0ef41Sopenharmony_ci return *desc.ToPropertyDescriptorObject(isolate); 15081cb0ef41Sopenharmony_ci} 15091cb0ef41Sopenharmony_ci 15101cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_LoadPrivateSetter) { 15111cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15121cb0ef41Sopenharmony_ci DCHECK_EQ(args.length(), 1); 15131cb0ef41Sopenharmony_ci Handle<AccessorPair> pair = args.at<AccessorPair>(0); 15141cb0ef41Sopenharmony_ci DCHECK(pair->setter().IsJSFunction()); 15151cb0ef41Sopenharmony_ci return pair->setter(); 15161cb0ef41Sopenharmony_ci} 15171cb0ef41Sopenharmony_ci 15181cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_LoadPrivateGetter) { 15191cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15201cb0ef41Sopenharmony_ci DCHECK_EQ(args.length(), 1); 15211cb0ef41Sopenharmony_ci Handle<AccessorPair> pair = args.at<AccessorPair>(0); 15221cb0ef41Sopenharmony_ci DCHECK(pair->getter().IsJSFunction()); 15231cb0ef41Sopenharmony_ci return pair->getter(); 15241cb0ef41Sopenharmony_ci} 15251cb0ef41Sopenharmony_ci 15261cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_CreatePrivateAccessors) { 15271cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15281cb0ef41Sopenharmony_ci DCHECK_EQ(args.length(), 2); 15291cb0ef41Sopenharmony_ci DCHECK(args[0].IsNull() || args[0].IsJSFunction()); 15301cb0ef41Sopenharmony_ci DCHECK(args[1].IsNull() || args[1].IsJSFunction()); 15311cb0ef41Sopenharmony_ci Handle<AccessorPair> pair = isolate->factory()->NewAccessorPair(); 15321cb0ef41Sopenharmony_ci pair->SetComponents(args[0], args[1]); 15331cb0ef41Sopenharmony_ci return *pair; 15341cb0ef41Sopenharmony_ci} 15351cb0ef41Sopenharmony_ci 15361cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 15371cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 15381cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableAllocate) { 15391cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15401cb0ef41Sopenharmony_ci int at_least_space_for = args.smi_value_at(0); 15411cb0ef41Sopenharmony_ci 15421cb0ef41Sopenharmony_ci return *isolate->factory()->NewSwissNameDictionary(at_least_space_for, 15431cb0ef41Sopenharmony_ci AllocationType::kYoung); 15441cb0ef41Sopenharmony_ci} 15451cb0ef41Sopenharmony_ci 15461cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 15471cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 15481cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableAdd) { 15491cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15501cb0ef41Sopenharmony_ci Handle<SwissNameDictionary> table = args.at<SwissNameDictionary>(0); 15511cb0ef41Sopenharmony_ci Handle<Name> key = args.at<Name>(1); 15521cb0ef41Sopenharmony_ci Handle<Object> value = args.at(2); 15531cb0ef41Sopenharmony_ci PropertyDetails details(Smi::cast(args[3])); 15541cb0ef41Sopenharmony_ci 15551cb0ef41Sopenharmony_ci DCHECK(key->IsUniqueName()); 15561cb0ef41Sopenharmony_ci 15571cb0ef41Sopenharmony_ci return *SwissNameDictionary::Add(isolate, table, key, value, details); 15581cb0ef41Sopenharmony_ci} 15591cb0ef41Sopenharmony_ci 15601cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 15611cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 15621cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableFindEntry) { 15631cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15641cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 15651cb0ef41Sopenharmony_ci auto table = SwissNameDictionary::cast(args[0]); 15661cb0ef41Sopenharmony_ci Name key = Name::cast(args[1]); 15671cb0ef41Sopenharmony_ci InternalIndex index = table.FindEntry(isolate, key); 15681cb0ef41Sopenharmony_ci return Smi::FromInt(index.is_found() 15691cb0ef41Sopenharmony_ci ? index.as_int() 15701cb0ef41Sopenharmony_ci : SwissNameDictionary::kNotFoundSentinel); 15711cb0ef41Sopenharmony_ci} 15721cb0ef41Sopenharmony_ci 15731cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 15741cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 15751cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableUpdate) { 15761cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15771cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 15781cb0ef41Sopenharmony_ci auto table = SwissNameDictionary::cast(args[0]); 15791cb0ef41Sopenharmony_ci InternalIndex index(args.smi_value_at(1)); 15801cb0ef41Sopenharmony_ci Object value = args[2]; 15811cb0ef41Sopenharmony_ci table.ValueAtPut(index, value); 15821cb0ef41Sopenharmony_ci 15831cb0ef41Sopenharmony_ci PropertyDetails details(Smi::cast(args[3])); 15841cb0ef41Sopenharmony_ci table.DetailsAtPut(index, details); 15851cb0ef41Sopenharmony_ci 15861cb0ef41Sopenharmony_ci return ReadOnlyRoots(isolate).undefined_value(); 15871cb0ef41Sopenharmony_ci} 15881cb0ef41Sopenharmony_ci 15891cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 15901cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 15911cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableDelete) { 15921cb0ef41Sopenharmony_ci HandleScope scope(isolate); 15931cb0ef41Sopenharmony_ci Handle<SwissNameDictionary> table = args.at<SwissNameDictionary>(0); 15941cb0ef41Sopenharmony_ci InternalIndex index(args.smi_value_at(1)); 15951cb0ef41Sopenharmony_ci 15961cb0ef41Sopenharmony_ci return *SwissNameDictionary::DeleteEntry(isolate, table, index); 15971cb0ef41Sopenharmony_ci} 15981cb0ef41Sopenharmony_ci 15991cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 16001cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 16011cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableEquals) { 16021cb0ef41Sopenharmony_ci HandleScope scope(isolate); 16031cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 16041cb0ef41Sopenharmony_ci auto table = SwissNameDictionary::cast(args[0]); 16051cb0ef41Sopenharmony_ci auto other = SwissNameDictionary::cast(args[0]); 16061cb0ef41Sopenharmony_ci return Smi::FromInt(table.EqualsForTesting(other)); 16071cb0ef41Sopenharmony_ci} 16081cb0ef41Sopenharmony_ci 16091cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 16101cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 16111cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableElementsCount) { 16121cb0ef41Sopenharmony_ci HandleScope scope(isolate); 16131cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 16141cb0ef41Sopenharmony_ci auto table = SwissNameDictionary::cast(args[0]); 16151cb0ef41Sopenharmony_ci return Smi::FromInt(table.NumberOfElements()); 16161cb0ef41Sopenharmony_ci} 16171cb0ef41Sopenharmony_ci 16181cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 16191cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 16201cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableKeyAt) { 16211cb0ef41Sopenharmony_ci HandleScope scope(isolate); 16221cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 16231cb0ef41Sopenharmony_ci auto table = SwissNameDictionary::cast(args[0]); 16241cb0ef41Sopenharmony_ci InternalIndex index(args.smi_value_at(1)); 16251cb0ef41Sopenharmony_ci return table.KeyAt(index); 16261cb0ef41Sopenharmony_ci} 16271cb0ef41Sopenharmony_ci 16281cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 16291cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 16301cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableValueAt) { 16311cb0ef41Sopenharmony_ci HandleScope scope(isolate); 16321cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 16331cb0ef41Sopenharmony_ci auto table = SwissNameDictionary::cast(args[0]); 16341cb0ef41Sopenharmony_ci InternalIndex index(args.smi_value_at(1)); 16351cb0ef41Sopenharmony_ci return table.ValueAt(index); 16361cb0ef41Sopenharmony_ci} 16371cb0ef41Sopenharmony_ci 16381cb0ef41Sopenharmony_ci// TODO(v8:11330) This is only here while the CSA/Torque implementaton of 16391cb0ef41Sopenharmony_ci// SwissNameDictionary is work in progress. 16401cb0ef41Sopenharmony_ciRUNTIME_FUNCTION(Runtime_SwissTableDetailsAt) { 16411cb0ef41Sopenharmony_ci HandleScope scope(isolate); 16421cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 16431cb0ef41Sopenharmony_ci auto table = SwissNameDictionary::cast(args[0]); 16441cb0ef41Sopenharmony_ci InternalIndex index(args.smi_value_at(1)); 16451cb0ef41Sopenharmony_ci PropertyDetails d = table.DetailsAt(index); 16461cb0ef41Sopenharmony_ci return d.AsSmi(); 16471cb0ef41Sopenharmony_ci} 16481cb0ef41Sopenharmony_ci 16491cb0ef41Sopenharmony_ci} // namespace internal 16501cb0ef41Sopenharmony_ci} // namespace v8 1651