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

Unified 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, 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_sdk.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/input_sdk/private/ddc_runtime/rtti.dart
diff --git a/tool/input_sdk/private/ddc_runtime/rtti.dart b/tool/input_sdk/private/ddc_runtime/rtti.dart
index 06bb28610c731fab5e12643c0a83a210fe1a522b..ee6a872197979211edc95ea5fdbac28dd9b14c0e 100644
--- a/tool/input_sdk/private/ddc_runtime/rtti.dart
+++ b/tool/input_sdk/private/ddc_runtime/rtti.dart
@@ -76,22 +76,35 @@ lazyFn(closure, computeType) {
final _runtimeType = JS('', 'Symbol("_runtimeType")');
_checkPrimitiveType(obj) {
- // TODO(jmesserly): JS is used to prevent type literal wrapping.
- // Is there a better way we can handle this?
+ // TODO(jmesserly): JS is used to prevent type literal wrapping. Is there a
+ // better way we can handle this? (sra: It is super dodgy that the values
+ // passed to JS are different to the values passed to a regular function - the
+ // semantics are not longer that of calling an interpreter. dart2js has other
+ // special functions, we could do the same.)
// Check for null and undefined
if (obj == null) return JS('', '#', Null);
- switch (JS('String', 'typeof #', obj)) {
- case "number":
- return JS('bool', 'Math.floor(#) == # ? # : #', obj, obj, int, double);
- case "boolean":
- return JS('', '#', bool);
- case "string":
- return JS('', '#', String);
- case "symbol":
- // Note: this is a JS Symbol, not a Dart one.
- return JS('', '#', jsobject);
+
+ if (JS('bool', 'typeof # == "number"', obj)) {
+ if (JS('bool', 'Math.floor(#) == #', obj, obj)) {
+ return JS('', '#', int);
+ }
+ return JS('', '#', double);
+ }
+
+ if (JS('bool', 'typeof # == "boolean"', obj)) {
+ return JS('', '#', bool);
+ }
+
+ if (JS('bool', 'typeof # == "string"', obj)) {
+ return JS('', '#', String);
}
+
+ if (JS('bool', 'typeof # == "symbol"', obj)) {
+ // Note: this is a JS Symbol, not a Dart one.
+ return JS('', '#', jsobject);
+ }
+
return null;
}
« 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