1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-05-07 09:54:09 +00:00

Fix problems with tiddlers called __proto__

Background:

http://www.2ality.com/2012/01/objects-as-maps.html
This commit is contained in:
Jermolene 2014-04-06 22:43:10 +01:00
parent 8a7d0f53d3
commit 1e960ffcac
2 changed files with 20 additions and 20 deletions

View File

@ -803,10 +803,10 @@ shadowTiddlers: Array of shadow tiddlers to be added
$tw.Wiki = function(options) { $tw.Wiki = function(options) {
options = options || {}; options = options || {};
var self = this, var self = this,
tiddlers = {}, // Hashmap of tiddlers tiddlers = Object.create(null), // Hashmap of tiddlers
pluginTiddlers = [], // Array of tiddlers containing registered plugins, ordered by priority pluginTiddlers = [], // Array of tiddlers containing registered plugins, ordered by priority
pluginInfo = {}, // Hashmap of parsed plugin content pluginInfo = Object.create(null), // Hashmap of parsed plugin content
shadowTiddlers = options.shadowTiddlers || {}; // Hashmap by title of {source:, tiddler:} shadowTiddlers = options.shadowTiddlers || Object.create(null); // Hashmap by title of {source:, tiddler:}
// Add a tiddler to the store // Add a tiddler to the store
this.addTiddler = function(tiddler) { this.addTiddler = function(tiddler) {

View File

@ -57,7 +57,7 @@ exports.setTextReference = function(textRef,value,currTiddlerTitle) {
title = tr.title || currTiddlerTitle; title = tr.title || currTiddlerTitle;
// Check if it is a reference to a tiddler field // Check if it is a reference to a tiddler field
if(tr.index) { if(tr.index) {
var data = this.getTiddlerData(title,{}); var data = this.getTiddlerData(title,Object.create(null));
data[tr.index] = value; data[tr.index] = value;
this.setTiddlerData(title,data,this.getModificationFields()); this.setTiddlerData(title,data,this.getModificationFields());
} else { } else {
@ -79,7 +79,7 @@ exports.deleteTextReference = function(textRef,currTiddlerTitle) {
title = tr.title || currTiddlerTitle; title = tr.title || currTiddlerTitle;
tiddler = this.getTiddler(title); tiddler = this.getTiddler(title);
if(tiddler && $tw.utils.hop(tiddler.fields,tr.field)) { if(tiddler && $tw.utils.hop(tiddler.fields,tr.field)) {
fields = {}; fields = Object.create(null);
fields[tr.field] = undefined; fields[tr.field] = undefined;
this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields())); this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields()));
} }
@ -122,11 +122,11 @@ This method should be called after the changes it describes have been made to th
*/ */
exports.enqueueTiddlerEvent = function(title,isDeleted) { exports.enqueueTiddlerEvent = function(title,isDeleted) {
// Record the touch in the list of changed tiddlers // Record the touch in the list of changed tiddlers
this.changedTiddlers = this.changedTiddlers || {}; this.changedTiddlers = this.changedTiddlers || Object.create(null);
this.changedTiddlers[title] = this.changedTiddlers[title] || {}; this.changedTiddlers[title] = this.changedTiddlers[title] || Object.create(null);
this.changedTiddlers[title][isDeleted ? "deleted" : "modified"] = true; this.changedTiddlers[title][isDeleted ? "deleted" : "modified"] = true;
// Increment the change count // Increment the change count
this.changeCount = this.changeCount || {}; this.changeCount = this.changeCount || Object.create(null);
if($tw.utils.hop(this.changeCount,title)) { if($tw.utils.hop(this.changeCount,title)) {
this.changeCount[title]++; this.changeCount[title]++;
} else { } else {
@ -138,7 +138,7 @@ exports.enqueueTiddlerEvent = function(title,isDeleted) {
var self = this; var self = this;
$tw.utils.nextTick(function() { $tw.utils.nextTick(function() {
var changes = self.changedTiddlers; var changes = self.changedTiddlers;
self.changedTiddlers = {}; self.changedTiddlers = Object.create(null);
self.eventsTriggered = false; self.eventsTriggered = false;
self.dispatchEvent("change",changes); self.dispatchEvent("change",changes);
}); });
@ -147,7 +147,7 @@ exports.enqueueTiddlerEvent = function(title,isDeleted) {
}; };
exports.getChangeCount = function(title) { exports.getChangeCount = function(title) {
this.changeCount = this.changeCount || {}; this.changeCount = this.changeCount || Object.create(null);
if($tw.utils.hop(this.changeCount,title)) { if($tw.utils.hop(this.changeCount,title)) {
return this.changeCount[title]; return this.changeCount[title];
} else { } else {
@ -223,7 +223,7 @@ exports.getCreationFields = function() {
Return a hashmap of the fields that should be set when a tiddler is modified Return a hashmap of the fields that should be set when a tiddler is modified
*/ */
exports.getModificationFields = function() { exports.getModificationFields = function() {
var fields = {}, var fields = Object.create(null),
modifier = this.getTiddlerText(USER_NAME_TITLE); modifier = this.getTiddlerText(USER_NAME_TITLE);
fields.modified = new Date(); fields.modified = new Date();
if(modifier) { if(modifier) {
@ -239,7 +239,7 @@ excludeTag: tag to exclude
includeSystem: whether to include system tiddlers (defaults to false) includeSystem: whether to include system tiddlers (defaults to false)
*/ */
exports.getTiddlers = function(options) { exports.getTiddlers = function(options) {
options = options || {}; options = options || Object.create(null);
var self = this, var self = this,
sortField = options.sortField || "title", sortField = options.sortField || "title",
tiddlers = [], t, titles = []; tiddlers = [], t, titles = [];
@ -448,7 +448,7 @@ Get a hashmap by tag of arrays of tiddler titles
exports.getTagMap = function() { exports.getTagMap = function() {
var self = this; var self = this;
return this.getGlobalCache("tagmap",function() { return this.getGlobalCache("tagmap",function() {
var tags = {}, var tags = Object.create(null),
storeTags = function(tagArray,title) { storeTags = function(tagArray,title) {
if(tagArray) { if(tagArray) {
for(var index=0; index<tagArray.length; index++) { for(var index=0; index<tagArray.length; index++) {
@ -549,7 +549,7 @@ Retrieve a tiddler as a JSON string of the fields
exports.getTiddlerAsJson = function(title) { exports.getTiddlerAsJson = function(title) {
var tiddler = this.getTiddler(title); var tiddler = this.getTiddler(title);
if(tiddler) { if(tiddler) {
var fields = {}; var fields = Object.create(null);
$tw.utils.each(tiddler.fields,function(value,name) { $tw.utils.each(tiddler.fields,function(value,name) {
fields[name] = tiddler.getFieldString(name); fields[name] = tiddler.getFieldString(name);
}); });
@ -591,7 +591,7 @@ exports.getTiddlerData = function(title,defaultData) {
Extract an indexed field from within a data tiddler Extract an indexed field from within a data tiddler
*/ */
exports.extractTiddlerDataItem = function(title,index,defaultText) { exports.extractTiddlerDataItem = function(title,index,defaultText) {
var data = this.getTiddlerData(title,{}), var data = this.getTiddlerData(title,Object.create(null)),
text; text;
if(data && $tw.utils.hop(data,index)) { if(data && $tw.utils.hop(data,index)) {
text = data[index]; text = data[index];
@ -640,7 +640,7 @@ exports.getTiddlerList = function(title,field,index) {
// Return a named global cache object. Global cache objects are cleared whenever a tiddler change occurs // Return a named global cache object. Global cache objects are cleared whenever a tiddler change occurs
exports.getGlobalCache = function(cacheName,initializer) { exports.getGlobalCache = function(cacheName,initializer) {
this.globalCache = this.globalCache || {}; this.globalCache = this.globalCache || Object.create(null);
if($tw.utils.hop(this.globalCache,cacheName)) { if($tw.utils.hop(this.globalCache,cacheName)) {
return this.globalCache[cacheName]; return this.globalCache[cacheName];
} else { } else {
@ -650,7 +650,7 @@ exports.getGlobalCache = function(cacheName,initializer) {
}; };
exports.clearGlobalCache = function() { exports.clearGlobalCache = function() {
this.globalCache = {}; this.globalCache = Object.create(null);
} }
// Return the named cache object for a tiddler. If the cache doesn't exist then the initializer function is invoked to create it // Return the named cache object for a tiddler. If the cache doesn't exist then the initializer function is invoked to create it
@ -659,13 +659,13 @@ exports.getCacheForTiddler = function(title,cacheName,initializer) {
// Temporarily disable caching so that tweakParseTreeNode() works // Temporarily disable caching so that tweakParseTreeNode() works
return initializer(); return initializer();
this.caches = this.caches || {}; this.caches = this.caches || Object.create(null);
var caches = this.caches[title]; var caches = this.caches[title];
if(caches && caches[cacheName]) { if(caches && caches[cacheName]) {
return caches[cacheName]; return caches[cacheName];
} else { } else {
if(!caches) { if(!caches) {
caches = {}; caches = Object.create(null);
this.caches[title] = caches; this.caches[title] = caches;
} }
caches[cacheName] = initializer(); caches[cacheName] = initializer();
@ -675,7 +675,7 @@ return initializer();
// Clear all caches associated with a particular tiddler // Clear all caches associated with a particular tiddler
exports.clearCache = function(title) { exports.clearCache = function(title) {
this.caches = this.caches || {}; this.caches = this.caches || Object.create(null);
if($tw.utils.hop(this.caches,title)) { if($tw.utils.hop(this.caches,title)) {
delete this.caches[title]; delete this.caches[title];
} }