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

Unified Diff: lib/runtime/dart_runtime.js

Issue 1135883004: Make typedefs lazy again (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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 | « lib/runtime/dart/core.js ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/runtime/dart_runtime.js
diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js
index 34ec47aa50709b87b4646810b8dbcff32cbaa8ff..88738006ba70b68e3c9701a5843f8f4babffb628 100644
--- a/lib/runtime/dart_runtime.js
+++ b/lib/runtime/dart_runtime.js
@@ -210,7 +210,7 @@ var dart, _js_helper, _js_primitives;
if (t2 == core.Type) {
// Special case Types.
result = t1.prototype instanceof core.Type ||
- t1 instanceof FunctionType ||
+ t1 instanceof AbstractFunctionType ||
isSubtype_(t1, t2);
} else {
result = isSubtype_(t1, t2)
@@ -339,7 +339,7 @@ var dart, _js_helper, _js_primitives;
function isGroundType(type) {
// TODO(vsm): Cache this if we start using it at runtime.
- if (type instanceof FunctionType) {
+ if (type instanceof AbstractFunctionType) {
if (!_isTop(type.returnType, false)) return false;
for (let i = 0; i < type.args.length; ++i) {
if (!_isBottom(type.args[i], true)) return false;
@@ -390,14 +390,9 @@ var dart, _js_helper, _js_primitives;
return name;
}
- // TODO(jmesserly): extends Type?
- class FunctionType {
- constructor(returnType, args, optionals, named, opt_typedefName) {
- this.returnType = returnType;
- this.args = args;
- this.optionals = optionals;
- this.named = named;
- this._stringValue = opt_typedefName;
+ class AbstractFunctionType {
+ constructor() {
+ this._stringValue = null;
}
get name() {
@@ -439,6 +434,16 @@ var dart, _js_helper, _js_primitives;
}
}
+ class FunctionType extends AbstractFunctionType {
+ constructor(returnType, args, optionals, named) {
+ super();
+ this.returnType = returnType;
+ this.args = args;
+ this.optionals = optionals;
+ this.named = named;
+ }
+ }
+
function functionType(returnType, args, extra) {
// TODO(vsm): Cache / memomize?
var optionals;
@@ -457,19 +462,55 @@ var dart, _js_helper, _js_primitives;
}
dart.functionType = functionType;
- function typedef(name, functionType) {
- let f = functionType;
- return new FunctionType(f.returnType, f.args, f.optionals, f.named, name);
+ class Typedef extends AbstractFunctionType {
+ constructor(name, closure) {
+ super();
+ this._name = name;
+ this._closure = closure;
+ this._functionType = null;
+ }
+
+ get name() {
+ return this._name;
+ }
+
+ get functionType() {
+ if (!this._functionType) {
+ this._functionType = this._closure();
+ }
+ return this._functionType;
+ }
+
+ get returnType() {
+ return this.functionType.returnType;
+ }
+
+ get args() {
+ return this.functionType.args;
+ }
+
+ get optionals() {
+ return this.functionType.optionals;
+ }
+
+ get named() {
+ return this.functionType.named;
+ }
+ }
+
+ function typedef(name, closure) {
+ return new Typedef(name, closure);
}
dart.typedef = typedef;
function isFunctionType(type) {
- return isClassSubType(type, core.Function) || type instanceof FunctionType;
+ return isClassSubType(type, core.Function) ||
+ type instanceof AbstractFunctionType;
}
function getFunctionType(obj) {
// TODO(vsm): Encode this properly on the function for Dart-generated code.
- var args = Array.apply(null, new Array(obj.length)).map(function(){return core.Object});
+ var args = Array.apply(null, new Array(obj.length)).map(() => core.Object);
return functionType(dart.bottom, args);
}
« no previous file with comments | « lib/runtime/dart/core.js ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698