Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

object-create.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. /* global ActiveXObject -- old IE, WSH */
  3. var anObject = require('../internals/an-object');
  4. var definePropertiesModule = require('../internals/object-define-properties');
  5. var enumBugKeys = require('../internals/enum-bug-keys');
  6. var hiddenKeys = require('../internals/hidden-keys');
  7. var html = require('../internals/html');
  8. var documentCreateElement = require('../internals/document-create-element');
  9. var sharedKey = require('../internals/shared-key');
  10. var GT = '>';
  11. var LT = '<';
  12. var PROTOTYPE = 'prototype';
  13. var SCRIPT = 'script';
  14. var IE_PROTO = sharedKey('IE_PROTO');
  15. var EmptyConstructor = function () { /* empty */ };
  16. var scriptTag = function (content) {
  17. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  18. };
  19. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  20. var NullProtoObjectViaActiveX = function (activeXDocument) {
  21. activeXDocument.write(scriptTag(''));
  22. activeXDocument.close();
  23. var temp = activeXDocument.parentWindow.Object;
  24. // eslint-disable-next-line no-useless-assignment -- avoid memory leak
  25. activeXDocument = null;
  26. return temp;
  27. };
  28. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  29. var NullProtoObjectViaIFrame = function () {
  30. // Thrash, waste and sodomy: IE GC bug
  31. var iframe = documentCreateElement('iframe');
  32. var JS = 'java' + SCRIPT + ':';
  33. var iframeDocument;
  34. iframe.style.display = 'none';
  35. html.appendChild(iframe);
  36. // https://github.com/zloirock/core-js/issues/475
  37. iframe.src = String(JS);
  38. iframeDocument = iframe.contentWindow.document;
  39. iframeDocument.open();
  40. iframeDocument.write(scriptTag('document.F=Object'));
  41. iframeDocument.close();
  42. return iframeDocument.F;
  43. };
  44. // Check for document.domain and active x support
  45. // No need to use active x approach when document.domain is not set
  46. // see https://github.com/es-shims/es5-shim/issues/150
  47. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  48. // avoid IE GC bug
  49. var activeXDocument;
  50. var NullProtoObject = function () {
  51. try {
  52. activeXDocument = new ActiveXObject('htmlfile');
  53. } catch (error) { /* ignore */ }
  54. NullProtoObject = typeof document != 'undefined'
  55. ? document.domain && activeXDocument
  56. ? NullProtoObjectViaActiveX(activeXDocument) // old IE
  57. : NullProtoObjectViaIFrame()
  58. : NullProtoObjectViaActiveX(activeXDocument); // WSH
  59. var length = enumBugKeys.length;
  60. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  61. return NullProtoObject();
  62. };
  63. hiddenKeys[IE_PROTO] = true;
  64. // `Object.create` method
  65. // https://tc39.es/ecma262/#sec-object.create
  66. // eslint-disable-next-line es/no-object-create -- safe
  67. module.exports = Object.create || function create(O, Properties) {
  68. var result;
  69. if (O !== null) {
  70. EmptyConstructor[PROTOTYPE] = anObject(O);
  71. result = new EmptyConstructor();
  72. EmptyConstructor[PROTOTYPE] = null;
  73. // add "__proto__" for Object.getPrototypeOf polyfill
  74. result[IE_PROTO] = O;
  75. } else result = NullProtoObject();
  76. return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
  77. };