diff --git a/boot/boot.js b/boot/boot.js index 09d92f134..e1be3cbab 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -32,8 +32,8 @@ if(!$tw) { $tw = require("./bootprefix.js").bootprefix(); } -$tw.utils = $tw.utils || {}; -$tw.boot = $tw.boot || {}; +$tw.utils = $tw.utils || Object.create(null); +$tw.boot = $tw.boot || Object.create(null); /////////////////////////// Standard node.js libraries @@ -280,7 +280,7 @@ $tw.utils.parseStringArray = function(value) { // Parse a block of name:value fields. The `fields` object is used as the basis for the return value $tw.utils.parseFields = function(text,fields) { - fields = fields || {}; + fields = fields || Object.create(null); text.split(/\r?\n/mg).forEach(function(line) { if(line.charAt(0) !== "#") { var p = line.indexOf(":"); @@ -385,7 +385,7 @@ $tw.utils.registerFileType = function(type,encoding,extension,flags) { Run code globally with specified context variables in scope */ $tw.utils.evalGlobal = function(code,context,filename) { - var contextCopy = $tw.utils.extend({},context); + var contextCopy = $tw.utils.extend(Object.create(null),context); // Get the context variables as a pair of arrays of names and values var contextNames = [], contextValues = []; $tw.utils.each(contextCopy,function(value,name) { @@ -409,7 +409,7 @@ $tw.utils.evalGlobal = function(code,context,filename) { Run code in a sandbox with only the specified context variables in scope */ $tw.utils.evalSandboxed = $tw.browser ? $tw.utils.evalGlobal : function(code,context,filename) { - var sandbox = $tw.utils.extend({},context); + var sandbox = $tw.utils.extend(Object.create(null),context); vm.runInNewContext(code,sandbox,filename); return sandbox.exports; }; @@ -682,7 +682,7 @@ Get all the modules of a particular type in a hashmap by their `name` field */ $tw.modules.getModulesByTypeAsHashmap = function(moduleType,nameField) { nameField = nameField || "name"; - var results = {}; + var results = Object.create(null); $tw.modules.forEachModuleOfType(moduleType,function(title,module) { results[module[nameField]] = module; }); @@ -694,7 +694,7 @@ Apply the exports of the modules of a particular type to a target object */ $tw.modules.applyMethods = function(moduleType,targetObject) { if(!targetObject) { - targetObject = {}; + targetObject = Object.create(null); } $tw.modules.forEachModuleOfType(moduleType,function(title,module) { $tw.utils.each(module,function(element,title,object) { @@ -708,7 +708,7 @@ $tw.modules.applyMethods = function(moduleType,targetObject) { Return an array of classes created from the modules of a specified type. Each module should export the properties to be added to those of the optional base class */ $tw.modules.createClassesFromModules = function(moduleType,subType,baseClass) { - var classes = {}; + var classes = Object.create(null); $tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) { if(!subType || moduleExports.types[subType]) { var newClass = function() {}; @@ -730,7 +730,7 @@ Construct a tiddler object from a hashmap of tiddler fields. If multiple hasmaps taking precedence to the right */ $tw.Tiddler = function(/* [fields,] fields */) { - this.fields = {}; + this.fields = Object.create(null); for(var c=0; c