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

Unified Diff: lib/runtime/dart_utils.js

Issue 1263583005: implement exports, fixes #141 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: rebase Created 5 years, 4 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
Index: lib/runtime/dart_utils.js
diff --git a/lib/runtime/dart_utils.js b/lib/runtime/dart_utils.js
index 39d4828e8123d0615ec2a2cf01edadbb8eb2d331..70555c729187a9577eebf25ccaff6bb7a202332b 100644
--- a/lib/runtime/dart_utils.js
+++ b/lib/runtime/dart_utils.js
@@ -49,32 +49,32 @@ var dart_utils =
* Defines a lazy property.
* After initial get or set, it will replace itself with a value property.
*/
- // TODO(jmesserly): is this the best implementation for JS engines?
// TODO(jmesserly): reusing descriptor objects has been shown to improve
// performance in other projects (e.g. webcomponents.js ShadowDOM polyfill).
function defineLazyProperty(to, name, desc) {
let init = desc.get;
- let writable = !!desc.set;
- function lazySetter(value) {
- defineProperty(to, name, { value: value, writable: writable });
+ let value = null;
+
+ function lazySetter(x) {
+ init = null;
+ value = x;
+ }
+ function circularInitError() {
+ throwError('circular initialization for field ' + name);
}
function lazyGetter() {
- // Clear the init function to detect circular initialization.
- let f = init;
- if (f === null) {
- throwError('circular initialization for field ' + name);
- }
- init = null;
+ if (init == null) return value;
- // Compute and store the value.
- let value = f();
- lazySetter(value);
+ // Compute and store the value, guarding against reentry.
+ let f = init;
+ init = circularInitError;
+ lazySetter(f());
return value;
}
desc.get = lazyGetter;
desc.configurable = true;
- if (writable) desc.set = lazySetter;
- defineProperty(to, name, desc);
+ if (desc.set) desc.set = lazySetter;
+ return defineProperty(to, name, desc);
}
dart_utils.defineLazyProperty = defineLazyProperty;
@@ -85,15 +85,8 @@ var dart_utils =
}
dart_utils.defineLazy = defineLazy;
- function defineMemoizedGetter(obj, name, get) {
- let cache = null;
- function getter() {
- if (cache != null) return cache;
- cache = get();
- get = null;
- return cache;
- }
- defineProperty(obj, name, {get: getter, configurable: true});
+ function defineMemoizedGetter(obj, name, getter) {
+ return defineLazyProperty(obj, name, {get: getter});
}
dart_utils.defineMemoizedGetter = defineMemoizedGetter;
@@ -114,10 +107,17 @@ var dart_utils =
}
dart_utils.copyProperties = copyProperties;
-
- function instantiate(type, args) {
- return new type(...args);
+ /** Exports from one Dart module to another. */
+ function export_(to, from, show, hide) {
+ if (show == void 0) {
+ show = getOwnNamesAndSymbols(from);
+ }
+ if (hide != void 0) {
+ var hideMap = new Map(hide);
+ show = show.filter((k) => !hideMap.has(k));
+ }
+ return copyTheseProperties(to, from, show);
}
- dart_utils.instantiate = instantiate;
+ dart_utils.export = export_;
})(dart_utils);

Powered by Google App Engine
This is Rietveld 408576698