Skip to content

Commit

Permalink
[fix] wrong scope chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed Feb 19, 2024
1 parent 4e96357 commit 415e2d8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,15 @@ function executor(generator, result) {
*/
function scope(push, scopeEval, scopeName) {
if (push) {
Scope.chain.push(new Scope(scopeEval, scopeName));
const scope = new Scope(scopeEval, scopeName);
Scope.chain.push(scope);
if (scopeName) {
Scope.curNamedScope = scope;
}
} else {
Scope.lastPop = Scope.chain.pop();
if (Scope.lastPop === Scope.curNamedScope) {
Scope.curNamedScope = null;
if (Scope.lastPop.name) {
Scope.curNamedScope = Scope.getSpecifiedScope((scope) => !!scope.name);
}
if (Scope.chain.length < 2) { // 只剩下全局作用域(length:1)或没有在执行(length:0)
// 如果有定义断点恢复设置,callFrameId设为极大,当前过程跑完后,保证能在下个循环中断住
Expand Down
6 changes: 1 addition & 5 deletions src/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export default class Scope {
}

static updateCallFrame(callFrame) {
const scope = Scope.curNamedScope || Scope.getSpecifiedScope((scope) => !!scope.name);
if (scope) {
scope.callFrame = callFrame;
Scope.curNamedScope = scope;
}
Scope.curNamedScope && (Scope.curNamedScope.callFrame = callFrame);
}
}
3 changes: 3 additions & 0 deletions tests/breakpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ describe('breakpoint tests', () => {
const pausedInfo = vDebugger.getPausedInfo();
expect(pausedInfo).toBeTruthy();
expect(pausedInfo.lineNumber).toEqual(breakLine);
expect(pausedInfo.scopeChain.length).toEqual(2);
expect(pausedInfo.scopeChain[1].callFrame).toBeTruthy();
expect(pausedInfo.scopeChain[1].callFrame.lineNumber).toEqual(breakLine);
expect(window.__trans_res__).toEqual(6);

const resumeRes = vDebugger.resume();
Expand Down

0 comments on commit 415e2d8

Please sign in to comment.