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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of _interceptors;
6
7 class JsType {}
8
9 /**
10 * 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.
11 * objects. This is used for a variety of things, such as reflection and
12 * runtime types.
13 */
14 class JsRuntimeType extends Interceptor implements JsType {
15 const JsRuntimeType();
16
17 String get mangledName => JS('String', r'#.builtin$cls', this);
18
19 String get name {
20 String m = mangledName;
21 String n = unmangleGlobalNameIfPreservedAnyways(m);
22 return n == null ? m : n;
23 }
24
25 String toString() => "JsRuntimeType on '$name'";
26 }
27
28 /**
29 * 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.
30 */
31 // 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.
32 class JsFunctionType extends Interceptor implements JsType {
33 const JsFunctionType();
34
35 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
36 get returnType => JS('', '#.ret', this);
37
38 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.
39
40 bool get hasArguments => JS('bool', '"args" in #', this);
41 List get arguments => JS('JSExtendableArray', '#.args', this);
42
43 bool get hasOptionalArguments => JS('bool', '"opt" in #', this);
44 List get optionalArguments => JS('JSExtendableArray', '#.opt', this);
45
46 bool get hasNamedArguments => JS('bool', '"named" in #', this);
47 get namedArguments => JS('=Object', '#.named', this);
48
49 String toString() {
50 var s = '(';
51 var sep = '';
52 if (hasArguments) {
53 for (var argument in arguments) {
54 s = '$s$sep${runtimeTypeToString(argument)}';
55 sep = ', ';
56 }
57 }
58 if (hasOptionalArguments) {
59 s = '$s$sep[';
60 sep = '';
61 for (var argument in optionalArguments) {
62 s = '$s$sep${runtimeTypeToString(argument)}';
63 sep = ', ';
64 }
65 s = '$s]';
66 }
67 if (hasNamedArguments) {
68 s = '${s}$sep{';
69 sep = '';
70 for (var name in extractKeys(namedArguments)) {
71 var type = JS('', '#[#]', namedArguments, name);
72 s = '$s$sep$name: ${runtimeTypeToString(type)}';
73 sep = ', ';
74 }
75 s = '$s}';
76 }
77 s = '${s}) -> ';
78 if (isVoid) {
79 s = '${s}void';
80 } else if (hasReturnType) {
81 s = '$s${runtimeTypeToString(returnType)}';
82 } else {
83 s = '${s}dynamic';
84 }
85 return s;
86 }
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698