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

Unified Diff: sdk/lib/_internal/js_runtime/lib/js_rti.dart

Issue 2699073003: Support `void` as generic argument.
Patch Set: Shuffle things around to have a better `voidRti` locality. Created 3 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
Index: sdk/lib/_internal/js_runtime/lib/js_rti.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/js_rti.dart b/sdk/lib/_internal/js_runtime/lib/js_rti.dart
index 2e1c8d702e10323a682f5e01728c27a65a5eab79..161c47e89abf511690b2b615305b11eccbff7f22 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_rti.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_rti.dart
@@ -165,6 +165,9 @@ String runtimeTypeToString(var rti, {String onTypeVariable(int i)}) {
if (rti == null) {
return 'dynamic';
}
+ if (isVoidType(rti)) {
+ return "void";
+ }
if (isJsArray(rti)) {
// A list representing a type with arguments.
return getRuntimeTypeAsString(rti, onTypeVariable: onTypeVariable);
@@ -194,15 +197,10 @@ String runtimeTypeToString(var rti, {String onTypeVariable(int i)}) {
String _functionRtiToString(var rti, String onTypeVariable(int i)) {
String returnTypeText;
- String voidTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_VOID_RETURN_TAG);
- if (JS('bool', '!!#[#]', rti, voidTag)) {
- returnTypeText = 'void';
- } else {
- String returnTypeTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_RETURN_TYPE_TAG);
- var returnRti = JS('', '#[#]', rti, returnTypeTag);
- returnTypeText =
- runtimeTypeToString(returnRti, onTypeVariable: onTypeVariable);
- }
+ String returnTypeTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_RETURN_TYPE_TAG);
+ var returnRti = JS('', '#[#]', rti, returnTypeTag);
+ returnTypeText =
+ runtimeTypeToString(returnRti, onTypeVariable: onTypeVariable);
String argumentsText = '';
String sep = '';
@@ -462,7 +460,10 @@ computeSignature(var signature, var context, var contextName) {
*/
bool isSupertypeOfNull(var type) {
// `null` means `dynamic`.
- return type == null || isDartObjectTypeRti(type) || isNullTypeRti(type);
+ return type == null ||
+ isVoidType(type) ||
+ isDartObjectTypeRti(type) ||
+ isNullTypeRti(type);
}
/**
@@ -474,7 +475,7 @@ bool isSupertypeOfNull(var type) {
*/
bool checkSubtypeOfRuntimeType(o, t) {
if (o == null) return isSupertypeOfNull(t);
- if (t == null) return true;
+ if (t == null || isVoidType(t)) return true;
// Get the runtime type information from the object here, because we may
// overwrite o with the interceptor below.
var rti = getRuntimeTypeInfo(o);
@@ -539,6 +540,9 @@ bool isSubtype(var s, var t) {
// If either type is dynamic, [s] is a subtype of [t].
if (s == null || t == null) return true;
if (isNullType(s)) return true;
+ if (isVoidType(t)) return true;
+ if (isVoidType(s)) return isDartObjectTypeRti(t);
+
if (isDartFunctionType(t)) {
return isFunctionSubtype(s, t);
}
@@ -633,17 +637,13 @@ bool areAssignableMaps(var s, var t) {
bool isFunctionSubtype(var s, var t) {
assert(isDartFunctionType(t));
if (!isDartFunctionType(s)) return false;
- var voidReturnTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_VOID_RETURN_TAG);
+
var returnTypeTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_RETURN_TYPE_TAG);
- if (hasField(s, voidReturnTag)) {
- if (hasNoField(t, voidReturnTag) && hasField(t, returnTypeTag)) {
- return false;
- }
- } else if (hasNoField(t, voidReturnTag)) {
- var sReturnType = getField(s, returnTypeTag);
- var tReturnType = getField(t, returnTypeTag);
- if (!isAssignable(sReturnType, tReturnType)) return false;
- }
+ var sReturnType = getField(s, returnTypeTag);
+ var tReturnType = getField(t, returnTypeTag);
+ if (!isAssignable(sReturnType, tReturnType)) return false;
+ if (isVoidType(sReturnType) && !isVoidType(tReturnType)) return false;
+
var requiredParametersTag =
JS_GET_NAME(JsGetName.FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG);
var sParameterTypes = getField(s, requiredParametersTag);
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/js_mirrors.dart ('k') | sdk/lib/_internal/js_runtime/lib/shared/embedded_names.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698