Version 1
[yaffs-website] / node_modules / core-js / modules / _object-create.js
1 // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
2 var anObject    = require('./_an-object')
3   , dPs         = require('./_object-dps')
4   , enumBugKeys = require('./_enum-bug-keys')
5   , IE_PROTO    = require('./_shared-key')('IE_PROTO')
6   , Empty       = function(){ /* empty */ }
7   , PROTOTYPE   = 'prototype';
8
9 // Create object with fake `null` prototype: use iframe Object with cleared prototype
10 var createDict = function(){
11   // Thrash, waste and sodomy: IE GC bug
12   var iframe = require('./_dom-create')('iframe')
13     , i      = enumBugKeys.length
14     , lt     = '<'
15     , gt     = '>'
16     , iframeDocument;
17   iframe.style.display = 'none';
18   require('./_html').appendChild(iframe);
19   iframe.src = 'javascript:'; // eslint-disable-line no-script-url
20   // createDict = iframe.contentWindow.Object;
21   // html.removeChild(iframe);
22   iframeDocument = iframe.contentWindow.document;
23   iframeDocument.open();
24   iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
25   iframeDocument.close();
26   createDict = iframeDocument.F;
27   while(i--)delete createDict[PROTOTYPE][enumBugKeys[i]];
28   return createDict();
29 };
30
31 module.exports = Object.create || function create(O, Properties){
32   var result;
33   if(O !== null){
34     Empty[PROTOTYPE] = anObject(O);
35     result = new Empty;
36     Empty[PROTOTYPE] = null;
37     // add "__proto__" for Object.getPrototypeOf polyfill
38     result[IE_PROTO] = O;
39   } else result = createDict();
40   return Properties === undefined ? result : dPs(result, Properties);
41 };