Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect closure serialization when object referenced through different functions. #2497

Merged
merged 13 commits into from
Feb 28, 2019

Conversation

CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Feb 28, 2019

@CyrusNajmabadi CyrusNajmabadi changed the title WIP: Incorrect closure serialization when object referenced through different functions. Incorrect closure serialization when object referenced through different functions. Feb 28, 2019
@@ -4801,7 +4801,7 @@ return function () { console.log(o.b()); console.log(o.b.name); };
expectText: `exports.handler = __f0;

var __o2 = {};
var __o2_b = {d: 3, c: 2};
var __o2_b = {c: 2, d: 3};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is equivalent to before. t he change in behavior is due to how we now clear and re-add. because of that, we restore this to the same order as the original object (i.e. 'c' then 'd', instead of 'd' then 'c').

@CyrusNajmabadi
Copy link
Contributor Author

@swgillespie @lukehoban PTAL. Thanks!

const objectInfo: ObjectInfo = entry.object || { env: new Map() };
entry.object = objectInfo;
const environment = entry.object.env;
entry.object = entry.object || { env: new Map() };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just simplification.

return false;
} else {
return await serializeSomeObjectPropertiesAsync(environment, localCapturedPropertyChains);
return await serializeSomeObjectPropertiesAsync(entry.object, localCapturedPropertyChains);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm passing the higher up object to prevent unnecessary null checks below.

}
object.env.set(keyEntry, <any>undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the core change to what we had before. previously, we said "ah, we've marker this prop, don't go into it again". This was done both to prevent infinite recursion, and to avoid serializing a prop we thought we'd already serialized.

Now, all we do is set the marking to prevent infinite recursion. if we see the prop a second time otherwise, then we still re-serialize it. This way, if we have a differnet set of sub-props to serialize that will ensure that that happens.

const proto = Object.getPrototypeOf(obj);
if (proto !== Object.prototype) {
entry.object!.proto = await getOrCreateEntryAsync(
object.proto = await getOrCreateEntryAsync(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could avoid the null checks here because entry.proto is the value passed in, and is known to be non-null.

continue;
}
object.env.set(keyEntry, <any>undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same fix as above. we prevent infinite recursion. but we don't stop re-examination of props we've already seen.

}
`,
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added several different permutations of visiting different property chains (of differing lengths), from different contexts. Def found several issues. But all these cases now work properly.

Copy link
Contributor

@swgillespie swgillespie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CyrusNajmabadi CyrusNajmabadi merged commit 3d1df98 into master Feb 28, 2019
@pulumi-bot pulumi-bot deleted the incorrectSerialization branch February 28, 2019 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants