| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef vm_ObjectFlags_inl_h |
| 8 |
#define vm_ObjectFlags_inl_h |
| 9 |
|
| 10 |
#include "vm/ObjectFlags.h" |
| 11 |
|
| 12 |
#include "builtin/Array.h" |
| 13 |
#include "vm/JSAtomState.h" |
| 14 |
#include "vm/JSContext.h" |
| 15 |
#include "vm/PlainObject.h" |
| 16 |
#include "vm/PropertyInfo.h" |
| 17 |
|
| 18 |
namespace js { |
| 19 |
|
| 20 |
MOZ_ALWAYS_INLINE ObjectFlags |
| 21 |
GetObjectFlagsForNewProperty(const JSClass* clasp, ObjectFlags flags, jsid id, |
| 22 |
PropertyFlags propFlags, JSContext* cx) { |
| 23 |
uint32_t index; |
| 24 |
if (IdIsIndex(id, &index)) { |
| 25 |
flags.setFlag(ObjectFlag::Indexed); |
| 26 |
} else if (id.isSymbol() && id.toSymbol()->isInterestingSymbol()) { |
| 27 |
flags.setFlag(ObjectFlag::HasInterestingSymbol); |
| 28 |
} |
| 29 |
|
| 30 |
if ((!propFlags.isDataProperty() || !propFlags.writable()) && |
| 31 |
clasp == &PlainObject::class_ && !id.isAtom(cx->names().proto_)) { |
| 32 |
flags.setFlag(ObjectFlag::HasNonWritableOrAccessorPropExclProto); |
| 33 |
} |
| 34 |
|
| 35 |
// https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver |
| 36 |
// Proxy.[[Get]] or [[Set]] Step 9 |
| 37 |
if (!propFlags.configurable()) { |
| 38 |
MOZ_ASSERT(clasp->isNativeObject()); |
| 39 |
// NOTE: there is a hole which this flag does not cover, which is if the |
| 40 |
// class has a resolve hook which could lazily define a non-configurable |
| 41 |
// non-writable property. We can just look this up directly though in the |
| 42 |
// JIT. |
| 43 |
if (propFlags.isDataProperty() && !propFlags.writable()) { |
| 44 |
flags.setFlag(ObjectFlag::NeedsProxyGetSetResultValidation); |
| 45 |
} else if (propFlags.isAccessorProperty()) { |
| 46 |
// This will cover us for both get trap validation and set trap |
| 47 |
// validation. We could be more aggressive, because what we really |
| 48 |
// care about is if there is a getter but not a setter and vice |
| 49 |
// versa, but the first pass at doing that resulted in test |
| 50 |
// failures. We'll need to work on that as a follow-up if it is |
| 51 |
// important. |
| 52 |
flags.setFlag(ObjectFlag::NeedsProxyGetSetResultValidation); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if (propFlags.enumerable()) { |
| 57 |
flags.setFlag(ObjectFlag::HasEnumerable); |
| 58 |
} |
| 59 |
|
| 60 |
return flags; |
| 61 |
} |
| 62 |
|
| 63 |
// When reusing another shape's PropMap, we need to copy the object flags that |
| 64 |
// are based on property information. This is equivalent to (but faster than) |
| 65 |
// calling GetObjectFlagsForNewProperty for all properties in the map. |
| 66 |
inline ObjectFlags CopyPropMapObjectFlags(ObjectFlags dest, |
| 67 |
ObjectFlags source) { |
| 68 |
if (source.hasFlag(ObjectFlag::Indexed)) { |
| 69 |
dest.setFlag(ObjectFlag::Indexed); |
| 70 |
} |
| 71 |
if (source.hasFlag(ObjectFlag::HasInterestingSymbol)) { |
| 72 |
dest.setFlag(ObjectFlag::HasInterestingSymbol); |
| 73 |
} |
| 74 |
if (source.hasFlag(ObjectFlag::HasNonWritableOrAccessorPropExclProto)) { |
| 75 |
dest.setFlag(ObjectFlag::HasNonWritableOrAccessorPropExclProto); |
| 76 |
} |
| 77 |
if (source.hasFlag(ObjectFlag::NeedsProxyGetSetResultValidation)) { |
| 78 |
dest.setFlag(ObjectFlag::NeedsProxyGetSetResultValidation); |
| 79 |
} |
| 80 |
return dest; |
| 81 |
} |
| 82 |
|
| 83 |
} // namespace js |
| 84 |
|
| 85 |
#endif /* vm_ObjectFlags_inl_h */ |