Skip to content

Property or method "toJSON" is not defined #333

@duziaqin

Description

@duziaqin

TL;DR:
when we use Vue.use to add a plugin, which render a component instance(with Vue.extend), and the component $emit events with vue instance as payload. It cause vue warns.
image

version:
vue(>2.0.0) vue-devtool(latest)
demo:
codepen
(can't reproduce the bug unless u copy the code, start a demo and open vue-devtool)
bug:
vue warns: Property or method "toJSON" is not defined
facts:

  • JSON.stringify would try to call toJSON attr when it meets object. spec
  • vue-devtool use JSON.stringify (or circular-json-es6) to deep copy(I guess) the $emit payload
  • vue use Proxy(_renderProxy) to warn not defined attr or method during render in develop mode

screen shot 2017-05-21 at 15 31 53

  • vue call the _init function (which included _renderProxy) in Vue and Vue.extend(produce _Ctor)

reason

  • vue-devtool find out a $emit, try to use JSON.stringify, JSON.stringify meet _Ctor attr first than circular reference
  • _Ctor[0] has _renderProxy, JSON.stringify try to call toJSON, cause getHandler to warn.
  • it's a rare bug, because it happens only when _renderPorxy is reached before circular reference.

but, it's real confusing...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions