Commit 0da5d71c authored by Tristan Cavelier's avatar Tristan Cavelier

defineConstant does not provide more security

parent 2ef4dc1c
/*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true */
/*global secureMethods, exports, defineConstant, console */
/*global secureMethods, exports, console */
/**
* Inspired by nodejs EventEmitter class
......
/*jslint indent: 2, maxlen: 80, sloppy: true */
/*global exports, defaults, defineConstant */
/*global exports, defaults */
function Storage() { // (storage_spec, util)
return undefined; // this is a constructor
......@@ -33,4 +33,4 @@ function addStorage(type, Constructor) {
// dictUpdate(Constructor.prototype, proto);
defaults.storage_types[type] = Constructor;
}
defineConstant(exports, 'addStorage', addStorage);
exports.addStorage = addStorage;
......@@ -9,46 +9,3 @@
window.jIO = {};
module(window.jIO);
}(['exports'], function (exports) {
/**
* Add a secured (write permission denied) property to an object.
*
* @method defineConstant
* @param {Object} object The object to fill
* @param {String} key The object key where to store the property
* @param {Any} value The value to store
*/
function defineConstant(object, key, value) {
Object.defineProperty(object, key, {
"configurable": false,
"enumerable": true,
"writable": false,
"value": value
});
return object;
}
/**
* Secures all enumerable functions from an object, making them
* not configurable, not writable, not enumerable.
*
* @method secureMethods
* @param {Object} object The object to secure
*/
function secureMethods(object) {
var key;
for (key in object) {
if (object.hasOwnProperty(key)) {
if (typeof object[key] === "function") {
Object.defineProperty(object, key, {
"configurable": false,
"enumerable": false,
"writable": false,
"value": object[key]
});
}
}
}
return object;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment