Skip to content

更新到0.11.0-rc3后遇到watcher.js报错 #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Alexorz opened this issue Oct 29, 2014 · 4 comments
Closed

更新到0.11.0-rc3后遇到watcher.js报错 #520

Alexorz opened this issue Oct 29, 2014 · 4 comments

Comments

@Alexorz
Copy link

Alexorz commented Oct 29, 2014

Hello,
觉得可能是个bug,所以就直接用中文描述了。。

报错页面的逻辑有点复杂,没能抽出纯粹的Demo,但已查到直接原因。

报错的截图如下:
snip20141029_7

出错场景还原如下:

    var cbs = this.cbs
    for (var i = 0, l = cbs.length; i < l; i++) {
        cbs[i](value, oldValue)
    }
  1. 代码执行到上面这段,cbs为[update, update]l == cbs.length == 2
  2. 进入for循环,i == 0,执行第一个update,执行后满足teardown的条件,进入_teardown()
  3. _teardown()中满足条件进入removeCb(),然后执行cbs.splice(i, 1),cbs变为[update]
  4. 回到最初的for循环,i == 1, l == 2i<l == true,遍历到第二个元素,但此时cbs的长度已变为1,cbs[1] == undefined
  5. cbs[1] == undefined被作为函数执行,浏览器报错。

相关代码的位置:
https://github.com/yyx990803/vue/blob/0.11.0-rc3/dist/vue.js#L2174
https://github.com/yyx990803/vue/blob/0.11.0-rc3/dist/vue.js#L2202

小结一下出错的条件:cbs长度>1,且非末位数组元素的执行触发了removeCb。

但不知update(value, oldValue)在怎样的情况下会进入teardown逻辑,我再试试能不能抽出纯粹的Demo。

@yyx990803
Copy link
Member

Hi, 非常感谢这么详细的报告,我想再对根本原因定位一下,能不能在出错的地方放个 debugger:

try {
  for (var i = 0, l = cbs.length; i < l; i++) {
    cbs[i](value, oldValue)
  }
} catch (e) { debugger }

然后让我看下出来的 stack trace 截图?或者展开那个错误的 stack trace 也可以

@Alexorz
Copy link
Author

Alexorz commented Oct 29, 2014

snip20141029_8
居然把最关键的漏了。。截图如上,index.js即dist/vue.js

@yyx990803
Copy link
Member

应该解决了,你按 next branch 最新的 commit 修改一下看看是否还报错。

@Alexorz
Copy link
Author

Alexorz commented Oct 30, 2014

正常了,赞!

@Alexorz Alexorz closed this as completed Oct 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants