From 1da2e99e0b317911dd2d2bb599f0e132a8d65a13 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 16 Nov 2023 21:43:57 +0000 Subject: [PATCH] Tests WIP 5 --- test/eval.test.js | 298 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 298 insertions(+) diff --git a/test/eval.test.js b/test/eval.test.js index 5b31de78..ac28a27b 100644 --- a/test/eval.test.js +++ b/test/eval.test.js @@ -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;