install_common_globals.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = function(globalObject, globals) {
  6. globalObject.process = (0,
  7. (_create_process_object || _load_create_process_object()).default)();
  8. // Keep a reference to "Promise", since "jasmine_light.js" needs it.
  9. globalObject[globalObject.Symbol.for('jest-native-promise')] = Promise;
  10. // Forward some APIs.
  11. DTRACE.forEach(dtrace => {
  12. globalObject[dtrace] = function() {
  13. for (
  14. var _len = arguments.length, args = Array(_len), _key = 0;
  15. _key < _len;
  16. _key++
  17. ) {
  18. args[_key] = arguments[_key];
  19. }
  20. return global[dtrace].apply(this, args);
  21. };
  22. });
  23. // Forward some others (this breaks the sandbox but for now it's OK).
  24. globalObject.Buffer = global.Buffer;
  25. globalObject.setImmediate = global.setImmediate;
  26. globalObject.clearImmediate = global.clearImmediate;
  27. return Object.assign(
  28. globalObject,
  29. (0, (_deep_cyclic_copy || _load_deep_cyclic_copy()).default)(globals)
  30. );
  31. };
  32. var _create_process_object;
  33. function _load_create_process_object() {
  34. return (_create_process_object = _interopRequireDefault(
  35. require('./create_process_object')
  36. ));
  37. }
  38. var _deep_cyclic_copy;
  39. function _load_deep_cyclic_copy() {
  40. return (_deep_cyclic_copy = _interopRequireDefault(
  41. require('./deep_cyclic_copy')
  42. ));
  43. }
  44. function _interopRequireDefault(obj) {
  45. return obj && obj.__esModule ? obj : {default: obj};
  46. }
  47. /**
  48. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  49. *
  50. * This source code is licensed under the MIT license found in the
  51. * LICENSE file in the root directory of this source tree.
  52. *
  53. *
  54. */
  55. const DTRACE = Object.keys(global).filter(key => key.startsWith('DTRACE'));