From b3c4b757e74a63d89cba00417366556029279419 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 1 Dec 2010 20:41:54 -0500 Subject: [PATCH] util.canFreeze removed, replaced with util.freeze() --- lib/class.js | 8 ++------ lib/interface.js | 9 +++------ lib/util.js | 20 +++++++++++++------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/class.js b/lib/class.js index c49c000..5cb9c96 100644 --- a/lib/class.js +++ b/lib/class.js @@ -22,8 +22,7 @@ * @package core */ -var util = require( './util' ), - can_freeze = require( './util' ).canFreeze(); +var util = require( './util' ); /** @@ -132,10 +131,7 @@ var extend = ( function( extending ) // lock down the new class (if supported) to ensure that we can't add // members at runtime - if ( can_freeze ) - { - Object.freeze( new_class ); - } + util.freeze( new_class ); // we're done with the extension process extending = false; diff --git a/lib/interface.js b/lib/interface.js index 0119dbc..762cb50 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -22,7 +22,7 @@ * @package core */ -var can_freeze = require( './util' ).canFreeze(); +var util = require( './util' ); /** @@ -53,11 +53,8 @@ function extend() var new_interface = {}; - // freeze the interface (preventing additions) if supported - if ( can_freeze ) - { - Object.freeze( new_interface ); - } + // freeze the interface (preventing additions), if supported + util.freeze( new_interface ); return new_interface; } diff --git a/lib/util.js b/lib/util.js index 18eefd1..6008de9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -34,16 +34,22 @@ var getset = ( Object.prototype.__defineGetter__ === undefined ) /** - * Whether the Object.freeze() method is available + * Freezes an object if freezing is supported * - * @return {boolean} + * @param {Object} obj object to freeze + * + * @return {Object} object passed to function */ -exports.canFreeze = function() +exports.freeze = function( obj ) { - return ( Object.seal === undefined ) - ? false - : true - ; + // if freezing is not supported (ES5), do nothing + if ( Object.freeze === undefined ) + { + return; + } + + Object.freeze( obj ); + return obj; }