Browse Source

Fixed setting the stack pointer in enterFuncBody. Fixes #309

Dmitry Panov 4 years ago
parent
commit
e981f83e1b
2 changed files with 15 additions and 1 deletions
  1. 14 0
      compiler_test.go
  2. 1 1
      vm.go

+ 14 - 0
compiler_test.go

@@ -3946,6 +3946,20 @@ func TestFuncParamScope(t *testing.T) {
 	testScript1(SCRIPT, asciiString("inside inside"), t)
 	testScript1(SCRIPT, asciiString("inside inside"), t)
 }
 }
 
 
+func TestDefParamsStackPtr(t *testing.T) {
+	const SCRIPT = `
+	function A() {};
+	A.B = function () {};
+	function D(message = '') {
+	  var C = A.B;
+	  C([1,2,3]);
+	};
+	
+	D();
+	`
+	testScript1(SCRIPT, _undefined, t)
+}
+
 /*
 /*
 func TestBabel(t *testing.T) {
 func TestBabel(t *testing.T) {
 	src, err := ioutil.ReadFile("babel7.js")
 	src, err := ioutil.ReadFile("babel7.js")

+ 1 - 1
vm.go

@@ -2797,7 +2797,7 @@ func (e *enterFuncBody) exec(vm *vm) {
 			vv[i] = nil
 			vv[i] = nil
 		}
 		}
 	}
 	}
-	sp = nsp
+	vm.sp = nsp
 	vm.pc++
 	vm.pc++
 }
 }