Skip to content

Commit

Permalink
Do not assume global variables are assigned to self.
Browse files Browse the repository at this point in the history
`requirejs` is a global variable (provided by [loader.js
here](https://github.com/ember-cli/loader.js/blob/v4.7.0/lib/loader/loader.js#L1)).
The prior code made the assumption that all global variables are
assigned to `self`/`window`, but this is _only_ true in some
circumstances. For example, when the entire bundle is evaluated within
an IIFE `self.requirejs` is undefined.
  • Loading branch information
rwjblue committed Nov 2, 2019
1 parent 6563435 commit b79fb98
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion addon/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
declare global {
var requirejs: {
_eak_seen: Object;
};
}

import Engine from '@ember/engine';
import require from 'require';

Expand Down Expand Up @@ -39,7 +45,7 @@ export default function loadInitializers(app: typeof Engine, prefix: string): vo
var instanceInitializers = [];
// this is 2 pass because generally the first pass is the problem
// and is reduced, and resolveInitializer has potential to deopt
var moduleNames = Object.keys(self.requirejs._eak_seen);
var moduleNames = Object.keys(requirejs._eak_seen);
for (var i = 0; i < moduleNames.length; i++) {
var moduleName = moduleNames[i];
if (moduleName.lastIndexOf(initializerPrefix, 0) === 0) {
Expand Down

0 comments on commit b79fb98

Please sign in to comment.