mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 19:47:20 +00:00
Fix problem with fields called "__proto__"
This commit is contained in:
parent
1e960ffcac
commit
ea46f85a8a
38
boot/boot.js
38
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<arguments.length; c++) {
|
||||
var arg = arguments[c],
|
||||
src = (arg instanceof $tw.Tiddler) ? arg.fields : arg;
|
||||
@ -960,7 +960,7 @@ $tw.Wiki = function(options) {
|
||||
}
|
||||
});
|
||||
// Now go through the plugins in ascending order and assign the shadows
|
||||
shadowTiddlers = {};
|
||||
shadowTiddlers = Object.create(null);
|
||||
$tw.utils.each(pluginTiddlers,function(tiddler) {
|
||||
// Extract the constituent tiddlers
|
||||
if($tw.utils.hop(pluginInfo,tiddler.fields.title)) {
|
||||
@ -1033,9 +1033,9 @@ $tw.Wiki.prototype.defineShadowModules = function() {
|
||||
Extracts tiddlers from a typed block of text, specifying default field values
|
||||
*/
|
||||
$tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) {
|
||||
srcFields = srcFields || {};
|
||||
srcFields = srcFields || Object.create(null);
|
||||
var deserializer = $tw.Wiki.tiddlerDeserializerModules[type],
|
||||
fields = {};
|
||||
fields = Object.create(null);
|
||||
if(!deserializer && $tw.config.fileExtensionInfo[type]) {
|
||||
// If we didn't find the serializer, try converting it from an extension to a content type
|
||||
type = $tw.config.fileExtensionInfo[type].type;
|
||||
@ -1098,7 +1098,7 @@ $tw.modules.define("$:/boot/tiddlerdeserializer/tids","tiddlerdeserializer",{
|
||||
if(line.charAt(0) !== "#") {
|
||||
var colonPos= line.indexOf(": ");
|
||||
if(colonPos !== -1) {
|
||||
var tiddler = $tw.utils.extend({},fields);
|
||||
var tiddler = $tw.utils.extend(Object.create(null),fields);
|
||||
tiddler.title = (tiddler.title || "") + line.substr(0,colonPos);
|
||||
if(titles.indexOf(tiddler.title) !== -1) {
|
||||
console.log("Warning: .multids file contains multiple definitions for " + tiddler.title);
|
||||
@ -1369,7 +1369,7 @@ $tw.loadPluginFolder = function(filepath,excludeRegExp) {
|
||||
}
|
||||
}
|
||||
// Save the plugin tiddlers into the plugin info
|
||||
pluginInfo.tiddlers = pluginInfo.tiddlers || {};
|
||||
pluginInfo.tiddlers = pluginInfo.tiddlers || Object.create(null);
|
||||
for(t=0; t<pluginTiddlers.length; t++) {
|
||||
if(pluginTiddlers[t].title) {
|
||||
pluginInfo.tiddlers[pluginTiddlers[t].title] = pluginTiddlers[t];
|
||||
@ -1546,7 +1546,7 @@ $tw.boot.startup = function(options) {
|
||||
// Initialise some more $tw properties
|
||||
$tw.utils.deepDefaults($tw,{
|
||||
modules: { // Information about each module
|
||||
titles: {}, // hashmap by module title of {fn:, exports:, moduleType:}
|
||||
titles: Object.create(null), // hashmap by module title of {fn:, exports:, moduleType:}
|
||||
types: {} // hashmap by module type of hashmap of exports
|
||||
},
|
||||
config: { // Configuration overridables
|
||||
@ -1560,13 +1560,13 @@ $tw.boot.startup = function(options) {
|
||||
wikiLanguagesSubDir: "./languages",
|
||||
wikiTiddlersSubDir: "./tiddlers",
|
||||
jsModuleHeaderRegExpString: "^\\/\\*\\\\(?:\\r?\\n)((?:^[^\\r\\n]*(?:\\r?\\n))+?)(^\\\\\\*\\/$(?:\\r?\\n)?)",
|
||||
fileExtensionInfo: {}, // Map file extension to {type:}
|
||||
contentTypeInfo: {} // Map type to {encoding:,extension:}
|
||||
fileExtensionInfo: Object.create(null), // Map file extension to {type:}
|
||||
contentTypeInfo: Object.create(null) // Map type to {encoding:,extension:}
|
||||
}
|
||||
});
|
||||
if(!options.readBrowserTiddlers) {
|
||||
// For writable tiddler files, a hashmap of title to {filepath:,type:,hasMetaFile:}
|
||||
$tw.boot.files = {};
|
||||
$tw.boot.files = Object.create(null);
|
||||
// System paths and filenames
|
||||
$tw.boot.bootPath = path.dirname(module.filename);
|
||||
$tw.boot.corePath = path.resolve($tw.boot.bootPath,"../core");
|
||||
@ -1613,7 +1613,7 @@ $tw.boot.startup = function(options) {
|
||||
// Install built in tiddler fields modules
|
||||
$tw.Tiddler.fieldModules = $tw.modules.getModulesByTypeAsHashmap("tiddlerfield");
|
||||
// Install the tiddler deserializer modules
|
||||
$tw.Wiki.tiddlerDeserializerModules = {};
|
||||
$tw.Wiki.tiddlerDeserializerModules = Object.create(null);
|
||||
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
|
||||
// Load tiddlers
|
||||
if(options.readBrowserTiddlers) {
|
||||
|
Loading…
Reference in New Issue
Block a user