| OLD | NEW |
| 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 runtime operations on objects used by the code | 5 /// This library defines runtime operations on objects used by the code |
| 6 /// generator. | 6 /// generator. |
| 7 part of dart._runtime; | 7 part of dart._runtime; |
| 8 | 8 |
| 9 class InvocationImpl extends Invocation { | 9 class InvocationImpl extends Invocation { |
| 10 final Symbol memberName; | 10 final Symbol memberName; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // TODO(leafp): Allow JS objects to go through? | 260 // TODO(leafp): Allow JS objects to go through? |
| 261 if ($typeArgs != null) { | 261 if ($typeArgs != null) { |
| 262 // TODO(jmesserly): is there a sensible way to handle these? | 262 // TODO(jmesserly): is there a sensible way to handle these? |
| 263 $throwStrongModeError('call to JS object `' + $obj + | 263 $throwStrongModeError('call to JS object `' + $obj + |
| 264 '` with type arguments <' + $typeArgs + '> is not supported.'); | 264 '` with type arguments <' + $typeArgs + '> is not supported.'); |
| 265 } | 265 } |
| 266 return $f.apply($obj, $args); | 266 return $f.apply($obj, $args); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Apply type arguments | 269 // Apply type arguments |
| 270 let formalCount = $ftype[$_typeFormalCount]; | 270 if ($ftype instanceof $GenericFunctionType) { |
| 271 if (formalCount != null) { | 271 let formalCount = $ftype.formalCount; |
| 272 |
| 272 if ($typeArgs == null) { | 273 if ($typeArgs == null) { |
| 274 // TODO(jmesserly): this should use instantiate to bounds logic. |
| 275 // See https://github.com/dart-lang/sdk/issues/27256 |
| 273 $typeArgs = Array(formalCount).fill($dynamic); | 276 $typeArgs = Array(formalCount).fill($dynamic); |
| 274 } else if ($typeArgs.length != formalCount) { | 277 } else if ($typeArgs.length != formalCount) { |
| 275 // TODO(jmesserly): is this the right error? | 278 // TODO(jmesserly): is this the right error? |
| 276 $throwStrongModeError( | 279 $throwStrongModeError( |
| 277 'incorrect number of arguments to generic function ' + | 280 'incorrect number of arguments to generic function ' + |
| 278 $typeName($ftype) + ', got <' + $typeArgs + '> expected ' + | 281 $typeName($ftype) + ', got <' + $typeArgs + '> expected ' + |
| 279 formalCount + '.'); | 282 formalCount + '.'); |
| 280 } | 283 } |
| 281 // Instantiate the function. | 284 // Instantiate the function type. |
| 282 $ftype = $ftype.apply(null, $typeArgs); | 285 $ftype = $ftype.instantiate($typeArgs); |
| 283 } else if ($typeArgs != null) { | 286 } else if ($typeArgs != null) { |
| 284 $throwStrongModeError( | 287 $throwStrongModeError( |
| 285 'got type arguments to non-generic function ' + $typeName($ftype) + | 288 'got type arguments to non-generic function ' + $typeName($ftype) + |
| 286 ', got <' + $typeArgs + '> expected none.'); | 289 ', got <' + $typeArgs + '> expected none.'); |
| 287 } | 290 } |
| 288 | 291 |
| 289 if ($_checkApply($ftype, $args)) { | 292 if ($_checkApply($ftype, $args)) { |
| 290 if ($typeArgs != null) { | 293 if ($typeArgs != null) { |
| 291 return $f.apply($obj, $typeArgs).apply($obj, $args); | 294 return $f.apply($obj, $typeArgs).apply($obj, $args); |
| 292 } | 295 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 // Ignore if we would ignore either side of union. | 422 // Ignore if we would ignore either side of union. |
| 420 let typeArg = $getGenericArgs(type)[0]; | 423 let typeArg = $getGenericArgs(type)[0]; |
| 421 let typeFuture = ${getGenericClass(Future)}(typeArg); | 424 let typeFuture = ${getGenericClass(Future)}(typeArg); |
| 422 return $_ignoreTypeFailure(actual, typeFuture) || | 425 return $_ignoreTypeFailure(actual, typeFuture) || |
| 423 $_ignoreTypeFailure(actual, typeArg); | 426 $_ignoreTypeFailure(actual, typeArg); |
| 424 } | 427 } |
| 425 | 428 |
| 426 if (!!$isSubtype(type, $Iterable) && !!$isSubtype(actual, $Iterable) || | 429 if (!!$isSubtype(type, $Iterable) && !!$isSubtype(actual, $Iterable) || |
| 427 !!$isSubtype(type, $Future) && !!$isSubtype(actual, $Future) || | 430 !!$isSubtype(type, $Future) && !!$isSubtype(actual, $Future) || |
| 428 !!$isSubtype(type, $Map) && !!$isSubtype(actual, $Map) || | 431 !!$isSubtype(type, $Map) && !!$isSubtype(actual, $Map) || |
| 429 $isFunctionType(type) && $isFunctionType(actual) || | 432 $_isFunctionType(type) && $_isFunctionType(actual) || |
| 430 !!$isSubtype(type, $Stream) && !!$isSubtype(actual, $Stream) || | 433 !!$isSubtype(type, $Stream) && !!$isSubtype(actual, $Stream) || |
| 431 !!$isSubtype(type, $StreamSubscription) && | 434 !!$isSubtype(type, $StreamSubscription) && |
| 432 !!$isSubtype(actual, $StreamSubscription)) { | 435 !!$isSubtype(actual, $StreamSubscription)) { |
| 433 console.warn('Ignoring cast fail from ' + $typeName(actual) + | 436 console.warn('Ignoring cast fail from ' + $typeName(actual) + |
| 434 ' to ' + $typeName(type)); | 437 ' to ' + $typeName(type)); |
| 435 return true; | 438 return true; |
| 436 } | 439 } |
| 437 return false; | 440 return false; |
| 438 }); | 441 }); |
| 439 })()'''); | 442 })()'''); |
| 440 | 443 |
| 441 /// Returns true if [obj] is an instance of [type] | 444 /// Returns true if [obj] is an instance of [type] |
| 442 /// Returns true if [obj] is a JS function and [type] is a function type | 445 /// Returns true if [obj] is a JS function and [type] is a function type |
| 443 /// Returns false if [obj] is not an instance of [type] in both spec | 446 /// Returns false if [obj] is not an instance of [type] in both spec |
| 444 /// and strong mode | 447 /// and strong mode |
| 445 /// Returns null if [obj] is not an instance of [type] in strong mode | 448 /// Returns null if [obj] is not an instance of [type] in strong mode |
| 446 /// but might be in spec mode | 449 /// but might be in spec mode |
| 447 bool strongInstanceOf(obj, type, ignoreFromWhiteList) => JS( | 450 bool strongInstanceOf(obj, type, ignoreFromWhiteList) => JS( |
| 448 '', | 451 '', |
| 449 '''(() => { | 452 '''(() => { |
| 450 let actual = $getReifiedType($obj); | 453 let actual = $getReifiedType($obj); |
| 451 let result = $isSubtype(actual, $type); | 454 let result = $isSubtype(actual, $type); |
| 452 if (result || (actual == $int && $isSubtype($double, $type))) return true; | 455 if (result || (actual == $int && $isSubtype($double, $type))) return true; |
| 453 if (actual == $jsobject && $isFunctionType(type) && | 456 if (actual == $jsobject && $_isFunctionType(type) && |
| 454 typeof(obj) === 'function') { | 457 typeof(obj) === 'function') { |
| 455 return true; | 458 return true; |
| 456 } | 459 } |
| 457 if (result === false) return false; | 460 if (result === false) return false; |
| 458 if (!$_ignoreWhitelistedErrors || ($ignoreFromWhiteList == void 0)) return res
ult; | 461 if (!$_ignoreWhitelistedErrors || ($ignoreFromWhiteList == void 0)) return res
ult; |
| 459 if ($_ignoreTypeFailure(actual, $type)) return true; | 462 if ($_ignoreTypeFailure(actual, $type)) return true; |
| 460 return result; | 463 return result; |
| 461 })()'''); | 464 })()'''); |
| 462 | 465 |
| 463 /// Returns true if [obj] is null or an instance of [type] | 466 /// Returns true if [obj] is null or an instance of [type] |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 name = '+' + name; | 936 name = '+' + name; |
| 934 } | 937 } |
| 935 return name; | 938 return name; |
| 936 } | 939 } |
| 937 | 940 |
| 938 /// Emulates the implicit "loadLibrary" function provided by a deferred library. | 941 /// Emulates the implicit "loadLibrary" function provided by a deferred library. |
| 939 /// | 942 /// |
| 940 /// Libraries are not actually deferred in DDC, so this just returns a future | 943 /// Libraries are not actually deferred in DDC, so this just returns a future |
| 941 /// that completes immediately. | 944 /// that completes immediately. |
| 942 Future loadLibrary() => new Future.value(); | 945 Future loadLibrary() => new Future.value(); |
| OLD | NEW |