@@ -5886,6 +5886,85 @@ func TestNestedDestructArray(t *testing.T) {
58865886 testScriptWithTestLib (SCRIPT , _undefined , t )
58875887}
58885888
5889+ func TestThisInStash (t * testing.T ) {
5890+ const SCRIPT = `
5891+ function f() {
5892+ globalThis.x = () => this; // move 'this' to stash
5893+
5894+ {
5895+ try {
5896+ throw new Error("boo!");
5897+ } catch (e) {
5898+ if (e.message !== 'boo!') {
5899+ throw new Error("unexpected exception value");
5900+ }
5901+ }
5902+ }
5903+ }
5904+
5905+ function f1() {
5906+ globalThis.x = () => this; // move 'this' to stash
5907+ var v; // introduce a stack variable
5908+
5909+ {
5910+ try {
5911+ throw new Error("boo!");
5912+ } catch (e) {
5913+ if (e.message !== 'boo!') {
5914+ throw new Error("unexpected exception value");
5915+ }
5916+ }
5917+ }
5918+ }
5919+
5920+ f();
5921+ f1();
5922+ `
5923+ testScript (SCRIPT , _undefined , t )
5924+ }
5925+
5926+ func TestThisInStashCtor (t * testing.T ) {
5927+ const SCRIPT = `
5928+ class C extends Object {
5929+ constructor() {
5930+ super();
5931+ globalThis.x = () => this; // move 'this' to stash
5932+ {
5933+ try {
5934+ throw new Error("boo!");
5935+ } catch (e) {
5936+ if (e.message !== 'boo!') {
5937+ throw new Error("unexpected exception value");
5938+ }
5939+ }
5940+ }
5941+ }
5942+ }
5943+
5944+ class C1 extends Object {
5945+ constructor() {
5946+ super();
5947+ globalThis.x = () => this; // move 'this' to stash
5948+ var v; // introduce a stack variable
5949+ {
5950+ try {
5951+ throw new Error("boo!");
5952+ } catch (e) {
5953+ if (e.message !== 'boo!') {
5954+ throw new Error("unexpected exception value");
5955+ }
5956+ }
5957+ }
5958+ }
5959+ }
5960+
5961+ new C();
5962+ new C1();
5963+ undefined;
5964+ `
5965+ testScript (SCRIPT , _undefined , t )
5966+ }
5967+
58895968/*
58905969func TestBabel(t *testing.T) {
58915970 src, err := os.ReadFile("babel7.js")
0 commit comments