From f99a4e7664cfc0f4c0eb82c0942d6025ce363b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20K=C3=BCppers?= Date: Sat, 7 Mar 2015 20:47:43 +0100 Subject: [PATCH] Bugfix: Object.freeze() called on null For five minutes I stared at the following code... if(value != null && typeof value === "object") { Object.freeze(value); } ... and at the error message that led me to this code: `Object.freeze called on non-object` And then I remembered that js treads null as object (http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3). This means the `typeof === "object"` will not discover null and freeze will throw an error... So `value != null` will also work when value is undefined. A hard to find bug ;) --- boot/boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/boot.js b/boot/boot.js index aa1e0f5bd..f9f8d16f2 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -793,7 +793,7 @@ $tw.Tiddler = function(/* [fields,] fields */) { value = src[t]; } // Freeze the field to keep it immutable - if(typeof value === "object") { + if(value != null && typeof value === "object") { Object.freeze(value); } this.fields[t] = value;