11cb0ef41Sopenharmony_ci// Copyright 2016 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/builtins/builtins-utils-inl.h"
61cb0ef41Sopenharmony_ci#include "src/builtins/builtins.h"
71cb0ef41Sopenharmony_ci#include "src/codegen/code-factory.h"
81cb0ef41Sopenharmony_ci#include "src/common/message-template.h"
91cb0ef41Sopenharmony_ci#include "src/heap/heap-inl.h"  // For ToBoolean. TODO(jkummerow): Drop.
101cb0ef41Sopenharmony_ci#include "src/logging/counters.h"
111cb0ef41Sopenharmony_ci#include "src/objects/keys.h"
121cb0ef41Sopenharmony_ci#include "src/objects/lookup.h"
131cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
141cb0ef41Sopenharmony_ci#include "src/objects/property-descriptor.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cinamespace v8 {
171cb0ef41Sopenharmony_cinamespace internal {
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci// -----------------------------------------------------------------------------
201cb0ef41Sopenharmony_ci// ES6 section 19.1 Object Objects
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci// ES6 section 19.1.3.4 Object.prototype.propertyIsEnumerable ( V )
231cb0ef41Sopenharmony_ciBUILTIN(ObjectPrototypePropertyIsEnumerable) {
241cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
251cb0ef41Sopenharmony_ci  Handle<JSReceiver> object;
261cb0ef41Sopenharmony_ci  Handle<Name> name;
271cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
281cb0ef41Sopenharmony_ci      isolate, name, Object::ToName(isolate, args.atOrUndefined(isolate, 1)));
291cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
301cb0ef41Sopenharmony_ci      isolate, object, Object::ToObject(isolate, args.receiver()));
311cb0ef41Sopenharmony_ci  Maybe<PropertyAttributes> maybe =
321cb0ef41Sopenharmony_ci      JSReceiver::GetOwnPropertyAttributes(object, name);
331cb0ef41Sopenharmony_ci  if (maybe.IsNothing()) return ReadOnlyRoots(isolate).exception();
341cb0ef41Sopenharmony_ci  if (maybe.FromJust() == ABSENT) return ReadOnlyRoots(isolate).false_value();
351cb0ef41Sopenharmony_ci  return isolate->heap()->ToBoolean((maybe.FromJust() & DONT_ENUM) == 0);
361cb0ef41Sopenharmony_ci}
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci// ES6 section 19.1.2.3 Object.defineProperties
391cb0ef41Sopenharmony_ciBUILTIN(ObjectDefineProperties) {
401cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
411cb0ef41Sopenharmony_ci  DCHECK_LE(3, args.length());
421cb0ef41Sopenharmony_ci  Handle<Object> target = args.at(1);
431cb0ef41Sopenharmony_ci  Handle<Object> properties = args.at(2);
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  RETURN_RESULT_OR_FAILURE(
461cb0ef41Sopenharmony_ci      isolate, JSReceiver::DefineProperties(isolate, target, properties));
471cb0ef41Sopenharmony_ci}
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci// ES6 section 19.1.2.4 Object.defineProperty
501cb0ef41Sopenharmony_ciBUILTIN(ObjectDefineProperty) {
511cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
521cb0ef41Sopenharmony_ci  DCHECK_LE(4, args.length());
531cb0ef41Sopenharmony_ci  Handle<Object> target = args.at(1);
541cb0ef41Sopenharmony_ci  Handle<Object> key = args.at(2);
551cb0ef41Sopenharmony_ci  Handle<Object> attributes = args.at(3);
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  return JSReceiver::DefineProperty(isolate, target, key, attributes);
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_cinamespace {
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_citemplate <AccessorComponent which_accessor>
631cb0ef41Sopenharmony_ciObject ObjectDefineAccessor(Isolate* isolate, Handle<Object> object,
641cb0ef41Sopenharmony_ci                            Handle<Object> name, Handle<Object> accessor) {
651cb0ef41Sopenharmony_ci  // 1. Let O be ? ToObject(this value).
661cb0ef41Sopenharmony_ci  Handle<JSReceiver> receiver;
671cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
681cb0ef41Sopenharmony_ci                                     Object::ToObject(isolate, object));
691cb0ef41Sopenharmony_ci  // 2. If IsCallable(getter) is false, throw a TypeError exception.
701cb0ef41Sopenharmony_ci  if (!accessor->IsCallable()) {
711cb0ef41Sopenharmony_ci    MessageTemplate message =
721cb0ef41Sopenharmony_ci        which_accessor == ACCESSOR_GETTER
731cb0ef41Sopenharmony_ci            ? MessageTemplate::kObjectGetterExpectingFunction
741cb0ef41Sopenharmony_ci            : MessageTemplate::kObjectSetterExpectingFunction;
751cb0ef41Sopenharmony_ci    THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(message));
761cb0ef41Sopenharmony_ci  }
771cb0ef41Sopenharmony_ci  // 3. Let desc be PropertyDescriptor{[[Get]]: getter, [[Enumerable]]: true,
781cb0ef41Sopenharmony_ci  //                                   [[Configurable]]: true}.
791cb0ef41Sopenharmony_ci  PropertyDescriptor desc;
801cb0ef41Sopenharmony_ci  if (which_accessor == ACCESSOR_GETTER) {
811cb0ef41Sopenharmony_ci    desc.set_get(accessor);
821cb0ef41Sopenharmony_ci  } else {
831cb0ef41Sopenharmony_ci    DCHECK(which_accessor == ACCESSOR_SETTER);
841cb0ef41Sopenharmony_ci    desc.set_set(accessor);
851cb0ef41Sopenharmony_ci  }
861cb0ef41Sopenharmony_ci  desc.set_enumerable(true);
871cb0ef41Sopenharmony_ci  desc.set_configurable(true);
881cb0ef41Sopenharmony_ci  // 4. Let key be ? ToPropertyKey(P).
891cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name,
901cb0ef41Sopenharmony_ci                                     Object::ToPropertyKey(isolate, name));
911cb0ef41Sopenharmony_ci  // 5. Perform ? DefinePropertyOrThrow(O, key, desc).
921cb0ef41Sopenharmony_ci  // To preserve legacy behavior, we ignore errors silently rather than
931cb0ef41Sopenharmony_ci  // throwing an exception.
941cb0ef41Sopenharmony_ci  Maybe<bool> success = JSReceiver::DefineOwnProperty(
951cb0ef41Sopenharmony_ci      isolate, receiver, name, &desc, Just(kThrowOnError));
961cb0ef41Sopenharmony_ci  MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
971cb0ef41Sopenharmony_ci  if (!success.FromJust()) {
981cb0ef41Sopenharmony_ci    isolate->CountUsage(v8::Isolate::kDefineGetterOrSetterWouldThrow);
991cb0ef41Sopenharmony_ci  }
1001cb0ef41Sopenharmony_ci  // 6. Return undefined.
1011cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
1021cb0ef41Sopenharmony_ci}
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ciObject ObjectLookupAccessor(Isolate* isolate, Handle<Object> object,
1051cb0ef41Sopenharmony_ci                            Handle<Object> key, AccessorComponent component) {
1061cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, object,
1071cb0ef41Sopenharmony_ci                                     Object::ToObject(isolate, object));
1081cb0ef41Sopenharmony_ci  // TODO(jkummerow/verwaest): PropertyKey(..., bool*) performs a
1091cb0ef41Sopenharmony_ci  // functionally equivalent conversion, but handles element indices slightly
1101cb0ef41Sopenharmony_ci  // differently. Does one of the approaches have a performance advantage?
1111cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
1121cb0ef41Sopenharmony_ci                                     Object::ToPropertyKey(isolate, key));
1131cb0ef41Sopenharmony_ci  PropertyKey lookup_key(isolate, key);
1141cb0ef41Sopenharmony_ci  LookupIterator it(isolate, object, lookup_key,
1151cb0ef41Sopenharmony_ci                    LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci  for (; it.IsFound(); it.Next()) {
1181cb0ef41Sopenharmony_ci    switch (it.state()) {
1191cb0ef41Sopenharmony_ci      case LookupIterator::INTERCEPTOR:
1201cb0ef41Sopenharmony_ci      case LookupIterator::NOT_FOUND:
1211cb0ef41Sopenharmony_ci      case LookupIterator::TRANSITION:
1221cb0ef41Sopenharmony_ci        UNREACHABLE();
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci      case LookupIterator::ACCESS_CHECK:
1251cb0ef41Sopenharmony_ci        if (it.HasAccess()) continue;
1261cb0ef41Sopenharmony_ci        isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>());
1271cb0ef41Sopenharmony_ci        RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
1281cb0ef41Sopenharmony_ci        return ReadOnlyRoots(isolate).undefined_value();
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci      case LookupIterator::JSPROXY: {
1311cb0ef41Sopenharmony_ci        PropertyDescriptor desc;
1321cb0ef41Sopenharmony_ci        Maybe<bool> found = JSProxy::GetOwnPropertyDescriptor(
1331cb0ef41Sopenharmony_ci            isolate, it.GetHolder<JSProxy>(), it.GetName(), &desc);
1341cb0ef41Sopenharmony_ci        MAYBE_RETURN(found, ReadOnlyRoots(isolate).exception());
1351cb0ef41Sopenharmony_ci        if (found.FromJust()) {
1361cb0ef41Sopenharmony_ci          if (component == ACCESSOR_GETTER && desc.has_get()) {
1371cb0ef41Sopenharmony_ci            return *desc.get();
1381cb0ef41Sopenharmony_ci          }
1391cb0ef41Sopenharmony_ci          if (component == ACCESSOR_SETTER && desc.has_set()) {
1401cb0ef41Sopenharmony_ci            return *desc.set();
1411cb0ef41Sopenharmony_ci          }
1421cb0ef41Sopenharmony_ci          return ReadOnlyRoots(isolate).undefined_value();
1431cb0ef41Sopenharmony_ci        }
1441cb0ef41Sopenharmony_ci        Handle<Object> prototype;
1451cb0ef41Sopenharmony_ci        ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1461cb0ef41Sopenharmony_ci            isolate, prototype, JSProxy::GetPrototype(it.GetHolder<JSProxy>()));
1471cb0ef41Sopenharmony_ci        if (prototype->IsNull(isolate)) {
1481cb0ef41Sopenharmony_ci          return ReadOnlyRoots(isolate).undefined_value();
1491cb0ef41Sopenharmony_ci        }
1501cb0ef41Sopenharmony_ci        return ObjectLookupAccessor(isolate, prototype, key, component);
1511cb0ef41Sopenharmony_ci      }
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci      case LookupIterator::INTEGER_INDEXED_EXOTIC:
1541cb0ef41Sopenharmony_ci      case LookupIterator::DATA:
1551cb0ef41Sopenharmony_ci        return ReadOnlyRoots(isolate).undefined_value();
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci      case LookupIterator::ACCESSOR: {
1581cb0ef41Sopenharmony_ci        Handle<Object> maybe_pair = it.GetAccessors();
1591cb0ef41Sopenharmony_ci        if (maybe_pair->IsAccessorPair()) {
1601cb0ef41Sopenharmony_ci          Handle<NativeContext> native_context = it.GetHolder<JSReceiver>()
1611cb0ef41Sopenharmony_ci                                                     ->GetCreationContext()
1621cb0ef41Sopenharmony_ci                                                     .ToHandleChecked();
1631cb0ef41Sopenharmony_ci          return *AccessorPair::GetComponent(
1641cb0ef41Sopenharmony_ci              isolate, native_context, Handle<AccessorPair>::cast(maybe_pair),
1651cb0ef41Sopenharmony_ci              component);
1661cb0ef41Sopenharmony_ci        }
1671cb0ef41Sopenharmony_ci      }
1681cb0ef41Sopenharmony_ci    }
1691cb0ef41Sopenharmony_ci  }
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
1721cb0ef41Sopenharmony_ci}
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci}  // namespace
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ci// ES6 B.2.2.2 a.k.a.
1771cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-object.prototype.__defineGetter__
1781cb0ef41Sopenharmony_ciBUILTIN(ObjectDefineGetter) {
1791cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
1801cb0ef41Sopenharmony_ci  Handle<Object> object = args.at(0);  // Receiver.
1811cb0ef41Sopenharmony_ci  Handle<Object> name = args.at(1);
1821cb0ef41Sopenharmony_ci  Handle<Object> getter = args.at(2);
1831cb0ef41Sopenharmony_ci  return ObjectDefineAccessor<ACCESSOR_GETTER>(isolate, object, name, getter);
1841cb0ef41Sopenharmony_ci}
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci// ES6 B.2.2.3 a.k.a.
1871cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-object.prototype.__defineSetter__
1881cb0ef41Sopenharmony_ciBUILTIN(ObjectDefineSetter) {
1891cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
1901cb0ef41Sopenharmony_ci  Handle<Object> object = args.at(0);  // Receiver.
1911cb0ef41Sopenharmony_ci  Handle<Object> name = args.at(1);
1921cb0ef41Sopenharmony_ci  Handle<Object> setter = args.at(2);
1931cb0ef41Sopenharmony_ci  return ObjectDefineAccessor<ACCESSOR_SETTER>(isolate, object, name, setter);
1941cb0ef41Sopenharmony_ci}
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci// ES6 B.2.2.4 a.k.a.
1971cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-object.prototype.__lookupGetter__
1981cb0ef41Sopenharmony_ciBUILTIN(ObjectLookupGetter) {
1991cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
2001cb0ef41Sopenharmony_ci  Handle<Object> object = args.at(0);
2011cb0ef41Sopenharmony_ci  Handle<Object> name = args.at(1);
2021cb0ef41Sopenharmony_ci  return ObjectLookupAccessor(isolate, object, name, ACCESSOR_GETTER);
2031cb0ef41Sopenharmony_ci}
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci// ES6 B.2.2.5 a.k.a.
2061cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-object.prototype.__lookupSetter__
2071cb0ef41Sopenharmony_ciBUILTIN(ObjectLookupSetter) {
2081cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
2091cb0ef41Sopenharmony_ci  Handle<Object> object = args.at(0);
2101cb0ef41Sopenharmony_ci  Handle<Object> name = args.at(1);
2111cb0ef41Sopenharmony_ci  return ObjectLookupAccessor(isolate, object, name, ACCESSOR_SETTER);
2121cb0ef41Sopenharmony_ci}
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci// ES6 section 19.1.2.5 Object.freeze ( O )
2151cb0ef41Sopenharmony_ciBUILTIN(ObjectFreeze) {
2161cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
2171cb0ef41Sopenharmony_ci  Handle<Object> object = args.atOrUndefined(isolate, 1);
2181cb0ef41Sopenharmony_ci  if (object->IsJSReceiver()) {
2191cb0ef41Sopenharmony_ci    MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object),
2201cb0ef41Sopenharmony_ci                                               FROZEN, kThrowOnError),
2211cb0ef41Sopenharmony_ci                 ReadOnlyRoots(isolate).exception());
2221cb0ef41Sopenharmony_ci  }
2231cb0ef41Sopenharmony_ci  return *object;
2241cb0ef41Sopenharmony_ci}
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ci// ES6 section B.2.2.1.1 get Object.prototype.__proto__
2271cb0ef41Sopenharmony_ciBUILTIN(ObjectPrototypeGetProto) {
2281cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
2291cb0ef41Sopenharmony_ci  // 1. Let O be ? ToObject(this value).
2301cb0ef41Sopenharmony_ci  Handle<JSReceiver> receiver;
2311cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2321cb0ef41Sopenharmony_ci      isolate, receiver, Object::ToObject(isolate, args.receiver()));
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci  // 2. Return ? O.[[GetPrototypeOf]]().
2351cb0ef41Sopenharmony_ci  RETURN_RESULT_OR_FAILURE(isolate,
2361cb0ef41Sopenharmony_ci                           JSReceiver::GetPrototype(isolate, receiver));
2371cb0ef41Sopenharmony_ci}
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_ci// ES6 section B.2.2.1.2 set Object.prototype.__proto__
2401cb0ef41Sopenharmony_ciBUILTIN(ObjectPrototypeSetProto) {
2411cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
2421cb0ef41Sopenharmony_ci  // 1. Let O be ? RequireObjectCoercible(this value).
2431cb0ef41Sopenharmony_ci  Handle<Object> object = args.receiver();
2441cb0ef41Sopenharmony_ci  if (object->IsNullOrUndefined(isolate)) {
2451cb0ef41Sopenharmony_ci    THROW_NEW_ERROR_RETURN_FAILURE(
2461cb0ef41Sopenharmony_ci        isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
2471cb0ef41Sopenharmony_ci                              isolate->factory()->NewStringFromAsciiChecked(
2481cb0ef41Sopenharmony_ci                                  "set Object.prototype.__proto__")));
2491cb0ef41Sopenharmony_ci  }
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ci  // 2. If Type(proto) is neither Object nor Null, return undefined.
2521cb0ef41Sopenharmony_ci  Handle<Object> proto = args.at(1);
2531cb0ef41Sopenharmony_ci  if (!proto->IsNull(isolate) && !proto->IsJSReceiver()) {
2541cb0ef41Sopenharmony_ci    return ReadOnlyRoots(isolate).undefined_value();
2551cb0ef41Sopenharmony_ci  }
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_ci  // 3. If Type(O) is not Object, return undefined.
2581cb0ef41Sopenharmony_ci  if (!object->IsJSReceiver()) return ReadOnlyRoots(isolate).undefined_value();
2591cb0ef41Sopenharmony_ci  Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ci  // 4. Let status be ? O.[[SetPrototypeOf]](proto).
2621cb0ef41Sopenharmony_ci  // 5. If status is false, throw a TypeError exception.
2631cb0ef41Sopenharmony_ci  MAYBE_RETURN(
2641cb0ef41Sopenharmony_ci      JSReceiver::SetPrototype(isolate, receiver, proto, true, kThrowOnError),
2651cb0ef41Sopenharmony_ci      ReadOnlyRoots(isolate).exception());
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ci  // Return undefined.
2681cb0ef41Sopenharmony_ci  return ReadOnlyRoots(isolate).undefined_value();
2691cb0ef41Sopenharmony_ci}
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_cinamespace {
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ciObject GetOwnPropertyKeys(Isolate* isolate, BuiltinArguments args,
2741cb0ef41Sopenharmony_ci                          PropertyFilter filter) {
2751cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
2761cb0ef41Sopenharmony_ci  Handle<Object> object = args.atOrUndefined(isolate, 1);
2771cb0ef41Sopenharmony_ci  Handle<JSReceiver> receiver;
2781cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
2791cb0ef41Sopenharmony_ci                                     Object::ToObject(isolate, object));
2801cb0ef41Sopenharmony_ci  Handle<FixedArray> keys;
2811cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2821cb0ef41Sopenharmony_ci      isolate, keys,
2831cb0ef41Sopenharmony_ci      KeyAccumulator::GetKeys(receiver, KeyCollectionMode::kOwnOnly, filter,
2841cb0ef41Sopenharmony_ci                              GetKeysConversion::kConvertToString));
2851cb0ef41Sopenharmony_ci  return *isolate->factory()->NewJSArrayWithElements(keys);
2861cb0ef41Sopenharmony_ci}
2871cb0ef41Sopenharmony_ci
2881cb0ef41Sopenharmony_ci}  // namespace
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ci// ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O )
2911cb0ef41Sopenharmony_ciBUILTIN(ObjectGetOwnPropertySymbols) {
2921cb0ef41Sopenharmony_ci  return GetOwnPropertyKeys(isolate, args, SKIP_STRINGS);
2931cb0ef41Sopenharmony_ci}
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ci// ES6 section 19.1.2.12 Object.isFrozen ( O )
2961cb0ef41Sopenharmony_ciBUILTIN(ObjectIsFrozen) {
2971cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
2981cb0ef41Sopenharmony_ci  Handle<Object> object = args.atOrUndefined(isolate, 1);
2991cb0ef41Sopenharmony_ci  Maybe<bool> result = object->IsJSReceiver()
3001cb0ef41Sopenharmony_ci                           ? JSReceiver::TestIntegrityLevel(
3011cb0ef41Sopenharmony_ci                                 Handle<JSReceiver>::cast(object), FROZEN)
3021cb0ef41Sopenharmony_ci                           : Just(true);
3031cb0ef41Sopenharmony_ci  MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
3041cb0ef41Sopenharmony_ci  return isolate->heap()->ToBoolean(result.FromJust());
3051cb0ef41Sopenharmony_ci}
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci// ES6 section 19.1.2.13 Object.isSealed ( O )
3081cb0ef41Sopenharmony_ciBUILTIN(ObjectIsSealed) {
3091cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
3101cb0ef41Sopenharmony_ci  Handle<Object> object = args.atOrUndefined(isolate, 1);
3111cb0ef41Sopenharmony_ci  Maybe<bool> result = object->IsJSReceiver()
3121cb0ef41Sopenharmony_ci                           ? JSReceiver::TestIntegrityLevel(
3131cb0ef41Sopenharmony_ci                                 Handle<JSReceiver>::cast(object), SEALED)
3141cb0ef41Sopenharmony_ci                           : Just(true);
3151cb0ef41Sopenharmony_ci  MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
3161cb0ef41Sopenharmony_ci  return isolate->heap()->ToBoolean(result.FromJust());
3171cb0ef41Sopenharmony_ci}
3181cb0ef41Sopenharmony_ci
3191cb0ef41Sopenharmony_ciBUILTIN(ObjectGetOwnPropertyDescriptors) {
3201cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
3211cb0ef41Sopenharmony_ci  Handle<Object> object = args.atOrUndefined(isolate, 1);
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ci  Handle<JSReceiver> receiver;
3241cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
3251cb0ef41Sopenharmony_ci                                     Object::ToObject(isolate, object));
3261cb0ef41Sopenharmony_ci
3271cb0ef41Sopenharmony_ci  Handle<FixedArray> keys;
3281cb0ef41Sopenharmony_ci  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
3291cb0ef41Sopenharmony_ci      isolate, keys, KeyAccumulator::GetKeys(
3301cb0ef41Sopenharmony_ci                         receiver, KeyCollectionMode::kOwnOnly, ALL_PROPERTIES,
3311cb0ef41Sopenharmony_ci                         GetKeysConversion::kConvertToString));
3321cb0ef41Sopenharmony_ci
3331cb0ef41Sopenharmony_ci  Handle<JSObject> descriptors =
3341cb0ef41Sopenharmony_ci      isolate->factory()->NewJSObject(isolate->object_function());
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ci  for (int i = 0; i < keys->length(); ++i) {
3371cb0ef41Sopenharmony_ci    Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
3381cb0ef41Sopenharmony_ci    PropertyDescriptor descriptor;
3391cb0ef41Sopenharmony_ci    Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor(
3401cb0ef41Sopenharmony_ci        isolate, receiver, key, &descriptor);
3411cb0ef41Sopenharmony_ci    MAYBE_RETURN(did_get_descriptor, ReadOnlyRoots(isolate).exception());
3421cb0ef41Sopenharmony_ci
3431cb0ef41Sopenharmony_ci    if (!did_get_descriptor.FromJust()) continue;
3441cb0ef41Sopenharmony_ci    Handle<Object> from_descriptor = descriptor.ToObject(isolate);
3451cb0ef41Sopenharmony_ci
3461cb0ef41Sopenharmony_ci    Maybe<bool> success = JSReceiver::CreateDataProperty(
3471cb0ef41Sopenharmony_ci        isolate, descriptors, key, from_descriptor, Just(kDontThrow));
3481cb0ef41Sopenharmony_ci    CHECK(success.FromJust());
3491cb0ef41Sopenharmony_ci  }
3501cb0ef41Sopenharmony_ci
3511cb0ef41Sopenharmony_ci  return *descriptors;
3521cb0ef41Sopenharmony_ci}
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci// ES6 section 19.1.2.17 Object.seal ( O )
3551cb0ef41Sopenharmony_ciBUILTIN(ObjectSeal) {
3561cb0ef41Sopenharmony_ci  HandleScope scope(isolate);
3571cb0ef41Sopenharmony_ci  Handle<Object> object = args.atOrUndefined(isolate, 1);
3581cb0ef41Sopenharmony_ci  if (object->IsJSReceiver()) {
3591cb0ef41Sopenharmony_ci    MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object),
3601cb0ef41Sopenharmony_ci                                               SEALED, kThrowOnError),
3611cb0ef41Sopenharmony_ci                 ReadOnlyRoots(isolate).exception());
3621cb0ef41Sopenharmony_ci  }
3631cb0ef41Sopenharmony_ci  return *object;
3641cb0ef41Sopenharmony_ci}
3651cb0ef41Sopenharmony_ci
3661cb0ef41Sopenharmony_ci}  // namespace internal
3671cb0ef41Sopenharmony_ci}  // namespace v8
368