From 80846e95f335fdef79e85fab8a6fa9fd189b392c Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 18 Nov 2011 23:14:40 -0500 Subject: [PATCH] __proto__ => getPrototypeOf --- lib/util.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index 5f902a1..65dd9e1 100644 --- a/lib/util.js +++ b/lib/util.js @@ -457,6 +457,15 @@ exports.getOwnPropertyDescriptor = }; +/** + * Returns prototype of object, or undefined if unsupported + */ +exports.getPrototypeOf = Object.getPrototypeOf || function() +{ + return undefined; +}; + + /** * Travels down the prototype chain of the given object in search of the * requested property and returns its descriptor @@ -483,14 +492,14 @@ exports.getPropertyDescriptor = function( obj, prop, nobase ) // note that this uses util's function, not Object's var desc = exports.getOwnPropertyDescriptor( obj, prop ), - next = obj.__proto__; + next = exports.getPrototypeOf( obj ); // if we didn't find a descriptor and a prototype is available, recurse down // the prototype chain, ensuring that the next prototype has a prototype if // the base is to be excluded - if ( !desc && next && ( !nobase || next.__proto__ ) ) + if ( !desc && next && ( !nobase || exports.getPrototypeOf( next ) ) ) { - return exports.getPropertyDescriptor( obj.__proto__, prop, nobase ); + return exports.getPropertyDescriptor( next, prop, nobase ); } // return the descriptor or undefined if no prototype is available @@ -505,7 +514,7 @@ exports.getPropertyDescriptor = function( obj, prop, nobase ) * @type {boolean} */ exports.defineSecureProp( exports.getPropertyDescriptor, 'canTraverse', - ( {}.__proto__ ) ? true : false + ( Object.getPrototypeOf ) ? true : false );