Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Unified Diff: pkg/dev_compiler/lib/js/legacy/dart_library.js

Issue 2699943003: Cleanup proxy/defer code (Closed)
Patch Set: Cleanup Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/js/legacy/dart_library.js
diff --git a/pkg/dev_compiler/lib/js/legacy/dart_library.js b/pkg/dev_compiler/lib/js/legacy/dart_library.js
index 19fa131fe0bb9f5b9cc3f2f825064a74881d366f..585b7a446b0228a15cdd06dc390c847aa98c7624 100644
--- a/pkg/dev_compiler/lib/js/legacy/dart_library.js
+++ b/pkg/dev_compiler/lib/js/legacy/dart_library.js
@@ -31,18 +31,28 @@ dart_library =
// This defers loading of a module until a library is actually used.
const loadedModule = Symbol('loadedModule');
dart_library.defer = function(module, name, patch) {
- var revocable = Proxy.revocable(module, {
+ let done = false;
+ function loadDeferred() {
+ done = true;
+ var mod = module[loadedModule];
+ var lib = mod[name];
+ // Install unproxied module and library in caller's context.
+ patch(mod, lib);
+ }
+ // The deferred library object. Note, the only legal operations on a Dart
+ // library object should be get (to read a top-level variable, method, or
+ // Class) or set (to write a top-level variable).
vsm 2017/02/17 15:16:17 A couple notes: (1) I'm no longer revoking the pro
+ return new Proxy({}, {
get: function(o, p) {
- var mod = o[loadedModule];
- var lib = mod[name];
- // Install unproxied module and library in caller's context.
- patch(mod, lib);
- // Ensure proxy is only used on first access.
- revocable.revoke();
- return lib[p];
- }
+ if (!done) loadDeferred();
+ return module[name][p];
+ },
+ set: function(o, p, value) {
+ if (!done) loadDeferred();
+ module[name][p] = value;
+ return true;
+ },
});
- return revocable.proxy;
};
class LibraryLoader {
@@ -85,6 +95,8 @@ dart_library =
// Load the library
let loader = this;
let library = this._library;
+ library[dartLibraryName] = this._name;
+ library[libraryImports] = this._imports;
vsm 2017/02/17 15:16:17 Note: these were getting set on the proxy instead
library[loadedModule] = library;
args.unshift(library);
@@ -95,22 +107,19 @@ dart_library =
} else {
// Load / parse other modules on demand.
let done = false;
- this._library = new Proxy(args, {
+ this._library = new Proxy(library, {
vsm 2017/02/17 15:16:17 Note, this is the module object, not the library o
get: function(o, name) {
- if (done) {
- return library[name];
+ if (!done) {
+ done = true;
+ loader._loader.apply(null, args);
+ loader._loader = null;
}
- done = true;
- loader._loader.apply(null, o);
- loader._loader = null;
- return library[name];
+ return o[name];
}
});
}
this._state = LibraryLoader.READY;
- this._library[dartLibraryName] = this._name;
- this._library[libraryImports] = this._imports;
return this._library;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698