Skip to content

Instantly share code, notes, and snippets.

@alangpierce
Created January 24, 2018 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alangpierce/9ca4eda80b148d7aba8e4b17d412f8f2 to your computer and use it in GitHub Desktop.
Save alangpierce/9ca4eda80b148d7aba8e4b17d412f8f2 to your computer and use it in GitHub Desktop.
Examples of undeclared global accesses in CoffeeScript soak operations
Example from SwitchyOmega/omega-target-chromium-extension/src/coffee/background.coffee:
168 | state = new OmegaTargetCurrent.BrowserStorage(localStorage, 'omega.local.')
169 |
> 170 | if chrome?.storage?.sync or browser?.storage?.sync
| ^^^^^^
171 | syncStorage = new OmegaTargetCurrent.Storage('sync')
172 | sync = new OmegaTargetCurrent.OptionsSync(syncStorage)
Example from SwitchyOmega/omega-target-chromium-extension/src/coffee/background.coffee:
168 | state = new OmegaTargetCurrent.BrowserStorage(localStorage, 'omega.local.')
169 |
> 170 | if chrome?.storage?.sync or browser?.storage?.sync
| ^^^^^^^
171 | syncStorage = new OmegaTargetCurrent.Storage('sync')
172 | sync = new OmegaTargetCurrent.OptionsSync(syncStorage)
Example from SwitchyOmega/omega-target-chromium-extension/src/coffee/omega_debug.coffee:
8 | filename = "OmegaLog_#{Date.now()}.txt"
9 |
> 10 | if browser?.downloads?.download?
| ^^^^^^^
11 | url = URL.createObjectURL(blob)
12 | browser.downloads.download({url: url, filename: filename})
Example from SwitchyOmega/omega-target-chromium-extension/src/module/options.coffee:
4 | querystring = require('querystring')
5 | chromeApiPromisify = require('./chrome_api').chromeApiPromisify
> 6 | if chrome?.proxy?.settings
| ^^^^^^
7 | proxySettings =
8 | clearAsync: chromeApiPromisify(chrome.proxy.settings, 'clear')
Example from SwitchyOmega/omega-target-chromium-extension/src/module/options.coffee:
128 | for watcher in @_proxyChangeWatchers
129 | watcher(details)
> 130 | if chrome?.proxy?.settings?.onChange?
| ^^^^^^
131 | chrome.proxy.settings.onChange.addListener @_proxyChangeListener
132 | @_proxyChangeWatchers.push(callback)
Example from SwitchyOmega/omega-target-chromium-extension/src/module/options.coffee:
132 | @_proxyChangeWatchers.push(callback)
133 | applyProfileProxy: (profile, meta) ->
> 134 | if chrome?.proxy?.settings?
| ^^^^^^
135 | return @applyProfileProxySettings(profile, meta)
136 | else if browser?.proxy?.registerProxyScript?
Example from SwitchyOmega/omega-target-chromium-extension/src/module/options.coffee:
134 | if chrome?.proxy?.settings?
135 | return @applyProfileProxySettings(profile, meta)
> 136 | else if browser?.proxy?.registerProxyScript?
| ^^^^^^^
137 | return @applyProfileProxyScript(profile, meta)
138 | else
Example from SwitchyOmega/omega-target-chromium-extension/src/module/storage.coffee:
37 |
38 | constructor: (@areaName) ->
> 39 | if browser?.storage?[@areaName]
| ^^^^^^^
40 | @storage = browser.storage[@areaName]
41 | else
Example from SwitchyOmega/omega-web/src/omega/app.coffee:
95 |
96 | angular.module('omega').factory 'downloadFile', ->
> 97 | if browser?.downloads?.download?
| ^^^^^^^
98 | return (blob, filename) ->
99 | url = URL.createObjectURL(blob)
Example from SwitchyOmega/omega-web/src/omega/controllers/fixed_profile.coffee:
39 | $scope.proxyEditors = {}
40 |
> 41 | socks5AuthSupported = (browser?.proxy?.register?)
| ^^^^^^^
42 | $scope.authSupported = {
43 | "http": true,
Example from SwitchyOmega/omega-web/src/omega/controllers/master.coffee:
4 | isProfileNameHidden, dispNameFilter, downloadFile) ->
5 |
> 6 | if not chrome?.proxy?.settings?
| ^^^^^^
7 | $scope.isExperimental = true
8 | $scope.pacProfilesUnsupported = true
Example from atom/bookmarks/lib/main.coffee:
36 |
37 | deactivate: ->
> 38 | bookmarksView?.destroy()
| ^^^^^^^^^^^^^
39 | bookmarks.deactivate() for bookmarks in editorsBookmarks
40 | disposables.dispose()
Example from atom/elmer/src/register-element.coffee:
20 | viewClass = document.registerElement(elementName, registerArgs)
21 |
> 22 | if elementPrototype.modelConstructor? and atom?.views?.addViewProvider?
| ^^^^
23 | atom.views.addViewProvider
24 | modelConstructor: elementPrototype.modelConstructor
Example from codecombat/app/core/CocoClass.coffee:
51 | listenToSubscriptions: ->
52 | # for initting subscriptions
> 53 | return unless Backbone?.Mediator?
| ^^^^^^^^
54 | for channel, func of @subscriptions
55 | func = utils.normalizeFunc(func, @)
Example from codecombat/app/core/CocoClass.coffee:
58 | addNewSubscription: (channel, func) ->
59 | # this is for adding subscriptions on the fly, rather than at init
> 60 | return unless Backbone?.Mediator?
| ^^^^^^^^
61 | return if @destroyed
62 | return unless @subscriptions[channel] is undefined
Example from codecombat/app/core/CocoClass.coffee:
66 |
67 | unsubscribeAll: ->
> 68 | return unless Backbone?.Mediator?
| ^^^^^^^^
69 | for channel, func of @subscriptions
70 | func = utils.normalizeFunc(func, @)
Example from codecombat/app/core/ParticleMan.coffee:
7 |
8 | constructor: ->
> 9 | return @unsupported = true unless Modernizr?.webgl # TODO: Fix with Webpack
| ^^^^^^^^^
10 | try
11 | @renderer = new THREE.WebGLRenderer alpha: true
Example from codecombat/app/core/Router.coffee:
334 | application.facebookHandler.renderButtons()
335 | application.gplusHandler.renderButtons()
> 336 | twttr?.widgets?.load?()
| ^^^^^
337 |
338 | activateTab: ->
Example from codecombat/app/core/Tracker.coffee:
86 | # Errorception
87 | # https://errorception.com/docs/meta
> 88 | _errs?.meta = traits
| ^^^^^
89 |
90 | # Inspectlet
Example from codecombat/app/core/Tracker.coffee:
90 | # Inspectlet
91 | # https://www.inspectlet.com/docs#identifying_users
> 92 | __insp?.push ['identify', me.id]
| ^^^^^^
93 | __insp?.push ['tagSession', traits]
94 |
Example from codecombat/app/core/Tracker.coffee:
91 | # https://www.inspectlet.com/docs#identifying_users
92 | __insp?.push ['identify', me.id]
> 93 | __insp?.push ['tagSession', traits]
| ^^^^^^
94 |
95 | # Mixpanel
Example from codecombat/app/core/Tracker.coffee:
116 | # Google Analytics
117 | # https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
> 118 | ga? 'send', 'pageview', url
| ^^
119 | ga?('codeplay.send', 'pageview', url) if features.codePlay
120 | window.snowplow 'trackPageView'
Example from codecombat/app/core/Tracker.coffee:
117 | # https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
118 | ga? 'send', 'pageview', url
> 119 | ga?('codeplay.send', 'pageview', url) if features.codePlay
| ^^
120 | window.snowplow 'trackPageView'
121 |
Example from codecombat/app/core/Tracker.coffee:
147 | gaFieldObject.eventLabel = properties.label if properties.label?
148 | gaFieldObject.eventValue = properties.value if properties.value?
> 149 | ga? 'send', gaFieldObject
| ^^
150 | ga? 'codeplay.send', gaFieldObject if features.codePlay
151 |
Example from codecombat/app/core/Tracker.coffee:
148 | gaFieldObject.eventValue = properties.value if properties.value?
149 | ga? 'send', gaFieldObject
> 150 | ga? 'codeplay.send', gaFieldObject if features.codePlay
| ^^
151 |
152 | # Inspectlet
Example from codecombat/app/core/Tracker.coffee:
152 | # Inspectlet
153 | # http://www.inspectlet.com/docs#tagging
> 154 | __insp?.push ['tagSession', action: action, properies: properties]
| ^^^^^^
155 |
156 | # Mixpanel
Example from codecombat/app/core/Tracker.coffee:
165 | for integration in includeIntegrations
166 | options.integrations[integration] = true
> 167 | analytics?.track action, {}, options
| ^^^^^^^^^
168 |
169 | trackSnowplow: (event, properties) =>
Example from codecombat/app/core/Tracker.coffee:
231 | console.log 'Would track timing event:', arguments if debugAnalytics
232 | return unless me and @isProduction and not me.isAdmin() and not me.isSmokeTestUser()
> 233 | ga? 'send', 'timing', category, variable, duration, label
| ^^
234 |
235 | updateIntercomRegularly: ->
Example from codecombat/app/core/application.coffee:
63 | store.commit('updateFeatures', features)
64 |
> 65 | @isIPadApp = webkit?.messageHandlers? and navigator.userAgent?.indexOf('CodeCombat-iPad') isnt -1
| ^^^^^^
66 | $('body').addClass 'ipad' if @isIPadApp
67 | $('body').addClass 'picoctf' if window.serverConfig.picoCTF
Example from codecombat/app/core/auth.coffee:
23 | # TODO: Refactor to use User.logout
24 | return if features.codePlay
> 25 | FB?.logout?()
| ^^
26 | callback = ->
27 | location = _.result(currentView, 'logoutRedirectURL')
Example from codecombat/app/core/initialize.coffee:
114 | return unless me.isAdmin() or document.location.href.search(/codecombat.com/) is -1 or document.location.href.search(/\/editor\//) isnt -1
115 | ++currentErrors
> 116 | unless webkit?.messageHandlers # Don't show these notys on iPad
| ^^^^^^
117 | noty {
118 | text
Example from codecombat/app/core/initialize.coffee:
150 |
151 | setUpIOSLogging = ->
> 152 | return unless webkit?.messageHandlers
| ^^^^^^
153 | for level in ['debug', 'log', 'info', 'warn', 'error']
154 | do (level) ->
Example from codecombat/app/core/initialize.coffee:
157 | originalLog.apply console, arguments
158 | try
> 159 | webkit?.messageHandlers?.consoleLogHandler?.postMessage level: level, arguments: (a?.toString?() ? ('' + a) for a in arguments)
| ^^^^^^
160 | catch e
161 | webkit?.messageHandlers?.consoleLogHandler?.postMessage level: level, arguments: ['could not post log: ' + e]
Example from codecombat/app/core/initialize.coffee:
159 | webkit?.messageHandlers?.consoleLogHandler?.postMessage level: level, arguments: (a?.toString?() ? ('' + a) for a in arguments)
160 | catch e
> 161 | webkit?.messageHandlers?.consoleLogHandler?.postMessage level: level, arguments: ['could not post log: ' + e]
| ^^^^^^
162 |
163 | loadOfflineFonts = ->
Example from codecombat/app/core/services/paypal.coffee:
11 | makeButton = (options) ->
12 | { buttonContainerID, product, onPaymentStarted, onPaymentComplete, description } = options
> 13 | paypal?.Button.render(_.assign({
| ^^^^^^
14 | env: if application.isProduction() then 'production' else 'sandbox', # sandbox | production
15 |
Example from codecombat/app/core/social-handlers/FacebookHandler.coffee:
105 |
106 | renderButtons: ->
> 107 | setTimeout(FB.XFBML.parse, 10) if FB?.XFBML?.parse # Handles FB login and Like
| ^^
108 |
Example from codecombat/app/core/social-handlers/GPlusHandler.coffee:
132 |
133 | renderButtons: ->
> 134 | return false unless gapi?.plusone?
| ^^^^
135 | gapi.plusone.go?() # Handles +1 button
136 |
Example from codecombat/app/core/utils.coffee:
308 | # Fast, basic way to replace text in an element when you don't need much.
309 | # http://stackoverflow.com/a/4962398/540620
> 310 | if document?.createElement
| ^^^^^^^^
311 | dummy = document.createElement 'div'
312 | dummy.innerHTML = 'text'
Example from codecombat/app/core/utils.coffee:
319 | # http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript/26230472#26230472
320 | # Don't use wantonly, or we'll have to implement a simple mechanism for clearing out old rules.
> 321 | if document?.createElement
| ^^^^^^^^
322 | injectCSS = ((doc) ->
323 | # wrapper for all injected styles and temp el to create them
Example from codecombat/app/lib/Angel.coffee:
209 | if $.browser
210 | context.browser = "#{$.browser.platform} #{$.browser.name} #{$.browser.versionNumber}"
> 211 | context.screenSize = "#{screen?.width ? $(window).width()} x #{screen?.height ? $(window).height()}"
| ^^^^^^
212 | context.subject = "Level Load Error: #{@work?.level?.name or 'Unknown Level'}"
213 | context.levelSlug = @work?.level?.slug
Example from codecombat/app/lib/Angel.coffee:
209 | if $.browser
210 | context.browser = "#{$.browser.platform} #{$.browser.name} #{$.browser.versionNumber}"
> 211 | context.screenSize = "#{screen?.width ? $(window).width()} x #{screen?.height ? $(window).height()}"
| ^^^^^^
212 | context.subject = "Level Load Error: #{@work?.level?.name or 'Unknown Level'}"
213 | context.levelSlug = @work?.level?.slug
Example from codecombat/app/lib/Angel.coffee:
308 | #### Synchronous code for running worlds on main thread (profiling / IE9) ####
309 | simulateSync: (work) =>
> 310 | console?.profile? "World Generation #{(Math.random() * 1000).toFixed(0)}" if imitateIE9?
| ^^^^^^^
311 | work.t0 = now()
312 | work.world = new World work.userCodeMap
Example from codecombat/app/lib/Angel.coffee:
369 | system.finish work.world.thangs for system in work.world.systems
370 | work.t2 = now()
> 371 | console?.profileEnd?() if imitateIE9?
| ^^^^^^^
372 | console.log 'Construction:', (work.t1 - work.t0).toFixed(0), 'ms. Simulation:', (work.t2 - work.t1).toFixed(0), 'ms --', ((work.t2 - work.t1) / work.world.frames.length).toFixed(3), 'ms per frame, profiled.'
373 |
Example from codecombat/app/lib/world/world_utils.coffee:
70 | return value
71 |
> 72 | module.exports.now = (if window?.performance?.now? then (-> window.performance.now()) else (-> new Date()))
| ^^^^^^
73 |
74 | module.exports.consolidateThangs = consolidateThangs = (thangs) ->
Example from codecombat/app/models/CocoModel.coffee:
176 | console.log 'going to log an error message'
177 | console.warn errorMessage, res.responseJSON
> 178 | unless webkit?.messageHandlers # Don't show these notys on iPad
| ^^^^^^
179 | try
180 | noty text: "#{errorMessage}: #{res.status} #{res.statusText}\n#{res.responseText}", layout: 'topCenter', type: 'error', killer: false, timeout: 10000
Example from codecombat/app/models/User.coffee:
296 | options.type = 'POST'
297 | options.url = '/auth/logout'
> 298 | FB?.logout?()
| ^^
299 | options.success ?= ->
300 | location = _.result(window.currentView, 'logoutRedirectURL')
Example from codecombat/app/views/account/AccountSettingsView.coffee:
129 | layout: 'topCenter'
130 | _.delay ->
> 131 | window?.webkit?.messageHandlers?.notification?.postMessage(name: "signOut") if window.application.isIPadApp
| ^^^^^^
132 | Backbone.Mediator.publish("auth:logging-out", {})
133 | window.tracker?.trackEvent 'Log Out', category:'Homepage' if @id is 'home-view'
Example from codecombat/app/views/admin/OutcomeReportResultView.coffee:
13 | @format = _.identity
14 |
> 15 | if window?.Intl?.NumberFormat?
| ^^^^^^
16 | intl = new window.Intl.NumberFormat()
17 | @format = intl.format.bind(intl)
Example from codecombat/app/views/core/CocoView.coffee:
522 | isIPadApp: ->
523 | return @_isIPadApp if @_isIPadApp?
> 524 | return @_isIPadApp = webkit?.messageHandlers? and navigator.userAgent?.indexOf('iPad') isnt -1
| ^^^^^^
525 |
526 | isIPadBrowser: ->
Example from codecombat/app/views/core/CocoView.coffee:
525 |
526 | isIPadBrowser: ->
> 527 | navigator?.userAgent?.indexOf('iPad') isnt -1
| ^^^^^^^^^
528 |
529 | isFirefox: ->
Example from codecombat/app/views/core/ContactModal.coffee:
49 | if $.browser
50 | context.browser = "#{$.browser.platform} #{$.browser.name} #{$.browser.versionNumber}"
> 51 | context.screenSize = "#{screen?.width ? $(window).width()} x #{screen?.height ? $(window).height()}"
| ^^^^^^
52 | context.screenshotURL = @screenshotURL
53 |
Example from codecombat/app/views/core/ContactModal.coffee:
49 | if $.browser
50 | context.browser = "#{$.browser.platform} #{$.browser.name} #{$.browser.versionNumber}"
> 51 | context.screenSize = "#{screen?.width ? $(window).width()} x #{screen?.height ? $(window).height()}"
| ^^^^^^
52 | context.screenshotURL = @screenshotURL
53 |
Example from codecombat/app/views/core/ModalView.coffee:
48 | $(document.activeElement).blur()
49 |
> 50 | if localStorage?.showViewNames
| ^^^^^^^^^^^^
51 | title = @constructor.name
52 | setTimeout ->
Example from codecombat/app/views/core/RootView.coffee:
59 |
60 | logoutAccount: ->
> 61 | window?.webkit?.messageHandlers?.notification?.postMessage(name: "signOut") if window.application.isIPadApp
| ^^^^^^
62 | Backbone.Mediator.publish("auth:logging-out", {})
63 | window.tracker?.trackEvent 'Log Out', category:'Homepage', ['Google Analytics'] if @id is 'home-view'
Example from codecombat/app/views/core/RootView.coffee:
121 | else title = 'CodeCombat - Learn how to code by playing a game'
122 |
> 123 | if localStorage?.showViewNames
| ^^^^^^^^^^^^
124 | title = @constructor.name
125 |
Example from codecombat/app/views/editor/level/modals/ArtisanGuideModal.coffee:
51 | if $.browser
52 | context.browser = "#{$.browser.platform} #{$.browser.name} #{$.browser.versionNumber}"
> 53 | context.screenSize = "#{screen?.width ? $(window).width()} x #{screen?.height ? $(window).height()}"
| ^^^^^^
54 | context.screenshotURL = @screenshotURL
55 |
Example from codecombat/app/views/editor/level/modals/ArtisanGuideModal.coffee:
51 | if $.browser
52 | context.browser = "#{$.browser.platform} #{$.browser.name} #{$.browser.versionNumber}"
> 53 | context.screenSize = "#{screen?.width ? $(window).width()} x #{screen?.height ? $(window).height()}"
| ^^^^^^
54 | context.screenshotURL = @screenshotURL
55 |
Example from codecombat/app/views/play/SpectateView.coffee:
289 | ]
290 | }
> 291 | history?.pushState? {}, '', url # Backbone won't update the URL if just query parameters change
| ^^^^^^^
292 |
293 | fetchRandomSessionPair: (cb) ->
Example from codecombat/app/views/play/level/modal/VictoryModal.coffee:
85 | super()
86 | @playSound 'victory'
> 87 | gapi?.plusone?.go? @$el[0]
| ^^^^
88 | FB?.XFBML?.parse? @$el[0]
89 | twttr?.widgets?.load?()
Example from codecombat/app/views/play/level/modal/VictoryModal.coffee:
86 | @playSound 'victory'
87 | gapi?.plusone?.go? @$el[0]
> 88 | FB?.XFBML?.parse? @$el[0]
| ^^
89 | twttr?.widgets?.load?()
90 |
Example from codecombat/app/views/play/level/modal/VictoryModal.coffee:
87 | gapi?.plusone?.go? @$el[0]
88 | FB?.XFBML?.parse? @$el[0]
> 89 | twttr?.widgets?.load?()
| ^^^^^
90 |
91 | destroy: ->
Example from codecombat/spec/server/functional/payment.spec.coffee:
519 | @admin = yield utils.initAdmin()
520 | yield utils.loginUser(@admin)
> 521 | payPal?.transactions?[0]?.related_resources?[0]?.sale?.id
| ^^^^^^
522 | @payment1 = yield utils.makePayment({payPal: transactions: [{related_resources: [{sale:{id:'abc'}}]}]})
523 | @payment2 = yield utils.makePayment({payPalSale: {id: '123'}})
Example from vimium/content_scripts/mode_key_handler.coffee:
47 | DomUtils.consumeKeyup event, => @reset()
48 | # If the help dialog loses the focus, then Escape should hide it; see point 2 in #2045.
> 49 | else if isEscape and HelpDialog?.isShowing()
| ^^^^^^^^^^
50 | HelpDialog.toggle()
51 | @suppressEvent
Example from vimium/content_scripts/mode_normal.coffee:
238 | " and not(@disabled or @readonly)]",
239 | "textarea", "*[@contenteditable='' or translate(@contenteditable, 'TRUE', 'true')='true']"]
> 240 | DomUtils?.makeXPath(inputElements)
| ^^^^^^^^
241 | )()
242 |
Example from vimium/lib/find_mode_history.coffee:
3 | # most recent first.
4 | FindModeHistory =
> 5 | storage: chrome?.storage.local # Guard against chrome being undefined (in the HUD iframe).
| ^^^^^^
6 | key: "findModeRawQueryList"
7 | max: 50
Example from vimium/lib/find_mode_history.coffee:
9 |
10 | init: ->
> 11 | @isIncognitoMode = chrome?.extension.inIncognitoContext
| ^^^^^^
12 |
13 | return unless @isIncognitoMode? # chrome is undefined in the HUD iframe during tests, so we do nothing.
Example from vimium/lib/keyboard_utils.coffee:
1 | mapKeyRegistry = {}
2 | # NOTE: "?" here for the tests.
> 3 | Utils?.monitorChromeStorage "mapKeyRegistry", (value) => mapKeyRegistry = value
| ^^^^^
4 |
5 | KeyboardUtils =
Example from vimium/lib/utils.coffee:
7 | true
8 |
> 9 | browserInfo = browser?.runtime?.getBrowserInfo?()
| ^^^^^^^
10 |
11 | Utils =
Example from vimium/lib/utils.coffee:
227 | monitorChromeStorage: (key, setter) ->
228 | # NOTE: "?" here for the tests.
> 229 | chrome?.storage.local.get key, (obj) =>
| ^^^^^^
230 | setter obj[key] if obj[key]?
231 | chrome.storage.onChanged.addListener (changes, area) =>
Example from vimium/pages/options.coffee:
264 | document.addEventListener "keyup", (event) ->
265 | if event.ctrlKey and event.keyCode == 13
> 266 | document.activeElement.blur() if document?.activeElement?.blur
| ^^^^^^^^
267 | saveOptions()
268 |
Example from vimium/pages/options.coffee:
358 | #
359 | # Backup and restore. "?" is for the tests."
> 360 | DomUtils?.documentReady ->
| ^^^^^^^^
361 | # Only initialize backup/restore on the options page (not the popup).
362 | return unless location.pathname == "/pages/options.html"
Example from yakyak/src/ui/models/index.coffee:
10 | module.exports = {entity, conv, viewstate, userinput, connection, convsettings, notify}
11 |
> 12 | window?.models = module.exports
| ^^^^^^
13 |
Example from yakyak/src/ui/util.coffee:
198 |
199 | # AutoLaunch requires a path unless you are running in electron/nw
> 200 | vesrions = process?.versions
| ^^^^^^^
201 | if versions? and (versions.nw? or versions['node-webkit']? or versions.electron?)
202 | autoLaunchPath = undefined
Example from yakyak/src/ui/views/notifications.coffee:
23 | tonot = notify.popToNotify()
24 |
> 25 | quietIf = (c, chat_id) -> document?.hasFocus() or conv.isQuiet(c) or entity.isSelf(chat_id)
| ^^^^^^^^
26 |
27 | tonot.forEach (msg) ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment