transplant.js (1020B)
1 class Base { 2 constructor(o) { 3 return o; 4 } 5 } 6 7 class A extends Base { 8 #x = 10; 9 static gx(o) { 10 return o.#x 11 } 12 static sx(o, v) { 13 o.#x = v; 14 } 15 } 16 17 function transplantTest(transplantOptions, global) { 18 var {object, transplant} = transplantableObject(transplantOptions); 19 20 new A(object); 21 assertEq(A.gx(object), 10); 22 A.sx(object, 15); 23 assertEq(A.gx(object), 15); 24 25 transplant(global); 26 27 assertEq(A.gx(object), 15); 28 A.sx(object, 29); 29 assertEq(A.gx(object), 29); 30 } 31 32 // Structure helpfully provided by bug1403679.js 33 const thisGlobal = this; 34 const otherGlobalSameCompartment = newGlobal({sameCompartmentAs: thisGlobal}); 35 const otherGlobalNewCompartment = newGlobal({newCompartment: true}); 36 37 const globals = 38 [thisGlobal, otherGlobalSameCompartment, otherGlobalNewCompartment]; 39 40 function testWithOptions(fn) { 41 for (let global of globals) { 42 for (let options of [{}, {proxy: true}, {object: new FakeDOMObject()}, ]) { 43 fn(options, global); 44 } 45 } 46 } 47 48 testWithOptions(transplantTest)