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

Unified Diff: dart/sdk/lib/_internal/lib/js_types.dart

Issue 23996002: Use interceptors to handle runtime types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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: dart/sdk/lib/_internal/lib/js_types.dart
diff --git a/dart/sdk/lib/_internal/lib/js_types.dart b/dart/sdk/lib/_internal/lib/js_types.dart
new file mode 100644
index 0000000000000000000000000000000000000000..81a3df0ca25fd340c7c7d668b9e7eae0c3b9f713
--- /dev/null
+++ b/dart/sdk/lib/_internal/lib/js_types.dart
@@ -0,0 +1,87 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of _interceptors;
+
+class JsType {}
+
+/**
+ * Interceptor for JavaScript constructor functions that create Dart
ngeoffray 2013/09/06 06:54:06 What is a JavaScript constructor function? Somethi
ahe 2013/09/09 11:26:29 Done.
+ * objects. This is used for a variety of things, such as reflection and
+ * runtime types.
+ */
+class JsRuntimeType extends Interceptor implements JsType {
+ const JsRuntimeType();
+
+ String get mangledName => JS('String', r'#.builtin$cls', this);
+
+ String get name {
+ String m = mangledName;
+ String n = unmangleGlobalNameIfPreservedAnyways(m);
+ return n == null ? m : n;
+ }
+
+ String toString() => "JsRuntimeType on '$name'";
+}
+
+/**
+ * Interceptor for JavaScript objects that represent function types.
ngeoffray 2013/09/06 06:54:06 Where do these JavaScript objects come from?
ahe 2013/09/09 11:26:29 Done.
+ */
+// TODO(ahe): Shouldn't use interceptors for this, instead create a constant.
ngeoffray 2013/09/06 06:54:06 What's "this"? How can you make it a constant?
ahe 2013/09/09 11:26:29 Done.
+class JsFunctionType extends Interceptor implements JsType {
+ const JsFunctionType();
+
+ bool get hasReturnType => JS('bool', '"ret" in #', this);
ngeoffray 2013/09/06 06:54:06 Maybe add a helper method hasPropertyIn(String pro
ahe 2013/09/09 11:26:29 I hope to be able to clean this up in a more funda
+ get returnType => JS('', '#.ret', this);
+
+ bool get isVoid => JS('bool', '!!#.void', this);
ngeoffray 2013/09/06 06:54:06 Will that work on the Android browser?
ahe 2013/09/09 11:26:29 I think it will now.
+
+ bool get hasArguments => JS('bool', '"args" in #', this);
+ List get arguments => JS('JSExtendableArray', '#.args', this);
+
+ bool get hasOptionalArguments => JS('bool', '"opt" in #', this);
+ List get optionalArguments => JS('JSExtendableArray', '#.opt', this);
+
+ bool get hasNamedArguments => JS('bool', '"named" in #', this);
+ get namedArguments => JS('=Object', '#.named', this);
+
+ String toString() {
+ var s = '(';
+ var sep = '';
+ if (hasArguments) {
+ for (var argument in arguments) {
+ s = '$s$sep${runtimeTypeToString(argument)}';
+ sep = ', ';
+ }
+ }
+ if (hasOptionalArguments) {
+ s = '$s$sep[';
+ sep = '';
+ for (var argument in optionalArguments) {
+ s = '$s$sep${runtimeTypeToString(argument)}';
+ sep = ', ';
+ }
+ s = '$s]';
+ }
+ if (hasNamedArguments) {
+ s = '${s}$sep{';
+ sep = '';
+ for (var name in extractKeys(namedArguments)) {
+ var type = JS('', '#[#]', namedArguments, name);
+ s = '$s$sep$name: ${runtimeTypeToString(type)}';
+ sep = ', ';
+ }
+ s = '$s}';
+ }
+ s = '${s}) -> ';
+ if (isVoid) {
+ s = '${s}void';
+ } else if (hasReturnType) {
+ s = '$s${runtimeTypeToString(returnType)}';
+ } else {
+ s = '${s}dynamic';
+ }
+ return s;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698