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

Unified Diff: pkg/dev_compiler/lib/js/amd/dart_sdk.js

Side-by-side diff isn't available for this file because of its large size.
Issue 2515353003: Support lazy JS types. (Closed)
Patch Set: Support lazy JS types. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
Download patch
« no previous file with comments | « no previous file | pkg/dev_compiler/lib/js/common/dart_sdk.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/js/amd/dart_sdk.js
diff --git a/pkg/dev_compiler/lib/js/amd/dart_sdk.js b/pkg/dev_compiler/lib/js/amd/dart_sdk.js
index 2b7e741645c898051b34226fe19bbdefa4304809..7252d35bd6a579a08d32c5a4836f67cf05cad629 100644
--- a/pkg/dev_compiler/lib/js/amd/dart_sdk.js
+++ b/pkg/dev_compiler/lib/js/amd/dart_sdk.js
@@ -1147,6 +1147,23 @@ define([], function() {
}
return type[dart._typeObject] = new dart.WrappedType(type);
};
+ dart.lazyJSType = function(getJSTypeCallback, name) {
+ let key = getJSTypeCallback.toString();
+ if (dart._lazyJSTypes.has(key)) {
+ return dart._lazyJSTypes.get(key);
+ }
+ let ret = new dart.LazyJSType(getJSTypeCallback, name);
+ dart._lazyJSTypes.set(key, ret);
+ return ret;
+ };
+ dart.lazyAnonymousJSType = function(name) {
+ if (dart._lazyJSTypes.has(name)) {
+ return dart._lazyJSTypes.get(name);
+ }
+ let ret = new dart.LazyJSType(null, name);
+ dart._lazyJSTypes.set(name, ret);
+ return ret;
+ };
const _wrappedType = Symbol('_wrappedType');
dart.unwrapType = function(obj) {
return dart.dload(obj, _wrappedType);
@@ -1169,6 +1186,26 @@ define([], function() {
dart.tagLazy = function(value, compute) {
dart.defineLazyProperty(value, dart._runtimeType, {get: compute});
};
+ const _jsTypeCallback = Symbol('_jsTypeCallback');
+ const _rawJSType = Symbol('_rawJSType');
+ dart._isInstanceOfLazyJSType = function(o, t) {
+ if (t[_jsTypeCallback] != null) {
+ return dart.is(o, t[_rawJSType]);
+ }
+ if (o == null) return false;
+ return dart._isJSObject(o);
+ };
+ dart._asInstanceOfLazyJSType = function(o, t) {
+ if (t[_jsTypeCallback] != null) {
+ return dart.as(o, t[_rawJSType]);
+ }
+ if (o == null) return null;
+ if (!dart.test(dart._isJSObject(o))) dart._throwCastError(o, t, true);
+ return o;
+ };
+ dart._isJSObject = function(o) {
+ return !dart.getReifiedType(o)[dart._runtimeType];
+ };
dart._initialize2 = function() {
dart.TypeRep.prototype.is = function is_T(object) {
return dart.is(object, this);
@@ -1188,6 +1225,12 @@ define([], function() {
dart.Dynamic.prototype._check = function check_Dynamic(object) {
return object;
};
+ dart.LazyJSType.prototype.is = function is_T(object) {
+ return dart._isInstanceOfLazyJSType(object, this);
+ };
+ dart.LazyJSType.prototype.as = function as_T(object) {
+ return dart._asInstanceOfLazyJSType(object, this);
+ };
};
dart._functionType = function(definite, returnType, args, extra) {
if (args === void 0 && extra === void 0) {
@@ -1250,6 +1293,11 @@ define([], function() {
dart.isFunctionType = function(type) {
return type instanceof dart.AbstractFunctionType || type === core.Function;
};
+ dart.isLazyJSSubtype = function(t1, t2, covariant) {
+ if (dart.equals(t1, t2)) return true;
+ if (t1[_jsTypeCallback] == null || t2[_jsTypeCallback] == null) return true;
+ return dart.isClassSubType(t1[_rawJSType], t2[_rawJSType], covariant);
+ };
dart.isFunctionSubtype = function(ft1, ft2, covariant) {
if (ft2 === core.Function) {
return true;
@@ -1345,6 +1393,9 @@ define([], function() {
if (dart.isFunctionType(t1) && dart.isFunctionType(t2)) {
return dart.isFunctionSubtype(t1, t2, covariant);
}
+ if (t1 instanceof dart.LazyJSType && t2 instanceof dart.LazyJSType) {
+ return dart.isLazyJSSubtype(t1, t2, covariant);
+ }
return false;
};
dart.isClassSubType = function(t1, t2, covariant) {
@@ -2066,6 +2117,12 @@ define([], function() {
dart.dartx = dartx;
dart._runtimeType = Symbol("_runtimeType");
dart.isNamedConstructor = Symbol("isNamedConstructor");
+ dart.defineLazy(dart, {
+ get _lazyJSTypes() {
+ return new Map();
+ },
+ set _lazyJSTypes(_) {}
+ });
dart.metadata = Symbol("metadata");
dart._typeObject = Symbol("typeObject");
core.Object = class Object {
@@ -2136,6 +2193,28 @@ define([], function() {
return 'dynamic';
}
};
+ const _dartName = Symbol('_dartName');
+ dart.LazyJSType = class LazyJSType extends core.Object {
+ new(jsTypeCallback, dartName) {
+ this[_jsTypeCallback] = jsTypeCallback;
+ this[_dartName] = dartName;
+ }
+ get [_rawJSType]() {
+ return this[_jsTypeCallback]();
+ }
+ toString() {
+ return core.String._check(this[_jsTypeCallback] != null ? dart.typeName(this[_rawJSType]) : this[_dartName]);
+ }
+ };
+ dart.LazyJSType[dart.implements] = () => [core.Type];
+ dart.setSignature(dart.LazyJSType, {
+ constructors: () => ({new: dart.definiteFunctionType(dart.LazyJSType, [dart.dynamic, dart.dynamic])}),
+ fields: () => ({
+ [_jsTypeCallback]: dart.dynamic,
+ [_dartName]: dart.dynamic
+ }),
+ getters: () => ({[_rawJSType]: dart.definiteFunctionType(dart.dynamic, [])})
+ });
dart.dynamic = new dart.Dynamic();
dart._initialize = dart._initialize2();
dart.Void = class Void extends dart.TypeRep {
« no previous file with comments | « no previous file | pkg/dev_compiler/lib/js/common/dart_sdk.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698