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

Side by Side Diff: dart/sdk/lib/_internal/lib/js_rti.dart

Issue 22859004: Improve type literals in minified mode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added a test, and changed how names are unmangled. Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This part contains helpers for supporting runtime type information. 6 * This part contains helpers for supporting runtime type information.
7 * 7 *
8 * The helper use a mixture of Dart and JavaScript objects. To indicate which is 8 * The helper use a mixture of Dart and JavaScript objects. To indicate which is
9 * used where we adopt the scheme of using explicit type annotation for Dart 9 * used where we adopt the scheme of using explicit type annotation for Dart
10 * objects and 'var' or omitted return type for JavaScript objects. 10 * objects and 'var' or omitted return type for JavaScript objects.
(...skipping 28 matching lines...) Expand all
39 * 3) A function mapping the type variables of the object to be checked to 39 * 3) A function mapping the type variables of the object to be checked to
40 * a list expression. 40 * a list expression.
41 */ 41 */
42 42
43 part of _js_helper; 43 part of _js_helper;
44 44
45 Type createRuntimeType(String name) => new TypeImpl(name); 45 Type createRuntimeType(String name) => new TypeImpl(name);
46 46
47 class TypeImpl implements Type { 47 class TypeImpl implements Type {
48 final String _typeName; 48 final String _typeName;
49 String _unmangledName;
49 50
50 TypeImpl(this._typeName); 51 TypeImpl(this._typeName);
51 52
52 String toString() => _typeName; 53 String toString() {
54 if (_unmangledName != null) return _unmangledName;
55 String unmangledName = unmangleGlobalNameIfPreservedAnyways(_typeName);
56 // TODO(ahe): Handle type arguments.
57 if (unmangledName == null) unmangledName = _typeName;
58 return _unmangledName = unmangledName;
59 }
53 60
54 // TODO(ahe): This is a poor hashCode as it collides with its name. 61 // TODO(ahe): This is a poor hashCode as it collides with its name.
55 int get hashCode => _typeName.hashCode; 62 int get hashCode => _typeName.hashCode;
56 63
57 bool operator ==(other) { 64 bool operator ==(other) {
58 return (other is TypeImpl) && _typeName == other._typeName; 65 return (other is TypeImpl) && _typeName == other._typeName;
59 } 66 }
60 } 67 }
61 68
69 getMangledTypeName(TypeImpl type) => type._typeName;
70
62 /** 71 /**
63 * Sets the runtime type information on [target]. [typeInfo] is a type 72 * Sets the runtime type information on [target]. [typeInfo] is a type
64 * representation of type 4 or 5, that is, either a JavaScript array or 73 * representation of type 4 or 5, that is, either a JavaScript array or
65 * [:null:]. 74 * [:null:].
66 */ 75 */
67 Object setRuntimeTypeInfo(Object target, var typeInfo) { 76 Object setRuntimeTypeInfo(Object target, var typeInfo) {
68 assert(isNull(typeInfo) || isJsArray(typeInfo)); 77 assert(isNull(typeInfo) || isJsArray(typeInfo));
69 // We have to check for null because factories may return null. 78 // We have to check for null because factories may return null.
70 if (target != null) JS('var', r'#.$builtinTypeInfo = #', target, typeInfo); 79 if (target != null) JS('var', r'#.$builtinTypeInfo = #', target, typeInfo);
71 return target; 80 return target;
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 int getLength(var array) { 679 int getLength(var array) {
671 assert(isJsArray(array)); 680 assert(isJsArray(array));
672 return JS('int', r'#.length', array); 681 return JS('int', r'#.length', array);
673 } 682 }
674 683
675 /// Returns whether [value] is a JavaScript array. 684 /// Returns whether [value] is a JavaScript array.
676 bool isJsArray(var value) { 685 bool isJsArray(var value) {
677 return value is JSArray; 686 return value is JSArray;
678 } 687 }
679 688
680 hasField(var object, var name) => JS('bool', r'#[#] != null', object, name); 689 hasField(var object, var name) => JS('bool', r'# in #', name, object);
681 690
682 hasNoField(var object, var name) => JS('bool', r'#[#] == null', object, name); 691 hasNoField(var object, var name) => !hasField(object, name);
683 692
684 /// Returns [:true:] if [o] is a JavaScript function. 693 /// Returns [:true:] if [o] is a JavaScript function.
685 bool isJsFunction(var o) => JS('bool', r'typeof # == "function"', o); 694 bool isJsFunction(var o) => JS('bool', r'typeof # == "function"', o);
686 695
687 /// Returns [:true:] if [o] is a JavaScript object. 696 /// Returns [:true:] if [o] is a JavaScript object.
688 bool isJsObject(var o) => JS('bool', r"typeof # == 'object'", o); 697 bool isJsObject(var o) => JS('bool', r"typeof # == 'object'", o);
689 698
690 /** 699 /**
691 * Returns [:true:] if [o] is equal to [:null:], that is either [:null:] or 700 * Returns [:true:] if [o] is equal to [:null:], that is either [:null:] or
692 * [:undefined:]. We use this helper to avoid generating code under the invalid 701 * [:undefined:]. We use this helper to avoid generating code under the invalid
(...skipping 14 matching lines...) Expand all
707 * and [t] are Dart values. 716 * and [t] are Dart values.
708 */ 717 */
709 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t); 718 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t);
710 719
711 /** 720 /**
712 * Returns [:true:] if the JavaScript values [s] and [t] are not identical. We 721 * Returns [:true:] if the JavaScript values [s] and [t] are not identical. We
713 * use this helper to avoid generating code under the invalid assumption that 722 * use this helper to avoid generating code under the invalid assumption that
714 * [s] and [t] are Dart values. 723 * [s] and [t] are Dart values.
715 */ 724 */
716 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t); 725 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t);
OLDNEW
« no previous file with comments | « dart/sdk/lib/_internal/lib/js_names.dart ('k') | dart/tests/lib/mirrors/unmangled_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698