Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/comlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,18 @@ export function expose(
};
const argumentList = (ev.data.argumentList || []).map(fromWireValue);
let returnValue;

const getDeepValue = (obj: any, path: string[]) =>
path.reduce((current, key) => {
if (current == null || !(key in current)) {
throw new Error(`Invalid path access: property '${key}' is undefined in path '${path.join(".")}'`);
}
return current[key];
}, obj);

try {
const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);
const rawValue = path.reduce((obj, prop) => obj[prop], obj);
const parent = getDeepValue(obj, path.slice(0, -1));
const rawValue = getDeepValue(obj, path);
switch (type) {
case MessageType.GET:
{
Expand Down