sandbox-globals.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <p>Run it both in Chrome and FF</p>
  2. <textarea id="results" style="width:30em; height: 90%" spellcheck="false"></textarea>
  3. <script>
  4. const el = document.getElementById('results');
  5. el.value = [
  6. function boundMethods() {
  7. const keys = [];
  8. /* global globalThis */
  9. for (const k in globalThis) {
  10. if (k >= 'a' && k <= 'z') {
  11. const { value } = Object.getOwnPropertyDescriptor(globalThis, k)
  12. || Object.getOwnPropertyDescriptor(EventTarget.prototype, k)
  13. || Object.getOwnPropertyDescriptor(Object.prototype, k)
  14. || {};
  15. if (typeof value === 'function') {
  16. if (k === 'createImageBitmap' || k === 'fetch') {
  17. keys.push(k);
  18. } else {
  19. try {
  20. globalThis[k].call({});
  21. } catch (e) {
  22. if (/Illegal invocation|implement interface/.test(e)) {
  23. keys.push(k);
  24. }
  25. }
  26. }
  27. }
  28. }
  29. }
  30. return keys.sort().map(k => `'${k}',`).join('\n');
  31. },
  32. function unforgeables() {
  33. return Object.entries(Object.getOwnPropertyDescriptors(window))
  34. .filter(([, v]) => !v.configurable)
  35. .map(([k]) => `'${k}',`)
  36. .sort()
  37. .join('\n');
  38. },
  39. function readonlys() {
  40. return Object.entries(Object.getOwnPropertyDescriptors(window))
  41. .filter(([k, v]) => k >= 'a' && k <= 'z'
  42. && k !== 'webkitStorageInfo' // deprecated
  43. && v.get && !v.set && v.configurable)
  44. .map(([k]) => `'${k}',`)
  45. .sort()
  46. .join('\n');
  47. },
  48. ].map(fn => `// ${fn.name}\n${fn()}\n`).join('\n');
  49. el.focus();
  50. el.select();
  51. </script>