Skip to content
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

Occurred TypeError in Observer.create #1765

Merged
merged 2 commits into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/observer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Observer.create = function (value, vm) {
}
var ob
if (
value.hasOwnProperty('__ob__') &&
Object.prototype.hasOwnProperty.call(value, '__ob__') &&
value.__ob__ instanceof Observer
) {
ob = value.__ob__
Expand Down
17 changes: 17 additions & 0 deletions test/unit/specs/observer/observer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ describe('Observer', function () {
expect(ob2).toBe(ob)
})

it('create on null', function () {
// on null
var obj = Object.create(null)
obj.a = {}
obj.b = {}
var ob = Observer.create(obj)
expect(ob instanceof Observer).toBe(true)
expect(ob.value).toBe(obj)
expect(obj.__ob__).toBe(ob)
// should've walked children
expect(obj.a.__ob__ instanceof Observer).toBe(true)
expect(obj.b.__ob__ instanceof Observer).toBe(true)
// should return existing ob on already observed objects
var ob2 = Observer.create(obj)
expect(ob2).toBe(ob)
})

it('create on array', function () {
// on object
var arr = [{}, {}]
Expand Down