[sdk/nodejs] Fix a bug in closure serialization. (#6999)

Co-authored-by: Komal <komal@pulumi.com>
Co-authored-by: Luke Hoban <luke@pulumi.com>
This commit is contained in:
PND 2021-07-16 10:20:09 +09:00 committed by GitHub
parent cb564608b1
commit c6062ea1d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 137 additions and 63 deletions

View file

@ -1,11 +1,11 @@
### Improvements
- [schema] - Support for unmarshaling/marshaling schemas from/to YAML
[#7509](https://github.com/pulumi/pulumi/pull/7509)
- [codegen/python] - Emit dynamic config-getters.
[#7447](https://github.com/pulumi/pulumi/pull/7447)
### Bug Fixes
- [sdk/nodejs] Fix a bug in closure serialization.
[#6999](https://github.com/pulumi/pulumi/pull/6999)

View file

@ -486,9 +486,11 @@ async function analyzeFunctionInfoAsync(
continue;
}
functionInfo.env.set(
await getOrCreateEntryAsync(getNameOrSymbol(descriptor), undefined, context, serialize, logInfo),
{ entry: await getOrCreateEntryAsync(funcProp, undefined, context, serialize, logInfo) });
const keyEntry = await getOrCreateEntryAsync(getNameOrSymbol(descriptor), undefined, context, serialize, logInfo);
const valEntry = await getOrCreateEntryAsync(funcProp, undefined, context, serialize, logInfo);
const propertyInfo = await createPropertyInfoAsync(descriptor, context, serialize, logInfo);
functionInfo.env.set(keyEntry, { info: propertyInfo, entry: valEntry });
}
const superEntry = context.classInstanceMemberToSuperEntry.get(func) ||
@ -779,6 +781,28 @@ async function isDefaultFunctionPrototypeAsync(func: Function, prototypeProp: an
return false;
}
async function createPropertyInfoAsync(
descriptor: ClosurePropertyDescriptor,
context: Context,
serialize: (o: any) => boolean,
logInfo: boolean | undefined): Promise<PropertyInfo> {
const propertyInfo = <PropertyInfo>{ hasValue: descriptor.value !== undefined };
propertyInfo.configurable = descriptor.configurable;
propertyInfo.enumerable = descriptor.enumerable;
propertyInfo.writable = descriptor.writable;
if (descriptor.get) {
propertyInfo.get = await getOrCreateEntryAsync(
descriptor.get, undefined, context, serialize, logInfo);
}
if (descriptor.set) {
propertyInfo.set = await getOrCreateEntryAsync(
descriptor.set, undefined, context, serialize, logInfo);
}
return propertyInfo;
}
function getOrCreateNameEntryAsync(
name: string, capturedObjectProperties: CapturedPropertyChain[] | undefined,
context: Context,
@ -996,7 +1020,7 @@ async function getOrCreateEntryAsync(
}
object.env.set(keyEntry, <any>undefined);
const propertyInfo = await createPropertyInfoAsync(descriptor);
const propertyInfo = await createPropertyInfoAsync(descriptor, context, serialize, logInfo);
const prop = await getOwnPropertyAsync(obj, descriptor);
const valEntry = await getOrCreateEntryAsync(
prop, undefined, context, serialize, logInfo);
@ -1145,7 +1169,7 @@ async function getOrCreateEntryAsync(
const desc = Object.getOwnPropertyDescriptor(current, key);
if (desc) {
const closurePropDescriptor = createClosurePropertyDescriptor(key, desc);
const propertyInfo = await createPropertyInfoAsync(closurePropDescriptor);
const propertyInfo = await createPropertyInfoAsync(closurePropDescriptor, context, serialize, logInfo);
return propertyInfo;
}
}
@ -1153,23 +1177,6 @@ async function getOrCreateEntryAsync(
return undefined;
}
async function createPropertyInfoAsync(descriptor: ClosurePropertyDescriptor): Promise<PropertyInfo> {
const propertyInfo = <PropertyInfo>{ hasValue: descriptor.value !== undefined };
propertyInfo.configurable = descriptor.configurable;
propertyInfo.enumerable = descriptor.enumerable;
propertyInfo.writable = descriptor.writable;
if (descriptor.get) {
propertyInfo.get = await getOrCreateEntryAsync(
descriptor.get, undefined, context, serialize, logInfo);
}
if (descriptor.set) {
propertyInfo.set = await getOrCreateEntryAsync(
descriptor.set, undefined, context, serialize, logInfo);
}
return propertyInfo;
}
function usesNonLexicalThis(localEntry: Entry | undefined) {
return localEntry && localEntry.function && localEntry.function.usesNonLexicalThis;
}
@ -1414,7 +1421,9 @@ async function getOwnPropertyDescriptors(obj: any): Promise<ClosurePropertyDescr
}
async function getOwnPropertyAsync(obj: any, descriptor: ClosurePropertyDescriptor): Promise<any> {
return obj[getNameOrSymbol(descriptor)];
return (descriptor.get || descriptor.set) ?
undefined :
obj[getNameOrSymbol(descriptor)];
}
async function getPropertyAsync(obj: any, name: string): Promise<any> {

View file

@ -1238,7 +1238,7 @@ return function () { return mutable; };
var __v = {};
var __v_d_proto = {};
__f1.prototype = __v_d_proto;
Object.defineProperty(__f1, "prototype", { value: __v_d_proto });
Object.defineProperty(__v_d_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__v_d_proto, "apply", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__v_d_proto, "get", { configurable: true, writable: true, value: __f3 });
@ -1309,7 +1309,7 @@ return function () { console.log(v); };
var __v = {};
var __v_d1_proto = {};
__f1.prototype = __v_d1_proto;
Object.defineProperty(__f1, "prototype", { value: __v_d1_proto });
Object.defineProperty(__v_d1_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__v_d1_proto, "apply", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__v_d1_proto, "get", { configurable: true, writable: true, value: __f3 });
@ -1391,7 +1391,7 @@ return function () { console.log(v); };
var __v = {};
var __v_d1_proto = {};
__f1.prototype = __v_d1_proto;
Object.defineProperty(__f1, "prototype", { value: __v_d1_proto });
Object.defineProperty(__v_d1_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__v_d1_proto, "apply", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__v_d1_proto, "get", { configurable: true, writable: true, value: __f3 });
@ -1489,7 +1489,7 @@ var __v = {};
var __v_x = {a: 1, b: true};
__v.x = __v_x;
var __v_o1_proto = {};
__f1.prototype = __v_o1_proto;
Object.defineProperty(__f1, "prototype", { value: __v_o1_proto });
Object.defineProperty(__v_o1_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__v_o1_proto, "apply", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__v_o1_proto, "get", { configurable: true, writable: true, value: __f3 });
@ -1812,7 +1812,7 @@ __outer_b[0] = __outer;
__outer.b = __outer_b;
__C_prototype.m = __f1;
__C_prototype.n = __f2;
__C.prototype = __C_prototype;
Object.defineProperty(__C, "prototype", { writable: true, value: __C_prototype });
__C.m = __f3;
function __C() {
@ -1891,8 +1891,8 @@ var __outer_b = [];
__outer_b[0] = __outer;
__outer.b = __outer_b;
Object.defineProperty(__f1_prototype, "n", { configurable: true, writable: true, value: __f3 });
__f1.prototype = __f1_prototype;
__f1.s = __f4;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
Object.defineProperty(__f1, "s", { configurable: true, writable: true, value: __f4 });
function __f1() {
return (function() {
@ -1966,8 +1966,8 @@ var __f1_prototype = {};
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, "m", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__f1_prototype, "n", { configurable: true, writable: true, value: __f3 });
__f1.prototype = __f1_prototype;
__f1.s = __f4;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
Object.defineProperty(__f1, "s", { configurable: true, writable: true, value: __f4 });
function __f1() {
return (function() {
@ -2043,8 +2043,8 @@ var __f1_prototype = {};
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, "m", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__f1_prototype, "n", { configurable: true, writable: true, value: __f3 });
__f1.prototype = __f1_prototype;
__f1.s = __f4;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
Object.defineProperty(__f1, "s", { configurable: true, writable: true, value: __f4 });
function __f1() {
return (function() {
@ -2616,7 +2616,7 @@ return () => { return 1; };
expectText: `exports.handler = __f;
var __f_prototype = Object.create(Object.getPrototypeOf((function*(){}).prototype));
__f.prototype = __f_prototype;
Object.defineProperty(__f, "prototype", { writable: true, value: __f_prototype });
Object.setPrototypeOf(__f, Object.getPrototypeOf(function*(){}));
function __f() {
@ -2641,7 +2641,7 @@ return function* /*f*/() { yield 1; };
expectText: `exports.handler = __f0;
var __f0_prototype = Object.create(Object.getPrototypeOf((function*(){}).prototype));
__f0.prototype = __f0_prototype;
Object.defineProperty(__f0, "prototype", { writable: true, value: __f0_prototype });
Object.setPrototypeOf(__f0, Object.getPrototypeOf(function*(){}));
function __f0() {
@ -2682,7 +2682,7 @@ return function* () { yield 1; };
var __f1_prototype = {};
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, "foo", { configurable: true, get: __f2, set: __f3 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
function __f1() {
return (function() {
@ -2720,6 +2720,71 @@ return function /*foo*/(v) {
}).apply(undefined, undefined).apply(this, arguments);
}
function __f0() {
return (function() {
with({ C: __f1 }) {
return () => C;
}
}).apply(undefined, undefined).apply(this, arguments);
}
`,
});
}
{
class C {
static get foo() {
throw new Error("This getter function should not be evaluated while closure serialization.")
}
static set foo(v: number) {
throw new Error("This setter function should not be evaluated while closure serialization.")
}
}
cases.push({
title: "Test getter/setter #2",
func: () => C,
expectText: `exports.handler = __f0;
Object.defineProperty(__f1, "foo", { configurable: true, get: __f2, set: __f3 });
function __f1() {
return (function() {
with({ }) {
return function /*constructor*/() { };
}
}).apply(undefined, undefined).apply(this, arguments);
}
function __f2() {
return (function() {
with({ }) {
return function /*foo*/() {
throw new Error("This getter function should not be evaluated while closure serialization.");
};
}
}).apply(undefined, undefined).apply(this, arguments);
}
function __f3(__0) {
return (function() {
with({ }) {
return function /*foo*/(v) {
throw new Error("This setter function should not be evaluated while closure serialization.");
};
}
}).apply(undefined, undefined).apply(this, arguments);
}
function __f0() {
return (function() {
with({ C: __f1 }) {
@ -2749,7 +2814,7 @@ return () => C;
var __f1_prototype = {};
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, "method name", { configurable: true, writable: true, value: __f2 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
function __f1() {
return (function() {
@ -2806,7 +2871,7 @@ Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writa
var __sym = Object.create(global.Symbol.prototype);
Object.defineProperty(__f1_prototype, "getSym", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__f1_prototype, __sym, { configurable: true, writable: true, value: __f3 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
function __f1() {
return (function() {
@ -2868,7 +2933,7 @@ return () => C;
var __f1_prototype = {};
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, Symbol.iterator, { configurable: true, writable: true, value: __f2 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
function __f1() {
return (function() {
@ -2938,12 +3003,12 @@ var __f2_prototype = {};
Object.defineProperty(__f2_prototype, "constructor", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__f2_prototype, "dMethod", { configurable: true, writable: true, value: __f3 });
Object.defineProperty(__f2_prototype, "dVirtual", { configurable: true, writable: true, value: __f4 });
__f2.prototype = __f2_prototype;
Object.defineProperty(__f2, "prototype", { value: __f2_prototype });
var __f1_prototype = Object.create(__f2_prototype);
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, "cMethod", { configurable: true, writable: true, value: __f5 });
Object.defineProperty(__f1_prototype, "dVirtual", { configurable: true, writable: true, value: __f6 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
Object.setPrototypeOf(__f1, __f2);
function __f2(__0) {
@ -3062,16 +3127,16 @@ return () => C;
var __f3_prototype = {};
Object.defineProperty(__f3_prototype, "constructor", { configurable: true, writable: true, value: __f3 });
Object.defineProperty(__f3_prototype, "method", { configurable: true, writable: true, value: __f4 });
__f3.prototype = __f3_prototype;
Object.defineProperty(__f3, "prototype", { value: __f3_prototype });
var __f2_prototype = Object.create(__f3_prototype);
Object.defineProperty(__f2_prototype, "constructor", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__f2_prototype, "method", { configurable: true, writable: true, value: __f5 });
__f2.prototype = __f2_prototype;
Object.defineProperty(__f2, "prototype", { value: __f2_prototype });
Object.setPrototypeOf(__f2, __f3);
var __f1_prototype = Object.create(__f2_prototype);
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, "method", { configurable: true, writable: true, value: __f6 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
Object.setPrototypeOf(__f1, __f2);
function __f3(__0) {
@ -3192,16 +3257,16 @@ var __f3_prototype = {};
Object.defineProperty(__f3_prototype, "constructor", { configurable: true, writable: true, value: __f3 });
var __f3_prototype_sym = Object.create(global.Symbol.prototype);
Object.defineProperty(__f3_prototype, __f3_prototype_sym, { configurable: true, writable: true, value: __f4 });
__f3.prototype = __f3_prototype;
Object.defineProperty(__f3, "prototype", { value: __f3_prototype });
var __f2_prototype = Object.create(__f3_prototype);
Object.defineProperty(__f2_prototype, "constructor", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__f2_prototype, __f3_prototype_sym, { configurable: true, writable: true, value: __f5 });
__f2.prototype = __f2_prototype;
Object.defineProperty(__f2, "prototype", { value: __f2_prototype });
Object.setPrototypeOf(__f2, __f3);
var __f1_prototype = Object.create(__f2_prototype);
Object.defineProperty(__f1_prototype, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__f1_prototype, __f3_prototype_sym, { configurable: true, writable: true, value: __f6 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
Object.setPrototypeOf(__f1, __f2);
function __f3(__0) {
@ -3312,11 +3377,11 @@ return () => C;
func: () => B,
expectText: `exports.handler = __f0;
__f2.method = __f3;
Object.defineProperty(__f2, "method", { configurable: true, writable: true, value: __f3 });
var __f2_sym = Object.create(global.Symbol.prototype);
__f2[__f2_sym] = __f4;
__f1.method = __f5;
__f1[__f2_sym] = __f6;
Object.defineProperty(__f2, __f2_sym, { configurable: true, writable: true, value: __f4 });
Object.defineProperty(__f1, "method", { configurable: true, writable: true, value: __f5 });
Object.defineProperty(__f1, __f2_sym, { configurable: true, writable: true, value: __f6 });
Object.setPrototypeOf(__f1, __f2);
function __f2(__0) {
@ -4341,7 +4406,7 @@ return function /*f1*/() {
expectText: `exports.handler = __f0;
var __o_proto = {};
__f1.prototype = __o_proto;
Object.defineProperty(__f1, "prototype", { value: __o_proto });
Object.defineProperty(__o_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__o_proto, "m", { configurable: true, writable: true, value: __f2 });
var __o = Object.create(__o_proto);
@ -4404,7 +4469,7 @@ return function () { o.m(); };
expectText: `exports.handler = __f0;
var __o_proto = {};
__f1.prototype = __o_proto;
Object.defineProperty(__f1, "prototype", { value: __o_proto });
Object.defineProperty(__o_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__o_proto, "m", { configurable: true, writable: true, value: __f2 });
var __o = Object.create(__o_proto);
@ -4564,11 +4629,11 @@ return function () { o["m"](); };
expectText: `exports.handler = __f0;
var __o_proto_proto = {};
__f1.prototype = __o_proto_proto;
Object.defineProperty(__f1, "prototype", { value: __o_proto_proto });
Object.defineProperty(__o_proto_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__o_proto_proto, "m", { configurable: true, writable: true, value: __f2 });
var __o_proto = Object.create(__o_proto_proto);
__f3.prototype = __o_proto;
Object.defineProperty(__f3, "prototype", { value: __o_proto });
Object.setPrototypeOf(__f3, __f1);
Object.defineProperty(__o_proto, "constructor", { configurable: true, writable: true, value: __f3 });
Object.defineProperty(__o_proto, "n", { configurable: true, writable: true, value: __f4 });
@ -4661,11 +4726,11 @@ return function () { o.m(); };
expectText: `exports.handler = __f0;
var __o_proto_proto = {};
__f1.prototype = __o_proto_proto;
Object.defineProperty(__f1, "prototype", { value: __o_proto_proto });
Object.defineProperty(__o_proto_proto, "constructor", { configurable: true, writable: true, value: __f1 });
Object.defineProperty(__o_proto_proto, "m", { configurable: true, writable: true, value: __f2 });
var __o_proto = Object.create(__o_proto_proto);
__f3.prototype = __o_proto;
Object.defineProperty(__f3, "prototype", { value: __o_proto });
Object.setPrototypeOf(__f3, __f1);
Object.defineProperty(__o_proto, "constructor", { configurable: true, writable: true, value: __f3 });
Object.defineProperty(__o_proto, "n", { configurable: true, writable: true, value: __f4 });
@ -6043,7 +6108,7 @@ return function () { typescript.parseCommandLine([""]); };
expectText: `exports.handler = __f0;
var __testConfig_proto = {};
__f1.prototype = __testConfig_proto;
Object.defineProperty(__f1, "prototype", { value: __testConfig_proto });
Object.defineProperty(__testConfig_proto, "constructor", { configurable: true, writable: true, value: __f1 });
var __config = {["test:TestingKey1"]: "TestingValue1", ["test:TestingKey2"]: "TestingValue2"};
var __runtimeConfig_1 = {getConfig: __getConfig};
@ -6134,7 +6199,7 @@ var __config = {["test:TestingKey1"]: "TestingValue1", ["test:TestingKey2"]: "Te
var __runtimeConfig_1 = {getConfig: __getConfig};
Object.defineProperty(__f1_prototype, "get", { configurable: true, writable: true, value: __f2 });
Object.defineProperty(__f1_prototype, "fullKey", { configurable: true, writable: true, value: __f3 });
__f1.prototype = __f1_prototype;
Object.defineProperty(__f1, "prototype", { value: __f1_prototype });
var __deploymentOnlyModule = {Config: __f1};
function __f1(__0) {