Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/compat.js

Issue 29345407: Issue 4090 - Make require() load modules lazily (Closed)
Patch Set: Created May 31, 2016, 11:37 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compat.js
===================================================================
--- a/lib/compat.js
+++ b/lib/compat.js
@@ -16,18 +16,22 @@
*/
//
// Module framework stuff
//
function require(module)
{
- return require.scopes[module];
+ let result = require.scopes[module];
+ if (typeof result == "function" && !(module in require.loaded))
Sebastian Noack 2016/05/31 11:44:27 Where is it actually added to require.loaded?
Wladimir Palant 2016/05/31 13:47:54 I probably should have tested this code path :) I
+ result = require.scopes[module] = result();
+ return result;
}
+require.loaded = Object.create(null);
require.scopes = Object.create(null);
function importAll(module, globalObj)
{
var exports = require(module);
for (var key in exports)
globalObj[key] = exports[key];
}
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld