Skip to content

Commit

Permalink
use HydratingObject instead of ConstructObject
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Dec 23, 2023
1 parent 51d00c6 commit 911db9d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/types/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function defineClassStructMethods(target, info) {
}
}

/** @type number | null */
export const _HydratingObject = null;

export function createObject(info, gType) {
const ParentClass = getParentClass(info) ?? Object;

Expand All @@ -106,20 +109,22 @@ export function createObject(info, gType) {
super(props);

if (gType == GType.OBJECT) {
const gType = Reflect.getOwnMetadata("gi:gtype", this.constructor);

if (!gType) {
throw new Error("Tried to construct an object without a GType");
}
if (_HydratingObject !== null) {
const gType = Reflect.getOwnMetadata("gi:gtype", this.constructor);

ConstructContext.push(gType);
if (!gType) {
throw new Error("Tried to construct an object without a GType");
}

Reflect.defineMetadata("gi:ref", g.object.new(gType, null), this);
Object.entries(props).forEach(([key, value]) => {
this[key] = value;
});
Reflect.defineMetadata("gi:ref", g.object.new(gType, null), this);
Object.entries(props).forEach(([key, value]) => {
this[key] = value;
});
} else {
Reflect.defineMetadata("gi:ref", _HydratingObject, this);

ConstructContext.pop();
_HydratingObject = null;
}
}
}
};
Expand Down

0 comments on commit 911db9d

Please sign in to comment.