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 = require("./bootprefix.js").bootprefix();
|
||||||
}
|
}
|
||||||
|
|
||||||
$tw.utils = $tw.utils || {};
|
$tw.utils = $tw.utils || Object.create(null);
|
||||||
$tw.boot = $tw.boot || {};
|
$tw.boot = $tw.boot || Object.create(null);
|
||||||
|
|
||||||
/////////////////////////// Standard node.js libraries
|
/////////////////////////// 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
|
// 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) {
|
$tw.utils.parseFields = function(text,fields) {
|
||||||
fields = fields || {};
|
fields = fields || Object.create(null);
|
||||||
text.split(/\r?\n/mg).forEach(function(line) {
|
text.split(/\r?\n/mg).forEach(function(line) {
|
||||||
if(line.charAt(0) !== "#") {
|
if(line.charAt(0) !== "#") {
|
||||||
var p = line.indexOf(":");
|
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
|
Run code globally with specified context variables in scope
|
||||||
*/
|
*/
|
||||||
$tw.utils.evalGlobal = function(code,context,filename) {
|
$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
|
// Get the context variables as a pair of arrays of names and values
|
||||||
var contextNames = [], contextValues = [];
|
var contextNames = [], contextValues = [];
|
||||||
$tw.utils.each(contextCopy,function(value,name) {
|
$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
|
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) {
|
$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);
|
vm.runInNewContext(code,sandbox,filename);
|
||||||
return sandbox.exports;
|
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) {
|
$tw.modules.getModulesByTypeAsHashmap = function(moduleType,nameField) {
|
||||||
nameField = nameField || "name";
|
nameField = nameField || "name";
|
||||||
var results = {};
|
var results = Object.create(null);
|
||||||
$tw.modules.forEachModuleOfType(moduleType,function(title,module) {
|
$tw.modules.forEachModuleOfType(moduleType,function(title,module) {
|
||||||
results[module[nameField]] = 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) {
|
$tw.modules.applyMethods = function(moduleType,targetObject) {
|
||||||
if(!targetObject) {
|
if(!targetObject) {
|
||||||
targetObject = {};
|
targetObject = Object.create(null);
|
||||||
}
|
}
|
||||||
$tw.modules.forEachModuleOfType(moduleType,function(title,module) {
|
$tw.modules.forEachModuleOfType(moduleType,function(title,module) {
|
||||||
$tw.utils.each(module,function(element,title,object) {
|
$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
|
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) {
|
$tw.modules.createClassesFromModules = function(moduleType,subType,baseClass) {
|
||||||
var classes = {};
|
var classes = Object.create(null);
|
||||||
$tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) {
|
$tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) {
|
||||||
if(!subType || moduleExports.types[subType]) {
|
if(!subType || moduleExports.types[subType]) {
|
||||||
var newClass = function() {};
|
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
|
taking precedence to the right
|
||||||
*/
|
*/
|
||||||
$tw.Tiddler = function(/* [fields,] fields */) {
|
$tw.Tiddler = function(/* [fields,] fields */) {
|
||||||
this.fields = {};
|
this.fields = Object.create(null);
|
||||||
for(var c=0; c<arguments.length; c++) {
|
for(var c=0; c<arguments.length; c++) {
|
||||||
var arg = arguments[c],
|
var arg = arguments[c],
|
||||||
src = (arg instanceof $tw.Tiddler) ? arg.fields : arg;
|
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
|
// Now go through the plugins in ascending order and assign the shadows
|
||||||
shadowTiddlers = {};
|
shadowTiddlers = Object.create(null);
|
||||||
$tw.utils.each(pluginTiddlers,function(tiddler) {
|
$tw.utils.each(pluginTiddlers,function(tiddler) {
|
||||||
// Extract the constituent tiddlers
|
// Extract the constituent tiddlers
|
||||||
if($tw.utils.hop(pluginInfo,tiddler.fields.title)) {
|
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
|
Extracts tiddlers from a typed block of text, specifying default field values
|
||||||
*/
|
*/
|
||||||
$tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) {
|
$tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) {
|
||||||
srcFields = srcFields || {};
|
srcFields = srcFields || Object.create(null);
|
||||||
var deserializer = $tw.Wiki.tiddlerDeserializerModules[type],
|
var deserializer = $tw.Wiki.tiddlerDeserializerModules[type],
|
||||||
fields = {};
|
fields = Object.create(null);
|
||||||
if(!deserializer && $tw.config.fileExtensionInfo[type]) {
|
if(!deserializer && $tw.config.fileExtensionInfo[type]) {
|
||||||
// If we didn't find the serializer, try converting it from an extension to a content type
|
// If we didn't find the serializer, try converting it from an extension to a content type
|
||||||
type = $tw.config.fileExtensionInfo[type].type;
|
type = $tw.config.fileExtensionInfo[type].type;
|
||||||
@ -1098,7 +1098,7 @@ $tw.modules.define("$:/boot/tiddlerdeserializer/tids","tiddlerdeserializer",{
|
|||||||
if(line.charAt(0) !== "#") {
|
if(line.charAt(0) !== "#") {
|
||||||
var colonPos= line.indexOf(": ");
|
var colonPos= line.indexOf(": ");
|
||||||
if(colonPos !== -1) {
|
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);
|
tiddler.title = (tiddler.title || "") + line.substr(0,colonPos);
|
||||||
if(titles.indexOf(tiddler.title) !== -1) {
|
if(titles.indexOf(tiddler.title) !== -1) {
|
||||||
console.log("Warning: .multids file contains multiple definitions for " + tiddler.title);
|
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
|
// 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++) {
|
for(t=0; t<pluginTiddlers.length; t++) {
|
||||||
if(pluginTiddlers[t].title) {
|
if(pluginTiddlers[t].title) {
|
||||||
pluginInfo.tiddlers[pluginTiddlers[t].title] = pluginTiddlers[t];
|
pluginInfo.tiddlers[pluginTiddlers[t].title] = pluginTiddlers[t];
|
||||||
@ -1546,7 +1546,7 @@ $tw.boot.startup = function(options) {
|
|||||||
// Initialise some more $tw properties
|
// Initialise some more $tw properties
|
||||||
$tw.utils.deepDefaults($tw,{
|
$tw.utils.deepDefaults($tw,{
|
||||||
modules: { // Information about each module
|
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
|
types: {} // hashmap by module type of hashmap of exports
|
||||||
},
|
},
|
||||||
config: { // Configuration overridables
|
config: { // Configuration overridables
|
||||||
@ -1560,13 +1560,13 @@ $tw.boot.startup = function(options) {
|
|||||||
wikiLanguagesSubDir: "./languages",
|
wikiLanguagesSubDir: "./languages",
|
||||||
wikiTiddlersSubDir: "./tiddlers",
|
wikiTiddlersSubDir: "./tiddlers",
|
||||||
jsModuleHeaderRegExpString: "^\\/\\*\\\\(?:\\r?\\n)((?:^[^\\r\\n]*(?:\\r?\\n))+?)(^\\\\\\*\\/$(?:\\r?\\n)?)",
|
jsModuleHeaderRegExpString: "^\\/\\*\\\\(?:\\r?\\n)((?:^[^\\r\\n]*(?:\\r?\\n))+?)(^\\\\\\*\\/$(?:\\r?\\n)?)",
|
||||||
fileExtensionInfo: {}, // Map file extension to {type:}
|
fileExtensionInfo: Object.create(null), // Map file extension to {type:}
|
||||||
contentTypeInfo: {} // Map type to {encoding:,extension:}
|
contentTypeInfo: Object.create(null) // Map type to {encoding:,extension:}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!options.readBrowserTiddlers) {
|
if(!options.readBrowserTiddlers) {
|
||||||
// For writable tiddler files, a hashmap of title to {filepath:,type:,hasMetaFile:}
|
// 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
|
// System paths and filenames
|
||||||
$tw.boot.bootPath = path.dirname(module.filename);
|
$tw.boot.bootPath = path.dirname(module.filename);
|
||||||
$tw.boot.corePath = path.resolve($tw.boot.bootPath,"../core");
|
$tw.boot.corePath = path.resolve($tw.boot.bootPath,"../core");
|
||||||
@ -1613,7 +1613,7 @@ $tw.boot.startup = function(options) {
|
|||||||
// Install built in tiddler fields modules
|
// Install built in tiddler fields modules
|
||||||
$tw.Tiddler.fieldModules = $tw.modules.getModulesByTypeAsHashmap("tiddlerfield");
|
$tw.Tiddler.fieldModules = $tw.modules.getModulesByTypeAsHashmap("tiddlerfield");
|
||||||
// Install the tiddler deserializer modules
|
// Install the tiddler deserializer modules
|
||||||
$tw.Wiki.tiddlerDeserializerModules = {};
|
$tw.Wiki.tiddlerDeserializerModules = Object.create(null);
|
||||||
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
|
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
|
||||||
// Load tiddlers
|
// Load tiddlers
|
||||||
if(options.readBrowserTiddlers) {
|
if(options.readBrowserTiddlers) {
|
||||||
|
Loading…
Reference in New Issue
Block a user