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

Side by Side Diff: tool/input_sdk/private/ddc_runtime/rtti.dart

Issue 2015513005: Tweak _checkPrimitiveType (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// This library defines the association between runtime objects and 5 /// This library defines the association between runtime objects and
6 /// runtime types. 6 /// runtime types.
7 part of dart._runtime; 7 part of dart._runtime;
8 8
9 /// Runtime type information. This module defines the mapping from 9 /// Runtime type information. This module defines the mapping from
10 /// runtime objects to their runtime type information. See the types 10 /// runtime objects to their runtime type information. See the types
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 lazyFn(closure, computeType) { 70 lazyFn(closure, computeType) {
71 tagLazy(closure, computeType); 71 tagLazy(closure, computeType);
72 return closure; 72 return closure;
73 } 73 }
74 74
75 // TODO(vsm): How should we encode the runtime type? 75 // TODO(vsm): How should we encode the runtime type?
76 final _runtimeType = JS('', 'Symbol("_runtimeType")'); 76 final _runtimeType = JS('', 'Symbol("_runtimeType")');
77 77
78 _checkPrimitiveType(obj) { 78 _checkPrimitiveType(obj) {
79 // TODO(jmesserly): JS is used to prevent type literal wrapping. 79 // TODO(jmesserly): JS is used to prevent type literal wrapping. Is there a
80 // Is there a better way we can handle this? 80 // better way we can handle this? (sra: It is super dodgy that the values
81 // passed to JS are different to the values passed to a regular function - the
82 // semantics are not longer that of calling an interpreter. dart2js has other
83 // special functions, we could do the same.)
81 84
82 // Check for null and undefined 85 // Check for null and undefined
83 if (obj == null) return JS('', '#', Null); 86 if (obj == null) return JS('', '#', Null);
84 switch (JS('String', 'typeof #', obj)) { 87
85 case "number": 88 if (JS('bool', 'typeof # == "number"', obj)) {
86 return JS('bool', 'Math.floor(#) == # ? # : #', obj, obj, int, double); 89 if (JS('bool', 'Math.floor(#) == #', obj, obj)) {
87 case "boolean": 90 return JS('', '#', int);
88 return JS('', '#', bool); 91 }
89 case "string": 92 return JS('', '#', double);
90 return JS('', '#', String);
91 case "symbol":
92 // Note: this is a JS Symbol, not a Dart one.
93 return JS('', '#', jsobject);
94 } 93 }
94
95 if (JS('bool', 'typeof # == "boolean"', obj)) {
96 return JS('', '#', bool);
97 }
98
99 if (JS('bool', 'typeof # == "string"', obj)) {
100 return JS('', '#', String);
101 }
102
103 if (JS('bool', 'typeof # == "symbol"', obj)) {
104 // Note: this is a JS Symbol, not a Dart one.
105 return JS('', '#', jsobject);
106 }
107
95 return null; 108 return null;
96 } 109 }
97 110
98 getFunctionType(obj) { 111 getFunctionType(obj) {
99 // TODO(vsm): Encode this properly on the function for Dart-generated code. 112 // TODO(vsm): Encode this properly on the function for Dart-generated code.
100 var args = JS('', 'Array(#.length).fill(#)', obj, dynamic); 113 var args = JS('', 'Array(#.length).fill(#)', obj, dynamic);
101 return definiteFunctionType(bottom, args, JS('', 'void 0')); 114 return definiteFunctionType(bottom, args, JS('', 'void 0'));
102 } 115 }
103 116
104 /// Returns an the runtime representation of the type of obj. 117 /// Returns an the runtime representation of the type of obj.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 171 }
159 172
160 void tagComputed(value, compute) { 173 void tagComputed(value, compute) {
161 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute); 174 JS('', '#(#, #, { get: # })', defineProperty, value, _runtimeType, compute);
162 } 175 }
163 176
164 void tagLazy(value, compute) { 177 void tagLazy(value, compute) {
165 JS('', '#(#, #, { get: # })', 178 JS('', '#(#, #, { get: # })',
166 defineLazyProperty, value, _runtimeType, compute); 179 defineLazyProperty, value, _runtimeType, compute);
167 } 180 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698