Skip to content

Commit

Permalink
Tests WIP 5
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 16, 2023
1 parent 6576d1a commit 1da2e99
Showing 1 changed file with 298 additions and 0 deletions.
298 changes: 298 additions & 0 deletions test/eval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,304 @@ describe('eval', () => {
});
});

describe('`super`', () => {
describe('in object literal method', () => {
itSerializes('with no prefix num change', {
in: `
'use strict';
const obj = {
meth() {
return eval('() => super.meth()');
},
__proto__: {
meth() { return 123; }
}
};
module.exports = obj.meth();
delete obj.meth;
`,
out: `(()=>{
const a=Object.create({meth(){return 123}});
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a)
)(a)(a)
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});

itSerializes('with prefix num change', {
in: `
'use strict';
const obj = {
meth() {
return eval('let livepack_tracker; () => super.meth()');
},
__proto__: {
meth() { return 123; }
}
};
module.exports = obj.meth();
delete obj.meth;
`,
out: `(()=>{
const a=Object.create({meth(){return 123}});
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a)
)(a)(a)
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});
});

describe('in class prototype method', () => {
itSerializes('with no prefix num change', {
in: `
class S {
meth() { return 123; }
}
class C extends S {
meth() {
return eval('() => super.meth()');
}
}
const obj = new C();
module.exports = obj.meth();
delete C.prototype.meth;
`,
out: `(()=>{
const a=(b=>[
b=class C{
constructor(...a){
return Reflect.construct(Object.getPrototypeOf(b),a,b)
}
},
a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a)
])(),
b=a[0],
c=Object,
d=c.setPrototypeOf,
e=class S{},
f=e.prototype,
g=b.prototype;
c.defineProperties(f,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
d(b,e);
d(g,f);
return a[1](c.create(g))
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});

itSerializes('with prefix num change', {
in: `
class S {
meth() { return 123; }
}
class C extends S {
meth() {
return eval('let livepack_tracker; () => super.meth()');
}
}
const obj = new C();
module.exports = obj.meth();
delete C.prototype.meth;
`,
out: `(()=>{
const a=(b=>[
b=class C{
constructor(...a){
return Reflect.construct(Object.getPrototypeOf(b),a,b)
}
},
a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a)
])(),
b=a[0],
c=Object,
d=c.setPrototypeOf,
e=class S{},
f=e.prototype,
g=b.prototype;
c.defineProperties(f,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
d(b,e);
d(g,f);
return a[1](c.create(g))
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});
});

describe('in class static method', () => {
itSerializes('with no prefix num change', {
in: `
class S {
static meth() { return 123; }
}
class C extends S {
static meth() {
return eval('() => super.meth()');
}
}
module.exports = C.meth();
delete C.meth;
`,
out: `(()=>{
const a=(b=>[
b=class C{
constructor(...a){
return Reflect.construct(Object.getPrototypeOf(b),a,b)
}
},
a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a)
])(),
b=a[0],
c=Object,
d=c.setPrototypeOf,
e=c.defineProperties(
class S{},
{meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}}
);
d(b,e);
d(b.prototype,e.prototype);
return a[1](b)
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});

itSerializes('with prefix num change', {
in: `
class S {
static meth() { return 123; }
}
class C extends S {
static meth() {
return eval('let livepack_tracker; () => super.meth()');
}
}
module.exports = C.meth();
delete C.meth;
`,
out: `(()=>{
const a=(b=>[
b=class C{
constructor(...a){
return Reflect.construct(Object.getPrototypeOf(b),a,b)
}
},
a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a)
])(),
b=a[0],
c=Object,
d=c.setPrototypeOf,
e=c.defineProperties(
class S{},
{meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}}
);
d(b,e);
d(b.prototype,e.prototype);
return a[1](b)
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});
});

describe('in class constructor', () => {
itSerializes('with no prefix num change', {
in: `
class S {
meth() { return 123; }
}
class C extends S {
constructor(module, exports, obj) {
super();
this.f = eval('() => super.meth()');
}
}
const obj = new C();
delete C.prototype.meth;
module.exports = obj.f;
delete obj.f;
`,
out: `(()=>{
const a=class S{},
b=a.prototype,
c=Object,
d=(0,eval)("\\"use strict\\";S=>_b=>[_b=class C{constructor(module,exports,obj){const _a=Reflect.construct(Object.getPrototypeOf(_b),[],_b);_a.f=eval(\\"() => super.meth()\\");return _a}},a=>()=>Reflect.get(Object.getPrototypeOf(_b.prototype),\\"meth\\",a).call(a)]")(a)(),
e=d[0],
f=c.setPrototypeOf,
g=e.prototype;
c.defineProperties(b,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
f(e,a);
f(g,b);
return d[1](c.create(g))
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});

itSerializes('with prefix num change', {
in: `
class S {
meth() { return 123; }
}
class C extends S {
constructor(module, exports, obj) {
super();
this.f = eval('let livepack_tracker; () => super.meth()');
}
}
const obj = new C();
delete C.prototype.meth;
module.exports = obj.f;
delete obj.f;
`,
out: `(()=>{
const a=class S{},
b=a.prototype,
c=Object,
d=(0,eval)("\\"use strict\\";S=>_b=>[_b=class C{constructor(module,exports,obj){const _a=Reflect.construct(Object.getPrototypeOf(_b),[],_b);_a.f=eval(\\"let livepack_tracker; () => super.meth()\\");return _a}},a=>()=>Reflect.get(Object.getPrototypeOf(_b.prototype),\\"meth\\",a).call(a)]")(a)(),
e=d[0],
f=c.setPrototypeOf,
g=e.prototype;
c.defineProperties(b,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
f(e,a);
f(g,b);
return d[1](c.create(g))
})()`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn()).toBe(123);
}
});
});
});

describe('functions', () => {
const input = `
const extA = 1;
Expand Down

0 comments on commit 1da2e99

Please sign in to comment.