Skip to content

Commit

Permalink
fix(kernel): properly deserialize structs passed in byref (#554)
Browse files Browse the repository at this point in the history
The deserializer mistakingly used `objectReference` instead of `isObjRef` when trying to identify this case.

Test was added to verify this fix.

Fixes #553

Co-authored-by: Romain Muller <rmuller@amazon.com>
  • Loading branch information
Elad Ben-Israel and RomainMuller authored Jun 25, 2019
1 parent 415cbdd commit 1e89aab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/jsii-kernel/lib/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,9 @@ export const SERIALIZERS: {[k: string]: Serializer} = {

// Similarly to other end, we might be getting a reference type where we're
// expecting a value type. Accept this for now.
const prevRef = objectReference(value);
if (prevRef) {
if (isObjRef(value)) {
host.debug('Expected value type but got reference type, accepting for now (awslabs/jsii#400)');
return prevRef;
return host.objects.findObject(value).instance;
}

const namedType = host.lookupType((optionalValue.type as spec.NamedTypeReference).fqn);
Expand Down
8 changes: 8 additions & 0 deletions packages/jsii-kernel/test/test.kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,14 @@ defineTest('erased base: can receive an instance of private type', async (test,
test.deepEqual(objref.result, { [api.TOKEN_REF]: 'jsii-calc.JSII417PublicBaseOfBase@10000' });
});

defineTest('deserialize a struct by reference', async (test, sandbox) => {
sandbox.callbackHandler = makeSyncCallbackHandler(() => 'xoxoxox');
const objref = sandbox.create({ fqn: 'Object', overrides: [ { property: 'field' } ] });
const consumer = sandbox.create({ fqn: 'jsii-calc.OptionalStructConsumer', args: [ objref ] });
const value = sandbox.get({ objref: consumer, property: 'fieldValue' });
test.deepEqual(value, { value: 'xoxoxox' });
});

// =================================================================================================

const testNames: { [name: string]: boolean } = { };
Expand Down

0 comments on commit 1e89aab

Please sign in to comment.