mirror of
https://github.com/atom/atom.git
synced 2026-02-04 11:45:16 -05:00
Add more window globals and shims in task shell
This allows jQuery to be successfully loaded from a web worker since it does not have a document or window object by default. Previously it would log about missing methods and properties. Closes #228
This commit is contained in:
@@ -12,6 +12,19 @@ self.console =
|
||||
log: -> callTaskMethod 'log', arguments...
|
||||
error: -> callTaskMethod 'error', arguments...
|
||||
|
||||
window.document =
|
||||
createElement: ->
|
||||
setAttribute: ->
|
||||
getElementsByTagName: -> []
|
||||
appendChild: ->
|
||||
documentElement:
|
||||
insertBefore: ->
|
||||
removeChild: ->
|
||||
getElementById: -> {}
|
||||
createComment: -> {}
|
||||
createDocumentFragment: -> {}
|
||||
self.document = window.document
|
||||
|
||||
# `callTaskMethod` can be used to invoke method's on the parent `Task` object
|
||||
# back in the window thread.
|
||||
self.callTaskMethod = (method, args...) ->
|
||||
@@ -19,9 +32,10 @@ self.callTaskMethod = (method, args...) ->
|
||||
|
||||
# The worker's initial handler replaces itself when `start` is invoked
|
||||
self.handler =
|
||||
start: ({resourcePath, requirePath, handlerPath}) ->
|
||||
self.resourcePath = resourcePath
|
||||
window.resourcePath = resourcePath
|
||||
start: ({resourcePath, globals, requirePath, handlerPath}) ->
|
||||
for key, value of globals
|
||||
self[key] = value
|
||||
window[key] = value
|
||||
importScripts(requirePath)
|
||||
require 'config'
|
||||
self.handler = require(handlerPath)
|
||||
|
||||
@@ -17,7 +17,10 @@ class Task
|
||||
|
||||
startWorker: ->
|
||||
@callWorkerMethod 'start'
|
||||
resourcePath: window.resourcePath
|
||||
globals:
|
||||
resourcePath: window.resourcePath
|
||||
navigator:
|
||||
userAgent: navigator.userAgent
|
||||
requirePath: require.getPath('require')
|
||||
handlerPath: @path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user