polyfill_Object.js.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: polyfill/Object.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: polyfill/Object.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>// Licensed Materials - Property of IBM
  20. //
  21. // IBM Watson Analytics
  22. //
  23. // (C) Copyright IBM Corp. 2015, 2018
  24. //
  25. // US Government Users Restricted Rights - Use, duplication or
  26. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  27. ( function( exports, Object )
  28. {
  29. "use strict";
  30. /*global Symbol*/
  31. var hasOwnProperty = Object.prototype.hasOwnProperty;
  32. var toString = Object.prototype.toString;
  33. // RegExp set up to match BareJS and polyfill.io symbol strings
  34. // polyfill uses "__\x01symbol:" and "__\x01symbol@@"
  35. var reSymbol = /^__\d*\x01?[sS]ymbol/;
  36. // By default, make members whose name does not start with _ or $ enumerable.
  37. var reEnumerable = /^[^_\$]/;
  38. var strUndef = "undefined";
  39. var NativeSymbol = typeof Symbol !== strUndef ? Symbol : null;
  40. //jshint -W122
  41. var symIt = NativeSymbol &amp;&amp; ( typeof Symbol.iterator === "symbol" ) ? Symbol.iterator : /*istanbul ignore next*/ null;
  42. //jshint +W122
  43. /**
  44. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object Object}.
  45. * Module that provides implementations for methods missing on Object. Methods that cannot be polyfilled close enough to
  46. * the spec (since they rely on Native implementations) are not added to the Object global.
  47. * @class module:barejs/polyfill.Object
  48. */
  49. /** @lends module:barejs/polyfill.Object */
  50. var stat = {};
  51. /**
  52. * Shortcut method that only defines a property if it is not already known
  53. * @param {object} _target The object to polyfill
  54. * @param {object} _members The members to polyfill
  55. * @param {object} [_copy] Optional: an object that the definitions will be copied to.
  56. * @param {string} [_ownerName] Optional: name of the owner object
  57. * @memberof module:barejs/polyfill.Object~
  58. * @private
  59. */
  60. function polyMixin( _target, _members, _copy, _ownerName )
  61. {
  62. for ( var name in _members )
  63. {
  64. /*istanbul ignore else: we're working on clean objects, iterating prototype properties is unexpected*/
  65. if ( _members.hasOwnProperty( name ) )
  66. {
  67. var member = _members[name], isFn = typeof member === "function";
  68. if ( isFn &amp;&amp; _ownerName )
  69. member.displayName = _ownerName + "." + name;
  70. if ( _copy )
  71. _copy[name] = member;
  72. if ( !( name in _target ) )
  73. exports.defineProperty( _target, name, { enumerable : false, configurable: isFn, writable: isFn, value: member } );
  74. }
  75. }
  76. }
  77. /**
  78. * Helper method that allows to easily apply static and prototype properties to a native object
  79. * @param {function} _native The native Object constructor to polyfill
  80. * @param {object} _static The static methods to polyfill. Can be null.
  81. * @param {object} _proto The instance members to polyfill. Can be null.
  82. * @param {object} [_copy] Optional: an object that the definitions will be copied to.
  83. * @param {string} [_ownerName] Optional: the name of the owner object.
  84. * Allows to add functions to "exports" as well, for unit testing.
  85. * @memberof module:barejs/polyfill.Object
  86. * @private
  87. */
  88. exports.polyfill = function polyfill( _native, _static, _proto, _copy, _ownerName )
  89. {
  90. if ( _static )
  91. polyMixin( _native, _static, _copy, _ownerName );
  92. if ( _proto )
  93. polyMixin( _native.prototype, _proto, _copy, _ownerName &amp;&amp; ( _ownerName + ".prototype" ) );
  94. return _native;
  95. };
  96. exports.shouldBeEnumerable = function shouldBeEnumerable( _name )
  97. {
  98. return typeof _name === "string" &amp;&amp; reEnumerable.test( _name );
  99. };
  100. /**
  101. * Utility method to check if _target is an Object
  102. * @param _arg The argument to check.
  103. * @returns {boolean} True if the target is an object, false otherwise
  104. */
  105. function isObject( _arg )
  106. {
  107. switch ( _arg &amp;&amp; typeof _arg )
  108. {
  109. case "object":
  110. case "function":
  111. return true;
  112. default:
  113. return false;
  114. }
  115. }
  116. exports.isObject = isObject;
  117. /**
  118. * Utility method to convert target to an Object (according to Ecmascript standard)
  119. * @param _arg The argument to check.
  120. * @param _caller The function requesting the cast. If provided, changes the exception message.
  121. * @returns {object} The argument, as object
  122. * @throws {TypeError} A TypeError if _arg is null or undefined.
  123. */
  124. function toObject( _arg, _caller )
  125. {
  126. switch ( _arg === null ? strUndef : typeof _arg )
  127. {
  128. case "undefined":
  129. throw new TypeError( _caller ? _caller.displayName + " called on null or undefined" : "Cannot convert undefined or null to object" );
  130. case "object":
  131. case "function":
  132. return _arg;
  133. default:
  134. return Object( _arg );
  135. }
  136. }
  137. exports.toObject = toObject;
  138. /**
  139. * Check if _arg is callable (i.e. a function).
  140. * @param _arg The argument to check.
  141. * @returns {boolean} True if _arg is a function, false otherwise.
  142. * @memberof module:barejs/polyfill.Object
  143. * @private
  144. */
  145. exports.isCallable = function isCallable( _arg )
  146. {
  147. // We can't check the internal [[Call]] property, so we rely on type checking.
  148. return ( typeof _arg === "function" ) || ( toString.call( _arg ) === "[object Function]" );
  149. };
  150. /**
  151. * Convenience method to check if _arg is callable (i.e. a function).
  152. * Note: If a second argument is provided, that is returned instead of _arg.
  153. * This allows inlining the ensureCallable method in convenient locations.
  154. * @param _arg function to check
  155. * @returns _arg, or second argument if present
  156. * @throws {TypeError} if _arg is not callable.
  157. * @memberof module:barejs/polyfill.Object
  158. * @private
  159. */
  160. exports.ensureCallable = function ensureCallable( _arg )
  161. {
  162. if ( !exports.isCallable( _arg ) )
  163. throw new TypeError( _arg + " is not a function" );
  164. return arguments.length > 1 ? arguments[1] : _arg;
  165. };
  166. /**
  167. * Helper function that will attempt to set the ES6 iterator Symbol for a class.
  168. * @param {object} _target The object to define the iterator on.
  169. * @param {function} _function The function that will result in the iterator.
  170. * @returns {object} `_target`.
  171. * @memberof module:barejs/polyfill.Object
  172. * @private
  173. */
  174. function setIterator( _target, _function )
  175. {
  176. var def = { configurable: true, value: _function };
  177. /*istanbul ignore else: always true in NodeJS*/
  178. if ( symIt )
  179. exports.defineProperty( _target, symIt, def );
  180. // Set @@iterator for compliancy with polyfill libraries like core.js
  181. exports.defineProperty( _target, "@@iterator", def );
  182. return _target;
  183. }
  184. exports.setIterator = setIterator;
  185. /**
  186. * Helper function that will get the ES6 iterator Symbol for a class.
  187. * @param {function} _class The constructor function to define the iterator on
  188. * @returns {object} The iterator, or null.
  189. * @memberof module:barejs/polyfill.Object
  190. * @private
  191. */
  192. function getIterator( _target )
  193. {
  194. var result = null;
  195. if ( _target )
  196. {
  197. var obj = Object( _target );
  198. if ( symIt &amp;&amp; ( symIt in obj ) )
  199. result = obj[symIt]();
  200. else if ( "@@iterator" in obj )
  201. result = obj["@@iterator"]();
  202. }
  203. return result;
  204. }
  205. exports.getIterator = getIterator;
  206. ////////////////////////////////////////////////////////////////////////////////////////////////////
  207. // Grab some methods that we may have to provide fallbacks for
  208. ////////////////////////////////////////////////////////////////////////////////////////////////////
  209. var modernPropertySupport = !!Object.defineProperties;
  210. var legacyPropertySupport = ( ( "__defineGetter__" in Object.prototype ) &amp;&amp; ( "__defineSetter__" in Object.prototype ) );
  211. /*istanbul ignore next: We know we have Object.defineProperties in NodeJS*/
  212. exports.propertyGetSetSupport = modernPropertySupport || legacyPropertySupport;
  213. // Take care not to grab IE8's defineProperty that only works on DOM elements.
  214. /*istanbul ignore else: native in NodeJS*/
  215. if ( modernPropertySupport )
  216. {
  217. exports.defineProperty = Object.defineProperty;
  218. exports.defineProperties = Object.defineProperties;
  219. exports.getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  220. exports.getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
  221. }
  222. exports.getPrototypeOf = Object.getPrototypeOf;
  223. exports.freeze = Object.freeze;
  224. exports.isFrozen = Object.isFrozen;
  225. exports.seal = Object.seal;
  226. exports.isSealed = Object.isSealed;
  227. // ES6
  228. exports.getOwnPropertyNames = Object.getOwnPropertyNames;
  229. exports.getOwnPropertySymbols = Object.getOwnPropertySymbols;
  230. /*istanbul ignore else: The tests are run with __ES__ set to 3*/
  231. if ( __ES__ &lt; 5 )
  232. {
  233. ////////////////////////////////////////////////////////////////////////////////////////////////
  234. // ES5 fallback functions
  235. ////////////////////////////////////////////////////////////////////////////////////////////////
  236. // The following methods are not actually polyfills; these methods cannot be polyfilled.
  237. // However, if the fallback behavior provided by the methods is sufficient, these can be used.
  238. /*istanbul ignore if: native in NodeJS*/
  239. if ( !exports.defineProperty )
  240. {
  241. /*
  242. * Object.defineProperty cannot be emulated on browsers that do not support it.
  243. * However, if the intention is to just set a value (no getters/setters), and the loss of
  244. * enumerable, writable and configurable flags is acceptable, this method can be used.
  245. * Uses the native method where possible
  246. *
  247. * Note: check for compliance via Object.defineProperties, since IE8 has an Object.defineProperty,
  248. * but that only works on DOM elements.
  249. */
  250. exports.defineProperty = function defineProperty( _object, _name, _definition )
  251. {
  252. if ( !isObject( _object ) )
  253. throw new TypeError( "Object.defineProperty called on non-object" );
  254. /*
  255. * Fallback to simple assignment or __define[GS]etter__
  256. */
  257. // Only assign if it actually exists.
  258. if ( "value" in _definition )
  259. {
  260. _object[_name] = _definition.value;
  261. }
  262. else if ( ( "get" in _definition ) || ( "set" in _definition ) )
  263. {
  264. if ( !exports.propertyGetSetSupport )
  265. throw new Error( "Property getters and setters are not supported in this environment" );
  266. if ( "get" in _definition )
  267. _object.__defineGetter__( _name, _definition.get );
  268. if ( "set" in _definition )
  269. _object.__defineSetter__( _name, _definition.set );
  270. }
  271. return _object;
  272. };
  273. }
  274. /*istanbul ignore if: native in NodeJS*/
  275. if ( !exports.defineProperties )
  276. {
  277. /*
  278. * Uses the possibly emulated defineProperty and behaves like Object.defineProperties.
  279. * Can only be used to set values (no getters/setters) in environments that do not support getters/setters.
  280. * Uses the native method where possible
  281. */
  282. exports.defineProperties = function defineProperties( _object, _properties )
  283. {
  284. if ( !isObject( _object ) )
  285. throw new TypeError( "Object.defineProperties called on non-object" );
  286. _properties = toObject( _properties );
  287. // Assume there is no Object.keys in an environment that requires this polyfill.
  288. for ( var i in _properties )
  289. if ( hasOwnProperty.call( _properties, i ) &amp;&amp; ( !reSymbol.test( i ) ) ) // Ignore Symbols
  290. exports.defineProperty( _object, i, _properties[i] );
  291. return _object;
  292. };
  293. }
  294. /*istanbul ignore if: native in NodeJS*/
  295. if ( !exports.getPrototypeOf )
  296. {
  297. /**
  298. * Object.getPrototypeOf cannot be fully emulated on browsers that do not support it.
  299. * We attempt to find a __proto__ or constructor.prototype.
  300. * Attempt to get an objects prototype, returns null on failure
  301. * @param {object} _object The object to get the prototype of
  302. * @returns {object} The prototype of _object
  303. * @memberof module:barejs/polyfill.Object
  304. * @private
  305. */
  306. exports.getPrototypeOf = function getPrototypeOf( _object )
  307. {
  308. switch ( _object === null ? strUndef : typeof _object )
  309. {
  310. case "undefined":
  311. throw new TypeError( "Cannot convert undefined or null to object" );
  312. case "boolean":
  313. return Boolean.prototype;
  314. case "number":
  315. return Number.prototype;
  316. case "string":
  317. return String.prototype;
  318. case "function":
  319. return Function.prototype;
  320. // case "object", and any other host value
  321. default:
  322. // jshint -W103
  323. if ( "__proto__" in _object )
  324. return _object.__proto__;
  325. // jshint +W103
  326. // If the object has the constructor property, this is already a prototype
  327. if ( !hasOwnProperty.call( _object, "constructor" ) )
  328. return _object.constructor.prototype;
  329. // See if a framework set a superclass property
  330. else if ( _object.constructor.superclass )
  331. return _object.constructor.superclass.prototype;
  332. if ( Array.isArray( _object ) )
  333. return Array.prototype;
  334. return null;
  335. }
  336. };
  337. }
  338. /*istanbul ignore if: native in NodeJS*/
  339. if ( !exports.freeze )
  340. {
  341. /*
  342. * Object.freeze cannot be emulated. This method is a NOOP if Object.freeze is not supported.
  343. */
  344. exports.freeze = function freeze( _o ){ return _o; };
  345. }
  346. /*istanbul ignore if: native in NodeJS*/
  347. if ( !exports.isFrozen )
  348. {
  349. /*
  350. * Object.isFrozen cannot be emulated. This method is a NOOP if Object.isFrozen is not supported.
  351. */
  352. exports.isFrozen = function isFrozen( _o ){ return false; };
  353. }
  354. /*istanbul ignore if: native in NodeJS*/
  355. if ( !exports.seal )
  356. {
  357. /*
  358. * Object.seal cannot be emulated. This method is a NOOP if Object.seal is not supported.
  359. */
  360. exports.seal = function seal( _o ){ return _o; };
  361. }
  362. /*istanbul ignore if: native in NodeJS*/
  363. if ( !exports.isSealed )
  364. {
  365. /*
  366. * Object.isSealed cannot be emulated. This method is a NOOP if Object.isSealed is not supported.
  367. */
  368. exports.isSealed = function isSealed( _o ){ return false; };
  369. }
  370. ////////////////////////////////////////////////////////////////////////////////////////////////
  371. // ES5 polyfills
  372. ////////////////////////////////////////////////////////////////////////////////////////////////
  373. //
  374. // ES5 - Object
  375. //
  376. ( function()
  377. {
  378. /*global document, ActiveXObject*/
  379. var createEmpty;
  380. // While we generally prefer named constructors, avoid it here since it adds no value,
  381. // and may even be confusing when looking at the prototype chain.
  382. var Anonymous = function(){};
  383. //jshint -W103
  384. /*istanbul ignore else: NodeJS supports the __proto__ property*/
  385. if ( ( !( { __proto__: null } instanceof Object ) ) || ( typeof document === strUndef ) )
  386. {
  387. // We can use the deprecated __proto__ property to create an object with no prototype
  388. createEmpty = function()
  389. {
  390. return { __proto__: null };
  391. };
  392. }
  393. //jshint +W103
  394. else
  395. {
  396. // We grab a foreign Object.prototype so any object created from it has instanceof Object return false,
  397. // and we can safely delete all properties from it without breaking regular objects.
  398. createEmpty = function()
  399. {
  400. var shouldUseActiveX = ( function()
  401. {
  402. try
  403. {
  404. return !!( document.domain &amp;&amp; new ActiveXObject( "htmlfile" ) );
  405. }
  406. catch ( ex )
  407. {
  408. return false;
  409. }
  410. }() );
  411. function Empty() {}
  412. if ( shouldUseActiveX )
  413. {
  414. Empty.prototype = ( function( _xDoc )
  415. {
  416. _xDoc.write( "&lt;script>&lt;\/script>" );
  417. _xDoc.close();
  418. var empty = _xDoc.parentWindow.Object.prototype;
  419. _xDoc = null;
  420. return empty;
  421. }( new ActiveXObject( "htmlfile" ) ));
  422. }
  423. else
  424. {
  425. Empty.prototype = ( function( _parent, _iframe )
  426. {
  427. _iframe.style.display = "none";
  428. _parent.appendChild( _iframe );
  429. // jshint -W107
  430. _iframe.src = "javascript:";
  431. // jshint +W107
  432. var empty = _iframe.contentWindow.Object.prototype;
  433. _parent.removeChild( _iframe );
  434. _iframe = null;
  435. return empty;
  436. }( document.body || document.documentElement, document.createElement( "iframe" ) ) );
  437. }
  438. // Now delete all existing definitions on our "empty" object to make it truly empty
  439. ( function( _e )
  440. {
  441. delete _e.constructor;
  442. delete _e.hasOwnProperty;
  443. delete _e.propertyIsEnumerable;
  444. delete _e.isPrototypeOf;
  445. delete _e.toLocaleString;
  446. delete _e.toString;
  447. delete _e.valueOf;
  448. }( Empty.prototype ) );
  449. // Shortcut createEmpty for future calls
  450. createEmpty = function()
  451. {
  452. // This returns an object for which instanceof Object is false
  453. return new Empty();
  454. };
  455. return createEmpty();
  456. };
  457. }
  458. /**
  459. * Create an instance of an object that has another object as its prototype
  460. * @param {object} _proto The prototype of the newly created object, or null.
  461. * @param {object} _properties
  462. * @returns {object} A new object that has the input object as prototype.
  463. */
  464. stat.create = function create( _proto, _properties )
  465. {
  466. var result;
  467. // _proto has 3 valid values: null or an Object (a function is an Object too)
  468. if ( _proto === null )
  469. {
  470. result = createEmpty();
  471. }
  472. else
  473. {
  474. if ( !isObject( _proto ) )
  475. throw new TypeError( "Object prototype may only be an Object or null: " + _proto );
  476. Anonymous.prototype = _proto;
  477. result = new Anonymous();
  478. Anonymous.prototype = null; // Reset prototype so we don't hold a reference to _proto
  479. }
  480. if ( typeof _properties !== strUndef )
  481. exports.defineProperties( result, toObject( _properties ) );
  482. return result;
  483. };
  484. }() );
  485. ( function()
  486. {
  487. var hasDontEnumBug = !( { toString: null } ).propertyIsEnumerable( "toString" ),
  488. dontEnums = [
  489. "toString",
  490. "toLocaleString",
  491. "valueOf",
  492. "hasOwnProperty",
  493. "isPrototypeOf",
  494. "propertyIsEnumerable",
  495. "constructor"
  496. ],
  497. dontEnumsLength = dontEnums.length;
  498. /**
  499. * Return the property names defined directly on object
  500. * @param {object} _obj The target object.
  501. * @returns {Array} String[] property names.
  502. */
  503. stat.keys = function keys( _obj )
  504. {
  505. // Ensure object
  506. _obj = toObject( _obj );
  507. var result = [];
  508. for ( var prop in _obj )
  509. if ( hasOwnProperty.call( _obj, prop ) &amp;&amp; ( !reSymbol.test( prop ) ) ) // Ignore Symbols
  510. result.push(prop);
  511. /*istanbul ignore if: not applicable in NodeJS*/
  512. if ( hasDontEnumBug )
  513. {
  514. for ( var i = 0; i &lt; dontEnumsLength; ++i )
  515. if ( hasOwnProperty.call( _obj, dontEnums[i] ) )
  516. result.push( dontEnums[i] );
  517. }
  518. return result;
  519. };
  520. }() );
  521. }
  522. /*istanbul ignore else: The tests are run with __ES__ set to 3*/
  523. if ( __ES__ &lt; 6 )
  524. {
  525. // Technically most of the methods set on exports are in ES5, but BareJS relies on them so ensure there's a fallback
  526. /*istanbul ignore if: native in NodeJS*/
  527. if ( !exports.getOwnPropertyNames )
  528. {
  529. exports.getOwnPropertyNames = function( _object )
  530. {
  531. var result = [];
  532. if ( _object )
  533. {
  534. var obj = Object( _object );
  535. for ( var key in obj )
  536. {
  537. if ( hasOwnProperty.call( obj, key ) &amp;&amp; typeof key === "string" )
  538. result.push( key );
  539. }
  540. }
  541. return result;
  542. };
  543. }
  544. /*istanbul ignore if: native in NodeJS*/
  545. if ( !exports.getOwnPropertySymbols )
  546. {
  547. exports.getOwnPropertySymbols = function getOwnPropertySymbols( _target )
  548. {
  549. // Ensure object
  550. _target = toObject( _target );
  551. var result = [];
  552. for ( var prop in _target )
  553. if ( hasOwnProperty.call( _target, prop ) &amp;&amp; ( reSymbol.test( prop ) ) )
  554. result.push(prop);
  555. return result;
  556. };
  557. }
  558. /*istanbul ignore if: native in NodeJS*/
  559. if ( !exports.getOwnPropertyDescriptor )
  560. {
  561. exports.getOwnPropertyDescriptor = function getOwnPropertyDescriptor( _object, _key )
  562. {
  563. var descriptor;
  564. if ( _object )
  565. {
  566. var obj = Object( _object );
  567. if ( hasOwnProperty.call( obj, _key ) )
  568. {
  569. descriptor = { configurable: true, enumerable: true };
  570. var getter;
  571. var setter;
  572. if ( legacyPropertySupport )
  573. {
  574. getter = obj.__lookupGetter__( _key );
  575. setter = obj.__lookupSetter__( _key );
  576. }
  577. if ( getter || setter )
  578. {
  579. if ( getter )
  580. descriptor.get = getter;
  581. if ( setter )
  582. descriptor.set = setter;
  583. }
  584. else
  585. {
  586. descriptor.value = obj[_key];
  587. }
  588. }
  589. }
  590. return descriptor;
  591. };
  592. }
  593. /*istanbul ignore if: native in NodeJS*/
  594. if ( !exports.getOwnPropertyDescriptors )
  595. {
  596. exports.getOwnPropertyDescriptors = function( _object )
  597. {
  598. var descriptors = {};
  599. if ( _object )
  600. {
  601. var names = exports.getOwnPropertyNames( _object );
  602. for ( var i = 0, len = names.length; i &lt; len; ++i )
  603. descriptors[names[i]] = exports.getOwnPropertyDescriptor( _object, names[i] );
  604. }
  605. return descriptors;
  606. };
  607. }
  608. /**
  609. * Object.is() determines whether two values are the same value. Two values are the same if one of the following holds:
  610. * - both undefined
  611. * - both null
  612. * - both true or both false
  613. * - both strings of the same length with the same characters
  614. * - both the same object
  615. * - both numbers and
  616. * - both +0
  617. * - both -0
  618. * - both NaN
  619. * - or both non-zero and both not NaN and both have the same value
  620. * @param _v1 The first value to compare.
  621. * @param _v2 The second value to compare.
  622. * @returns {boolean} A new object that has the input object as prototype.
  623. */
  624. stat.is = function is( _v1, _v2 )
  625. {
  626. if ( _v1 === _v2 )
  627. return ( _v1 !== 0 ) || ( 1 / _v1 === 1 / _v2 ); // Ensure Object.is( +0, -0 ) returns false
  628. else
  629. return ( _v1 !== _v1 ) &amp;&amp; ( _v2 !== _v2 ); // Ensure Object.is( NaN, NaN ) returns true
  630. };
  631. /**
  632. * The Object.assign() method only copies enumerable and own properties from a source object to a target object.
  633. * It uses [[Get]] on the source and [[Put]] on the target, so it will invoke getters and setters.
  634. * Therefore it assigns properties versus just copying or defining new properties.
  635. * This may make it unsuitable for merging new properties into a prototype if the merge sources contain getters.
  636. * For copying property definitions, including their enumerability, into prototypes Object.getOwnPropertyDescriptor() and Object.defineProperty() should be used instead.
  637. * @param {object} _target The target to assign to.
  638. * @param {object} _firstSource The first source object to copy from.
  639. * @returns {object} the _target, with properties assigned.
  640. */
  641. stat.assign = function assign( _target, _firstSource /*assign.length should be 2*/ )
  642. {
  643. // Ensure object
  644. _target = toObject( _target );
  645. for ( var arg = 1, argLen = arguments.length, source; arg &lt; argLen; ++arg )
  646. {
  647. if ( isObject( source = arguments[arg] ) )
  648. {
  649. for ( var key in source )
  650. {
  651. /*istanbul ignore else: clean prototypes assumed*/
  652. if ( hasOwnProperty.call( source, key ) )
  653. _target[key] = source[key];
  654. }
  655. }
  656. }
  657. return _target;
  658. };
  659. // End of ES6 polyfill scope
  660. }
  661. if ( __ES__ &lt; 7 )
  662. {
  663. /**
  664. * The Object.values() method returns an array of a given object's own enumerable property values,
  665. * in the same order as that provided by a for...in loop
  666. * (the difference being that a for-in loop enumerates properties in the prototype chain as well).
  667. * @param {object} _target The object to enumerate.
  668. * @returns {Array} The array of values
  669. */
  670. stat.values = function values( _target )
  671. {
  672. // Avoid using Array.map for speed (and perform in-place replacement)
  673. for ( var t = toObject( _target ), result = Object.keys( t ), i = 0, len = result.length; i &lt; len; ++i )
  674. result[i] = t[result[i]];
  675. return result;
  676. };
  677. /**
  678. * The Object.entries() method returns an array of a given object's own enumerable property [key, value] pairs,
  679. * in the same order as that provided by a for...in loop
  680. * (the difference being that a for-in loop enumerates properties in the prototype chain as well).
  681. * @param {object} _target The object to enumerate.
  682. * @returns {Array} The array of values
  683. */
  684. stat.entries = function entries( _target )
  685. {
  686. // Avoid using Array.map for speed (and perform in-place replacement)
  687. for ( var t = toObject( _target ), result = Object.keys( t ), i = 0, len = result.length; i &lt; len; ++i )
  688. result[i] = [ result[i], t[result[i]] ];
  689. return result;
  690. };
  691. // End of ES7 polyfill scope
  692. }
  693. // Apply static members (not using exports.polyfill since we only have static members)
  694. polyMixin( Object, stat, exports, "Object" );
  695. //
  696. // ES6 - ES5 Patching
  697. //
  698. /*istanbul ignore else: The tests are run with __ES__ set to 3*/
  699. if ( __ES__ &lt; 6 )
  700. {
  701. // It is possible Object.create exists (natively or polyfilled), but does not support the second
  702. // argument. In this case, we replace it with a method that will call defineProperties
  703. // We define this in the ES6 scope since we assume ES7 browsers will all support the optional second argument.
  704. /*istanbul ignore if: NodeJS's Object.create supports the second argument*/
  705. if ( Object.create( null, { test: { value: true } } ).test !== true )
  706. {
  707. Object.create = ( function( _originalCreate )
  708. {
  709. /**
  710. * Object.create wrapper that adds support for an optional second argument.
  711. */
  712. return function create( _proto, _properties )
  713. {
  714. var result = _originalCreate.call( Object, _proto ); // Call native Object.create
  715. if ( _properties )
  716. exports.defineProperties( result, _properties );
  717. return result;
  718. };
  719. }( Object.create ) );
  720. }
  721. }
  722. // End of module
  723. }( exports, Object ) );
  724. </code></pre>
  725. </article>
  726. </section>
  727. </div>
  728. <nav>
  729. <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-barejs.html">barejs</a></li><li><a href="module-barejs_polyfill.html">barejs/polyfill</a></li><li><a href="module-barejs_polyfill_Intl.html">barejs/polyfill/Intl</a></li></ul><h3>Classes</h3><ul><li><a href="module-barejs.decl.html">decl</a></li><li><a href="module-barejs.decl-Enum.html">Enum</a></li><li><a href="module-barejs.decl-Interface.html">Interface</a></li><li><a href="module-barejs.decl-SpecialType.html">SpecialType</a></li><li><a href="module-barejs.Destroyable.html">Destroyable</a></li><li><a href="module-barejs.EventArgs.html">EventArgs</a></li><li><a href="module-barejs.Evented.html">Evented</a></li><li><a href="module-barejs.Evented-EventedHandle.html">EventedHandle</a></li><li><a href="module-barejs.Exception.html">Exception</a></li><li><a href="module-barejs_polyfill.Array.html">Array</a></li><li><a href="module-barejs_polyfill.Date.html">Date</a></li><li><a href="module-barejs_polyfill.EntryStore.html">EntryStore</a></li><li><a href="module-barejs_polyfill.EntryStore.Iterator.html">Iterator</a></li><li><a href="module-barejs_polyfill.Function.html">Function</a></li><li><a href="module-barejs_polyfill.Map.html">Map</a></li><li><a href="module-barejs_polyfill.Map-MapIterator.html">MapIterator</a></li><li><a href="module-barejs_polyfill.Math.html">Math</a></li><li><a href="module-barejs_polyfill.Number.html">Number</a></li><li><a href="module-barejs_polyfill.Object.html">Object</a></li><li><a href="module-barejs_polyfill.Promise.html">Promise</a></li><li><a href="module-barejs_polyfill.Set.html">Set</a></li><li><a href="module-barejs_polyfill.Set-SetIterator.html">SetIterator</a></li><li><a href="module-barejs_polyfill.String.html">String</a></li><li><a href="module-barejs_polyfill.Symbol.html">Symbol</a></li><li><a href="module-barejs_polyfill.WeakMap.html">WeakMap</a></li><li><a href="module-barejs_polyfill.WeakSet.html">WeakSet</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat.html">DateTimeFormat</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat-DateTimeFormatOptions.html">DateTimeFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat.html">NumberFormat</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat-NumberFormatOptions.html">NumberFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl-Format.html">Format</a></li></ul>
  730. </nav>
  731. <br class="clear">
  732. <footer>
  733. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 03 2018 15:59:34 GMT+0200 (W. Europe Daylight Time)
  734. </footer>
  735. <script> prettyPrint(); </script>
  736. <script src="scripts/linenumber.js"> </script>
  737. </body>
  738. </html>