Skip to content

Commit

Permalink
Instrumentation check WIP 3
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jan 4, 2023
1 parent d87b5fc commit 3732135
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions lib/instrument/visitors/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ function visitObjectMembers(objectNode, memberNodes, parent, key, state) {
}
}

// If `super` used in a method, queue function to add temp var for object as `super` target
const superVarNode = getSuperVarNode(superBlock);
if (superVarNode) state.secondPass(wrapWithSuperTargetVar, objectNode, parent, key, superVarNode);
// If `super` used in a method, add temp var for object as `super` target in 2nd pass
state.secondPass(wrapWithSuperTargetVar, objectNode, parent, key, superBlock);
}

/**
Expand Down Expand Up @@ -156,14 +155,15 @@ function visitObjectMethod(node, memberNodes, index, computedMethodKeys, state)
}

/**
* Wrap object expression to capture value of class in temp var,
* which can be used in tracker functions to pass `super` target to serializer.
* If `super` has been used in a method of the object, wrap object expression to capture value
* of object in temp var, which can be used in tracker functions to pass `super` target to serializer.
* @param {Object} objectNode - Object expression AST node
* @param {Object|Array} parent - Parent AST node/container
* @param {string|number} key - Node's key on parent AST node/container
* @param {Object} superVarNode - Temp var node for `super` target
* @param {Object} superBlock - `super` block object
* @returns {undefined}
*/
function wrapWithSuperTargetVar(objectNode, parent, key, superVarNode) {
parent[key] = t.assignmentExpression('=', superVarNode, objectNode);
function wrapWithSuperTargetVar(objectNode, parent, key, superBlock) {
const superVarNode = getSuperVarNode(superBlock);
if (superVarNode) parent[key] = t.assignmentExpression('=', superVarNode, objectNode);
}
4 changes: 2 additions & 2 deletions test/functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6146,8 +6146,8 @@ describe('Functions', () => {
out: `(()=>{
const a={extA:1},b={extB:2};
return(
(e,f,g,h)=>(a=f,b=g,c=e,d=h)=>[a,b,c,d]
)({ctx:3},a,b,function(){return arguments}(a,b))
(e,f,g,h)=>(a=e,b=f,c=g,d=h)=>[a,b,c,d]
)(a,b,{ctx:3},function(){return arguments}(a,b))
})()`,
validate(fn) {
expect(fn).toBeFunction();
Expand Down
6 changes: 3 additions & 3 deletions test/misc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Internal vars created by instrumentation do not interfere with code',

itSerializes('`temp`', {
in: () => Object.setPrototypeOf(
{x() { return super.x(typeof livepack_temp_21); }}, // eslint-disable-line camelcase
{x() { return super.x(typeof livepack_temp_27); }}, // eslint-disable-line camelcase
{x(v) { return v; }}
),
out: `(()=>{
Expand All @@ -58,7 +58,7 @@ describe('Internal vars created by instrumentation do not interfere with code',
b=>a=b,
{
x(){
return Reflect.get(Object.getPrototypeOf(a),"x",this).call(this,typeof livepack_temp_21)
return Reflect.get(Object.getPrototypeOf(a),"x",this).call(this,typeof livepack_temp_27)
}
}.x
]
Expand All @@ -76,7 +76,7 @@ describe('Internal vars created by instrumentation do not interfere with code',
// NB code for this file is injected into `transpiledFiles` in babel transform
// (see `test/support/transform.js`)
// eslint-disable-next-line no-useless-concat
expect(transpiledFiles[__filename]).toInclude('Object.setPrototypeOf' + '(livepack1_temp_21 =');
expect(transpiledFiles[__filename]).toInclude('Object.setPrototypeOf' + '(livepack1_temp_27 =');

expect(obj.x()).toBe('undefined');
}
Expand Down

0 comments on commit 3732135

Please sign in to comment.