Skip to content

Commit

Permalink
Revert D19318820: Make direct property slots trailing and overlapping…
Browse files Browse the repository at this point in the history
… w/ C++ fields of subclasses

Differential Revision:
D19318820

Original commit changeset: 516617e461c1

fbshipit-source-id: 400652cbfdd0995672f3fa4653b9493af765c23b
  • Loading branch information
Greg Nelson authored and facebook-github-bot committed Jan 14, 2020
1 parent cc56574 commit 8d57632
Show file tree
Hide file tree
Showing 29 changed files with 245 additions and 473 deletions.
42 changes: 19 additions & 23 deletions include/hermes/VM/Callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ class Callable : public JSObject {
/// Fast constructor used by deserializer.
Callable(Deserializer &d, const VTable *vt);

friend void serializeCallableImpl(
Serializer &s,
const GCCell *cell,
unsigned overlapSlots);
friend void serializeCallableImpl(Serializer &s, const GCCell *cell);
#endif

static bool classof(const GCCell *cell) {
Expand Down Expand Up @@ -360,6 +357,10 @@ class BoundFunction final : public Callable {
using Super = Callable;
static CallableVTable vt;

// We need one more slot for '.length'
static const PropStorage::size_type NAMED_PROPERTY_SLOTS =
Super::NAMED_PROPERTY_SLOTS + 1;

static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::BoundFunctionKind;
}
Expand Down Expand Up @@ -465,16 +466,17 @@ class NativeFunction : public Callable {
void *context,
NativeFunctionPtr functionPtr);

static void serializeNativeFunctionImpl(
Serializer &s,
const GCCell *cell,
unsigned overlapSlots);
static void serializeNativeFunctionImpl(Serializer &s, const GCCell *cell);
friend void NativeFunctionSerialize(Serializer &s, const GCCell *cell);
#endif

using Super = Callable;
static CallableVTable vt;

// We need two more slots for '.name' and '.length'
static const PropStorage::size_type NAMED_PROPERTY_SLOTS =
Super::NAMED_PROPERTY_SLOTS + 2;

static bool classof(const GCCell *cell) {
return kindInRange(
cell->getKind(),
Expand Down Expand Up @@ -644,9 +646,7 @@ class NativeFunction : public Callable {
Runtime *runtime,
unsigned index) {
return JSObject::getInternalProperty(
self,
runtime,
numOverlapSlots<NativeFunction>() + ANONYMOUS_PROPERTY_SLOTS + index);
self, runtime, ANONYMOUS_PROPERTY_SLOTS + index);
}

/// Set the value in an additional slot.
Expand All @@ -658,10 +658,7 @@ class NativeFunction : public Callable {
unsigned index,
HermesValue value) {
return JSObject::setInternalProperty(
self,
runtime,
numOverlapSlots<NativeFunction>() + ANONYMOUS_PROPERTY_SLOTS + index,
value);
self, runtime, ANONYMOUS_PROPERTY_SLOTS + index, value);
}

protected:
Expand Down Expand Up @@ -742,8 +739,7 @@ class NativeConstructor final : public NativeFunction {
runtime,
*parentHandle,
runtime->getHiddenClassForPrototypeRaw(
*parentHandle,
numOverlapSlots<NativeConstructor>() + ANONYMOUS_PROPERTY_SLOTS),
*parentHandle, ANONYMOUS_PROPERTY_SLOTS),
context,
functionPtr,
creator,
Expand All @@ -768,8 +764,7 @@ class NativeConstructor final : public NativeFunction {
runtime,
*parentHandle,
runtime->getHiddenClassForPrototypeRaw(
*parentHandle,
numOverlapSlots<NativeConstructor>() + ANONYMOUS_PROPERTY_SLOTS),
*parentHandle, ANONYMOUS_PROPERTY_SLOTS),
parentEnvHandle,
context,
functionPtr,
Expand Down Expand Up @@ -866,10 +861,7 @@ class JSFunction : public Callable {
#ifdef HERMESVM_SERIALIZE
JSFunction(Deserializer &d, const VTable *vt);

friend void serializeFunctionImpl(
Serializer &s,
const GCCell *cell,
unsigned overlapSlots);
friend void serializeFunctionImpl(Serializer &s, const GCCell *cell);
friend void FunctionDeserialize(Deserializer &d, CellKind kind);
#endif

Expand Down Expand Up @@ -908,6 +900,10 @@ class JSFunction : public Callable {
public:
static CallableVTable vt;

// We need two more slot for '.length' and '.prototype'
static const PropStorage::size_type NAMED_PROPERTY_SLOTS =
Super::NAMED_PROPERTY_SLOTS + 2;

static bool classof(const GCCell *cell) {
return kindInRange(
cell->getKind(),
Expand Down
13 changes: 2 additions & 11 deletions include/hermes/VM/Domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,6 @@ class RequireContext final : public JSObject {
static const PropStorage::size_type ANONYMOUS_PROPERTY_SLOTS =
Super::ANONYMOUS_PROPERTY_SLOTS + 2;

static constexpr SlotIndex domainPropIndex() {
return numOverlapSlots<RequireContext>() + ANONYMOUS_PROPERTY_SLOTS - 2;
}

static constexpr SlotIndex dirnamePropIndex() {
return numOverlapSlots<RequireContext>() + ANONYMOUS_PROPERTY_SLOTS - 1;
}

static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::RequireContextKind;
}
Expand All @@ -278,14 +270,13 @@ class RequireContext final : public JSObject {

/// \return the domain for this require context.
static Domain *getDomain(Runtime *runtime, RequireContext *self) {
return vmcast<Domain>(
JSObject::getInternalProperty(self, runtime, domainPropIndex()));
return vmcast<Domain>(JSObject::getInternalProperty(self, runtime, 0));
}

/// \return the current dirname for this require context.
static StringPrimitive *getDirname(Runtime *runtime, RequireContext *self) {
return vmcast<StringPrimitive>(
JSObject::getInternalProperty(self, runtime, dirnamePropIndex()));
JSObject::getInternalProperty(self, runtime, 1));
}

private:
Expand Down
14 changes: 3 additions & 11 deletions include/hermes/VM/JSArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ArrayImpl : public JSObject {
#ifdef HERMESVM_SERIALIZE
ArrayImpl(Deserializer &d, const VTable *vt);

friend void
serializeArrayImpl(Serializer &s, const GCCell *cell, unsigned overlapSlots);
friend void serializeArrayImpl(Serializer &s, const GCCell *cell);
#endif

static bool classof(const GCCell *cell) {
Expand Down Expand Up @@ -364,14 +363,7 @@ class JSArray final : public ArrayImpl {
// Object needs to be able to call setLength.
friend class JSObject;

static constexpr SlotIndex jsArrayPropertyCount() {
return numOverlapSlots<JSArray>() + ANONYMOUS_PROPERTY_SLOTS +
NAMED_PROPERTY_SLOTS;
}

static constexpr inline SlotIndex lengthPropIndex() {
return jsArrayPropertyCount() - 1;
}
enum : SlotIndex { LengthPropIndex = 0, JSArrayPropertyCount = 1 };

/// A copy of the ".length" property. We compare every putComputed()
/// index against ".length", and extracting it from property storage every
Expand All @@ -397,7 +389,7 @@ class JSArray final : public ArrayImpl {
static void putLength(JSArray *self, Runtime *runtime, uint32_t newLength) {
self->shadowLength_ = newLength;

namedSlotRef(self, runtime, lengthPropIndex())
namedSlotRef(self, runtime, LengthPropIndex)
.setNonPtr(HermesValue::encodeNumberValue(newLength));
}

Expand Down
8 changes: 3 additions & 5 deletions include/hermes/VM/JSDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class JSDate final : public JSObject {
/// \return the [[PrimitiveValue]] internal property.
static HermesValue getPrimitiveValue(JSObject *self, Runtime *runtime) {
return JSObject::getInternalProperty(
self, runtime, JSDate::primitiveValuePropIndex());
self, runtime, JSDate::primitiveValueIndex);
}

/// Set the [[PrimitiveValue]] internal property.
static void
setPrimitiveValue(JSObject *self, Runtime *runtime, HermesValue value) {
return JSObject::setInternalProperty(
self, runtime, JSDate::primitiveValuePropIndex(), value);
self, runtime, JSDate::primitiveValueIndex, value);
}

protected:
Expand All @@ -61,9 +61,7 @@ class JSDate final : public JSObject {
: JSObject(runtime, &vt.base, parent, clazz) {}

protected:
static constexpr SlotIndex primitiveValuePropIndex() {
return numOverlapSlots<JSDate>() + ANONYMOUS_PROPERTY_SLOTS - 1;
}
static const SlotIndex primitiveValueIndex = ANONYMOUS_PROPERTY_SLOTS - 1;
};

} // namespace vm
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSError.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class JSError final : public JSObject {
return cell->getKind() == CellKind::ErrorKind;
}

static const PropStorage::size_type NAMED_PROPERTY_SLOTS =
Super::NAMED_PROPERTY_SLOTS + 1;

/// Create an Error Object.
static CallResult<HermesValue> create(
Runtime *runtime,
Expand Down
Loading

0 comments on commit 8d57632

Please sign in to comment.