sandbox.js 960 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * The fake sandbox of browser environment
  3. */
  4. var path = require("path")
  5. var normalize = require("./winos").normalize
  6. exports.document = {
  7. getElementById: function(id) {
  8. // Return the fake loader script node
  9. if (id === "seajsnode") {
  10. return {
  11. hasAttribute: true,
  12. getAttribute: function() {},
  13. src: normalize(path.join(__dirname, "../dist/sea.js"))
  14. }
  15. }
  16. },
  17. getElementsByTagName: function(tag) {
  18. // Return the fake head node
  19. if (tag === "head") {
  20. return [{
  21. getElementsByTagName: function() {
  22. return []
  23. }
  24. }]
  25. }
  26. return []
  27. },
  28. URL: normalize(process.cwd() + "/index.js"),
  29. scripts: []
  30. }
  31. exports.location = {
  32. href: normalize(process.cwd() + "/index.js"),
  33. search: ""
  34. }
  35. exports.navigator = {
  36. userAgent: ""
  37. }
  38. exports.console = console
  39. exports.exports = { console: console }
  40. exports.setTimeout = setTimeout
  41. exports.process = process