Skip to content

Commit

Permalink
Tests WIP 1
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 26, 2023
1 parent 7246a32 commit b723547
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 500 deletions.
36 changes: 12 additions & 24 deletions test/arrays.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,9 @@ describe('Arrays', () => {
out: `(()=>{
const a=Object.setPrototypeOf,
b=Array,
c=(b=>b=class A{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
d=c.prototype;
a(c,b);
a(d,b.prototype);
return a([],d)
c=a(class A extends class{}{},b).prototype;
a(c,b.prototype);
return a([],c)
})()`,
validate(arr) {
expect(arr).toBeArrayOfSize(0);
Expand All @@ -367,13 +363,9 @@ describe('Arrays', () => {
out: `(()=>{
const a=Object.setPrototypeOf,
b=Array,
c=(b=>b=class A{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
d=c.prototype;
a(c,b);
a(d,b.prototype);
return a([1,2,3],d)
c=a(class A extends class{}{},b).prototype;
a(c,b.prototype);
return a([1,2,3],c)
})()`,
validate(arr) {
expect(arr).toBeArrayOfSize(3);
Expand All @@ -399,16 +391,12 @@ describe('Arrays', () => {
out: `(()=>{
const a=Object.setPrototypeOf,
b=Array,
c=(b=>b=class A{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
d=c.prototype,
e=a([,2],d);
a(c,b);
a(d,b.prototype);
e[0]=e;
e[2]=e;
return e
c=a(class A extends class{}{},b).prototype,
d=a([,2],c);
a(c,b.prototype);
d[0]=d;
d[2]=d;
return d
})()`,
validate(arr) {
expect(arr).toBeArrayOfSize(3);
Expand Down
40 changes: 12 additions & 28 deletions test/boxed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,9 @@ describe('Boxed Strings', () => {
out: `(()=>{
const a=String,
b=Object.setPrototypeOf,
c=(b=>b=class S{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
d=c.prototype;
b(c,a);
b(d,a.prototype);
return b(new a("abc"),d)
c=b(class S extends class{}{},a).prototype;
b(c,a.prototype);
return b(new a("abc"),c)
})()`,
validate(str) {
expect(typeof str).toBe('object');
Expand Down Expand Up @@ -146,13 +142,9 @@ describe('Boxed Booleans', () => {
out: `(()=>{
const a=Boolean,
b=Object.setPrototypeOf,
c=(b=>b=class B{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
d=c.prototype;
b(c,a);
b(d,a.prototype);
return b(new a(1),d)
c=b(class B extends class{}{},a).prototype;
b(c,a.prototype);
return b(new a(1),c)
})()`,
validate(bool) {
expect(typeof bool).toBe('object');
Expand Down Expand Up @@ -282,13 +274,9 @@ describe('Boxed Numbers', () => {
out: `(()=>{
const a=Number,
b=Object.setPrototypeOf,
c=(b=>b=class N{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
d=c.prototype;
b(c,a);
b(d,a.prototype);
return b(new a(1),d)
c=b(class N extends class{}{},a).prototype;
b(c,a.prototype);
return b(new a(1),c)
})()`,
validate(num) {
expect(typeof num).toBe('object');
Expand Down Expand Up @@ -368,13 +356,9 @@ describe('Boxed BigInts', () => {
const a=Object,
b=a.setPrototypeOf,
c=BigInt,
d=(b=>b=class B{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
e=d.prototype;
b(d,c);
b(e,c.prototype);
return b(a(100n),e)
d=b(class B extends class{}{},c).prototype;
b(d,c.prototype);
return b(a(100n),d)
})()`,
validate(bigInt) {
expect(typeof bigInt).toBe('object');
Expand Down
25 changes: 6 additions & 19 deletions test/buffers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ describe('Buffers', () => {
out: `(()=>{
const a=Buffer,
b=Object.setPrototypeOf,
c=(b=>b=class B{
constructor(...a){return Reflect.construct(Object.getPrototypeOf(b),a,b)}
})(),
d=c.prototype;
b(c,a);
b(d,a.prototype);
return b(a.from("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=","base64"),d)
c=b(class B extends class{}{},a).prototype;
b(c,a.prototype);
return b(a.from("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=","base64"),c)
})()`,
validate(buf) {
expect(buf).toBeInstanceOf(Buffer);
Expand Down Expand Up @@ -377,18 +373,9 @@ describe('Buffers', () => {
out: `(()=>{
const a=Uint8Array,
b=Object.setPrototypeOf,
c=(b=>b=class B{
constructor(...a){
return Reflect.construct(Object.getPrototypeOf(b),a,b)
}
})(),
d=c.prototype;
b(c,a);
b(d,a.prototype);
return b(
new a([100,200]),
d
)
c=b(class B extends class{}{},a).prototype;
b(c,a.prototype);
return b(new a([100,200]),c)
})()`,
validate(buf) {
expect(buf).toBeInstanceOf(Uint8Array);
Expand Down
162 changes: 70 additions & 92 deletions test/eval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1376,26 +1376,19 @@ describe('eval', () => {
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,{
const a=Object,
b=a.setPrototypeOf,
c=class S{},
d=c.prototype,
e=b(class C extends class{}{},c),
f=e.prototype;
a.defineProperties(d,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
d(b,e);
d(g,f);
return a[1](c.create(g))
b(f,d);
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a)
)(e)(a.create(f))
})()`,
validate(fn) {
expect(fn).toBeFunction();
Expand All @@ -1418,26 +1411,19 @@ describe('eval', () => {
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,{
const a=Object,
b=a.setPrototypeOf,
c=class S{},
d=c.prototype,
e=b(class C extends class{}{},c),
f=e.prototype;
a.defineProperties(d,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
d(b,e);
d(g,f);
return a[1](c.create(g))
b(f,d);
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a)
)(e)(a.create(f))
})()`,
validate(fn) {
expect(fn).toBeFunction();
Expand All @@ -1461,24 +1447,17 @@ describe('eval', () => {
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(
const a=Object,
b=a.setPrototypeOf,
c=a.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)
),
d=b(class C extends class{}{},c);
b(d.prototype,c.prototype);
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a)
)(d)(d)
})()`,
validate(fn) {
expect(fn).toBeFunction();
Expand All @@ -1500,24 +1479,17 @@ describe('eval', () => {
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(
const a=Object,
b=a.setPrototypeOf,
c=a.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)
),
d=b(class C extends class{}{},c);
b(d.prototype,c.prototype);
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b),"meth",a).call(a)
)(d)(d)
})()`,
validate(fn) {
expect(fn).toBeFunction();
Expand All @@ -1533,7 +1505,7 @@ describe('eval', () => {
meth() { return 123; }
}
class C extends S {
constructor(module, exports, obj) {
constructor(module, exports, S, obj) {
super();
this.f = eval('() => super.meth()');
}
Expand All @@ -1544,19 +1516,22 @@ describe('eval', () => {
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,{
const a=Object,
b=a.setPrototypeOf,
c=class S{},
d=c.prototype,
e=b(
(0,eval)("(class C extends class{}{constructor(module,exports,S,obj){super();this.f=eval(\\"() => super.meth()\\")}})"),
c
),
f=e.prototype;
a.defineProperties(d,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
f(e,a);
f(g,b);
return d[1](c.create(g))
b(f,d);
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a)
)(e)(a.create(f))
})()`,
validate(fn) {
expect(fn).toBeFunction();
Expand All @@ -1570,7 +1545,7 @@ describe('eval', () => {
meth() { return 123; }
}
class C extends S {
constructor(module, exports, obj) {
constructor(module, exports, S, obj) {
super();
this.f = eval('let livepack_tracker; () => super.meth()');
}
Expand All @@ -1581,19 +1556,22 @@ describe('eval', () => {
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,{
const a=Object,
b=a.setPrototypeOf,
c=class S{},
d=c.prototype,
e=b(
(0,eval)("(class C extends class{}{constructor(module,exports,S,obj){super();this.f=eval(\\"let livepack_tracker; () => super.meth()\\")}})"),
c
),
f=e.prototype;
a.defineProperties(d,{
meth:{value:{meth(){return 123}}.meth,writable:true,configurable:true}
});
f(e,a);
f(g,b);
return d[1](c.create(g))
b(f,d);
return(
b=>a=>()=>Reflect.get(Object.getPrototypeOf(b.prototype),"meth",a).call(a)
)(e)(a.create(f))
})()`,
validate(fn) {
expect(fn).toBeFunction();
Expand Down
Loading

0 comments on commit b723547

Please sign in to comment.