littledan/js-shared-interfaces

Globals to add

Opened this issue · 6 comments

List of globals to add:

  • console (#7)
  • crypto
  • Timers
  • WebWorkers
  • URL
  • URLSearchParams (#7)

Does Promise belong in the globals list?

That’s already a language builtin; what needs to be added?

setTimeout

The full range of global timer functions in Node.js:

  • clearImmediate
  • clearInterval
  • clearTimeout
  • setImmediate
  • setInterval
  • setTimeout

There are also queueMicrotask which is experimental, and WebAssembly which comes from V8. (Node.js's console is not entirely from V8 depending on where you are accessing it)

Also Node.js implements parts of the Performance Timing API but it's still experimental and I don't recall plans to make it a global. It is intentionally different from the browser in some cases (e.g. nodejs/node#19563)

BTW this script can be used to find Node.js-specific globals:

'use strict';

const vm = require('vm');
const globalsFromVM = JSON.parse(
  JSON.stringify(
    vm.runInNewContext('Reflect.ownKeys(globalThis)')
  )
);

const globalsFromNode = [];
for (const key of Reflect.ownKeys(globalThis)) {
  if (!globalsFromVM.includes(key)) {
    globalsFromNode.push(key);
  }
}

console.log(globalsFromNode.map(key => String(key)).join('\n'))