Replace __defineGetter__ with Object.defineProperty
Before adoption: this commit came in with the history the project adopted, so no landing records it.
closes #2162
authored by Guy Ellis Monster · committed by Douglas Christopher Wilson · parent bdfd288 · Browse files · 1 file·+26 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+26 added−10 removed
- other:+26 added−10 removed
Provenance
- Commit
746044b- Tree
95642eb- Author
Guy Ellis Monster <wildfiction@gmail.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
bdfd288
1 file changed+26 added−10 removed
modified:lib/request.js+26 added-10 removed
247 unmodified lines248 * @return {String}249 * @api public250 */251 252-req.__defineGetter__('protocol', function(){252+defineGetter(req, 'protocol', function protocol(){253 var trust = this.app.get('trust proxy fn');254 255 if (!trust(this.connection.remoteAddress)) {256 return this.connection.encrypted15 unmodified lines272 * @return {Boolean}273 * @api public274 */275 276-req.__defineGetter__('secure', function(){276+defineGetter(req, 'secure', function secure(){277 return 'https' == this.protocol;278 });279 280 /**5 unmodified lines286 * @return {String}287 * @api public288 */289 290-req.__defineGetter__('ip', function(){290+defineGetter(req, 'ip', function ip(){291 var trust = this.app.get('trust proxy fn');292 return proxyaddr(this, trust);293 });294 8 unmodified lines303 * @return {Array}304 * @api public305 */306 307-req.__defineGetter__('ips', function(){307+defineGetter(req, 'ips', function ips() {308 var trust = this.app.get('trust proxy fn');309 var addrs = proxyaddr.all(this, trust);310 return addrs.slice(1).reverse();311 });12 unmodified lines324 * @return {Array}325 * @api public326 */327 328-req.__defineGetter__('subdomains', function(){328+defineGetter(req, 'subdomains', function subdomains() {329 var offset = this.app.get('subdomain offset');330 return (this.host || '')331 .split('.')332 .reverse()6 unmodified lines339 * @return {String}340 * @api public341 */342 343-req.__defineGetter__('path', function(){343+defineGetter(req, 'path', function path() {344 return parse(this).pathname;345 });346 347 /**6 unmodified lines354 * @return {String}355 * @api public356 */357 358-req.__defineGetter__('host', function(){358+defineGetter(req, 'host', function host(){359 var trust = this.app.get('trust proxy fn');360 var host = this.get('X-Forwarded-Host');361 362 if (!host || !trust(this.connection.remoteAddress)) {21 unmodified lines384 * @return {Boolean}385 * @api public386 */387 388-req.__defineGetter__('fresh', function(){388+defineGetter(req, 'fresh', function(){389 var method = this.method;390 var s = this.res.statusCode;391 392 // GET or HEAD for weak freshness validation only15 unmodified lines408 * @return {Boolean}409 * @api public410 */411 412-req.__defineGetter__('stale', function(){412+defineGetter(req, 'stale', function stale(){413 return !this.fresh;414 });415 416 /**2 unmodified lines419 * @return {Boolean}420 * @api public421 */422 423-req.__defineGetter__('xhr', function(){423+defineGetter(req, 'xhr', function xhr(){424 var val = this.get('X-Requested-With') || '';425 return 'xmlhttprequest' == val.toLowerCase();426 });427+428+/**429+ * Helper function for creating a getter on an object.430+ *431+ * @param {Object} obj432+ * @param {String} name433+ * @param {Function} getter434+ * @api private435+ */436+function defineGetter(obj, name, getter) {437+ Object.defineProperty(obj, name, {438+ configurable: true,439+ enumerable: true,440+ get: getter441+ });442+};