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 834b3a00a720ebed564b81e1944489c81c6d80ea..3834c2f7b8a2a5d72bcee8cd5fb424a427dd28c3 100644 |
--- a/tool/input_sdk/private/ddc_runtime/rtti.dart |
+++ b/tool/input_sdk/private/ddc_runtime/rtti.dart |
@@ -6,12 +6,14 @@ |
/// runtime types. |
part of dart._runtime; |
-/// |
/// Runtime type information. This module defines the mapping from |
/// runtime objects to their runtime type information. See the types |
/// module for the definition of how type information is represented. |
/// |
-/// Runtime objects fall into four main categories: |
+/// There are two kinds of objects that represent "types" at runtime. A |
+/// "runtime type" contains all of the data needed to implement the runtime |
+/// type checking inserted by the compiler. These objects fall into four |
+/// categories: |
/// |
/// - Things represented by javascript primitives, such as |
/// null, numbers, booleans, strings, and symbols. For these |
@@ -36,10 +38,13 @@ part of dart._runtime; |
/// reliably recognize type objects and map directly to core.Type |
/// rather than attaching this property everywhere. |
/// |
-/// |
+/// The other kind of object representing a "type" is the instances of the |
+/// dart:core Type class. These are the user visible objects you get by calling |
+/// "runtimeType" on an object or using a class literal expression. These are |
+/// different from the above objects, and are created by calling `wrapType()` |
+/// on a runtime type. |
-/// |
-///Tag a closure with a type, using one of three forms: |
+/// Tags a closure with a type, using one of three forms: |
/// dart.fn(cls) marks cls has having no optional or named |
/// parameters, with all argument and return types as dynamic |
/// dart.fn(cls, func) marks cls with the lazily computed |
@@ -93,15 +98,12 @@ checkPrimitiveType(obj) => JS('', '''(() => { |
})()'''); |
runtimeType(obj) => JS('', '''(() => { |
- // Lookup primitive (int/double/string) |
+ // Handle primitives where the method isn't on the object. |
let result = $checkPrimitiveType($obj); |
- if (result !== null) return result; |
+ if (result !== null) return $wrapType(result); |
- // Lookup recorded type |
- result = $obj.runtimeType; |
- if (result) return result; |
- |
- return $_nonPrimitiveRuntimeType(obj); |
+ // Delegate to the actual method on the object. |
Jennifer Messerly
2016/05/02 23:04:20
it might be worth a comment/TODO here, this issue
|
+ return $obj.runtimeType; |
})()'''); |
getFunctionType(obj) => JS('', '''(() => { |
@@ -110,13 +112,17 @@ getFunctionType(obj) => JS('', '''(() => { |
return $definiteFunctionType($bottom, args); |
})()'''); |
+/// The base implementation of Object.runtimeType. |
+objectRuntimeType(obj) => JS('', '''(() => { |
Jennifer Messerly
2016/05/02 23:04:20
Hey so I've been trying to clean these up. You can
Bob Nystrom
2016/05/03 20:50:47
Done.
|
+ return $wrapType($getReifiedType($obj)); |
+})()'''); |
+ |
+/// Returns an the runtime representation of the type of obj. |
/// |
-/// Returns the runtime type of obj. This is the same as `obj.realRuntimeType` |
-/// but will not call an overridden getter. |
-/// |
-/// Currently this will return null for non-Dart objects. |
-/// |
-realRuntimeType(obj) => JS('', '''(() => { |
+/// The resulting object is used internally for runtime type checking. This is |
+/// different from the user-visible Type object returned by calling |
+/// `runtimeType` on some Dart object. |
+getReifiedType(obj) => JS('', '''(() => { |
Jennifer Messerly
2016/05/02 23:04:20
if you feel like it -- cleanup idea :)
getReified
Bob Nystrom
2016/05/03 20:50:47
Done.
|
// Lookup primitive type |
let result = $checkPrimitiveType($obj); |
if (result !== null) return result; |
@@ -145,6 +151,18 @@ _nonPrimitiveRuntimeType(obj) => JS('', '''(() => { |
return result; |
})()'''); |
+/// Given an internal runtime type object, wraps it in a `WrappedType` object |
+/// that implements the dart:core Type interface. |
+wrapType(type) => JS('', '''(() => { |
Jennifer Messerly
2016/05/02 23:04:20
nowadays we'd write this more like:
wrapType(type
Bob Nystrom
2016/05/03 20:50:47
Done.
|
+ // If we've already wrapped this type once, use the previous wrapper. This |
+ // way, multiple references to the same type return an identical Type. |
+ if ($type.hasOwnProperty($_typeObject)) { |
+ return $type[$_typeObject]; |
+ } |
+ |
+ return $type[$_typeObject] = new $WrappedType($type); |
+})()'''); |
+ |
read(value) => JS('', '#[#]', value, _runtimeType); |
/// Tag the runtime type of [value] to be type [t]. |