mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-12 15:44:40 +08:00
fix(object-freezing): Null is an object
, but not a freezable one
Resolves T1141
This commit is contained in:
parent
e2cd2e41ba
commit
958eceec56
2 changed files with 19 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
_ = require('underscore-plus')
|
_ = require('underscore-plus')
|
||||||
Utils = require '../src/flux/models/utils'
|
Utils = require '../src/flux/models/utils'
|
||||||
|
Thread = require '../src/flux/models/thread'
|
||||||
|
Contact = require '../src/flux/models/contact'
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
constructor: (@instanceVar) ->
|
constructor: (@instanceVar) ->
|
||||||
|
@ -13,6 +15,20 @@ class Bar extends Foo
|
||||||
@moreStuff = stuff
|
@moreStuff = stuff
|
||||||
@method(stuff)
|
@method(stuff)
|
||||||
|
|
||||||
|
describe "modelFreeze", ->
|
||||||
|
it "should freeze the object", ->
|
||||||
|
o =
|
||||||
|
a: 1
|
||||||
|
b: 2
|
||||||
|
Utils.modelFreeze(o)
|
||||||
|
expect(Object.isFrozen(o)).toBe(true)
|
||||||
|
|
||||||
|
it "should not throw an exception when nulls appear in strange places", ->
|
||||||
|
t = new Thread(participants: [new Contact(email: 'ben@nylas.com'), null], subject: '123')
|
||||||
|
Utils.modelFreeze(t)
|
||||||
|
expect(Object.isFrozen(t)).toBe(true)
|
||||||
|
expect(Object.isFrozen(t.participants[0])).toBe(true)
|
||||||
|
|
||||||
describe "deepClone", ->
|
describe "deepClone", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@v1 = [1,2,3]
|
@v1 = [1,2,3]
|
||||||
|
|
|
@ -114,8 +114,9 @@ Utils =
|
||||||
modelFreeze: (o) ->
|
modelFreeze: (o) ->
|
||||||
Object.freeze(o)
|
Object.freeze(o)
|
||||||
for key, prop of o
|
for key, prop of o
|
||||||
if !o.hasOwnProperty(key) || typeof prop isnt 'object' || Object.isFrozen(prop)
|
continue unless o.hasOwnProperty(key)
|
||||||
continue
|
continue unless typeof prop is 'object' and prop isnt null
|
||||||
|
continue if Object.isFrozen(prop)
|
||||||
Utils.modelFreeze(prop)
|
Utils.modelFreeze(prop)
|
||||||
|
|
||||||
modelReviver: (k, v) ->
|
modelReviver: (k, v) ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue