1
0
Fork 0

Monkeypatches loaded by default and refactored

The monkeypatches will now always be loaded a server startup.
I also refactored them.
This commit is contained in:
Lucas Dohmen 2012-06-20 16:18:04 +02:00
parent a31d5e8f27
commit 455befdbf6
3 changed files with 31 additions and 24 deletions

View File

@ -40,8 +40,6 @@ var internal = require("internal"),
findOrCreateCollectionByName,
findOrCreateEdgeCollectionByName;
require("monkeypatches");
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------

View File

@ -38,8 +38,7 @@
Object.defineProperty(Array.prototype, "removeLastOccurrenceOf", {
value: function (element) {
var index = this.lastIndexOf(element);
return this.splice(index, 1);
return this.splice(this.lastIndexOf(element), 1);
}
});
@ -73,16 +72,9 @@ Object.defineProperty(Array.prototype, "intersect", {
Object.defineProperty(Object.prototype, "shallowCopy", {
get: function () {
var shallow = {},
key;
for (key in this) {
if (this.hasOwnProperty(key) && key[0] !== '_' && key[0] !== '$') {
shallow[key] = this[key];
}
}
return shallow;
return this.propertyKeys.reduce(function (previousValue, key) {
previousValue[key] = this[key]; return previousValue;
}, {});
}
});
@ -92,16 +84,9 @@ Object.defineProperty(Object.prototype, "shallowCopy", {
Object.defineProperty(Object.prototype, "propertyKeys", {
get: function () {
var keys = [],
key;
for (key in this) {
if (this.hasOwnProperty(key) && key[0] !== '_' && key[0] !== '$') {
keys.push(key);
}
}
return keys;
return Object.keys(this).filter(function (element) {
return (element[0] !== '_' && element[0] !== '$');
});
}
});

View File

@ -105,6 +105,30 @@
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- Module "monkeypatches"
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup V8ModuleMonkeypatches
/// @{
////////////////////////////////////////////////////////////////////////////////
(function () {
var console = require("console");
try {
require("monkeypatches");
}
catch (err) {
console.error("while loading 'monkeypatches' module: %s", err);
}
}());
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- ShapedJson
// -----------------------------------------------------------------------------