Skip to content

Commit

Permalink
Serialize/Deserialize JSStringIterator and JSSymbol.
Browse files Browse the repository at this point in the history
Summary: Serialize/Deserialize JStringIterator and JSSymbol.

Reviewed By: avp

Differential Revision: D16663533

fbshipit-source-id: a0cee2903189294b6ba4e0fe5d75d6436dc07303
  • Loading branch information
Lun-Liu authored and facebook-github-bot committed Sep 3, 2019
1 parent 3e4b223 commit 19fd6a2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
13 changes: 13 additions & 0 deletions include/hermes/VM/PrimitiveBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ class JSStringIterator : public JSObject {
Runtime *runtime);

private:
#ifdef HERMESVM_SERIALIZE
explicit JSStringIterator(Deserializer &d);

friend void StringIteratorSerialize(Serializer &s, const GCCell *cell);
friend void StringIteratorDeserialize(Deserializer &d, CellKind kind);
#endif

JSStringIterator(
Runtime *runtime,
JSObject *parent,
Expand Down Expand Up @@ -281,6 +288,12 @@ class JSSymbol final : public PrimitiveBox {
}

protected:
#ifdef HERMESVM_SERIALIZE
explicit JSSymbol(Deserializer &d);

friend void SymbolObjectDeserialize(Deserializer &d, CellKind kind);
#endif

JSSymbol(Runtime *runtime, JSObject *parent, HiddenClass *clazz)
: PrimitiveBox(runtime, &vt.base, parent, clazz) {}
};
Expand Down
33 changes: 22 additions & 11 deletions lib/VM/PrimitiveBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,24 @@ void StringIteratorBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
}

#ifdef HERMESVM_SERIALIZE
JSStringIterator::JSStringIterator(Deserializer &d) : JSObject(d, &vt.base) {
d.readRelocation(&iteratedString_, RelocationKind::GCPointer);
nextIndex_ = d.readInt<uint32_t>();
}

void StringIteratorSerialize(Serializer &s, const GCCell *cell) {
LLVM_DEBUG(
llvm::dbgs()
<< "Serialize function not implemented for StringIterator\n");
auto *self = vmcast<const JSStringIterator>(cell);
JSObject::serializeObjectImpl(s, cell);
s.writeRelocation(self->iteratedString_.get(s.getRuntime()));
s.writeInt<uint32_t>(self->nextIndex_);
s.endObject(cell);
}

void StringIteratorDeserialize(Deserializer &d, CellKind kind) {
LLVM_DEBUG(
llvm::dbgs()
<< "Deserialize function not implemented for StringIterator\n");
assert(kind == CellKind::StringIteratorKind && "Expected StringIterator");
void *mem = d.getRuntime()->alloc(sizeof(JSStringIterator));
auto *cell = new (mem) JSStringIterator(d);
d.endObject(cell);
}
#endif

Expand Down Expand Up @@ -419,15 +427,18 @@ void SymbolObjectBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
}

#ifdef HERMESVM_SERIALIZE
JSSymbol::JSSymbol(Deserializer &d) : PrimitiveBox(d, &vt.base) {}

void SymbolObjectSerialize(Serializer &s, const GCCell *cell) {
LLVM_DEBUG(
llvm::dbgs() << "Serialize function not implemented for SymbolObject\n");
JSObject::serializeObjectImpl(s, cell);
s.endObject(cell);
}

void SymbolObjectDeserialize(Deserializer &d, CellKind kind) {
LLVM_DEBUG(
llvm::dbgs()
<< "Deserialize function not implemented for SymbolObject\n");
assert(kind == CellKind::SymbolObjectKind && "Expected SymbolObject");
void *mem = d.getRuntime()->alloc(sizeof(JSSymbol));
auto *cell = new (mem) JSSymbol(d);
d.endObject(cell);
}
#endif

Expand Down

0 comments on commit 19fd6a2

Please sign in to comment.