@@ -47,6 +47,7 @@ import {
4747
4848import {
4949 ElementKind ,
50+ OperatorKind ,
5051 FunctionPrototype ,
5152 Class ,
5253 Field ,
@@ -64,7 +65,7 @@ import {
6465} from "./resolver" ;
6566
6667import {
67- CommonFlags , CommonSymbols
68+ CommonFlags
6869} from "./common" ;
6970
7071/** Symbols of various compiler built-ins. */
@@ -76,6 +77,7 @@ export namespace BuiltinSymbols {
7677 export const isReference = "~lib/builtins/isReference" ;
7778 export const isString = "~lib/builtins/isString" ;
7879 export const isArray = "~lib/builtins/isArray" ;
80+ export const isArrayLike = "~lib/builtins/isArrayLike" ;
7981 export const isFunction = "~lib/builtins/isFunction" ;
8082 export const isNullable = "~lib/builtins/isNullable" ;
8183 export const isDefined = "~lib/builtins/isDefined" ;
@@ -350,6 +352,19 @@ export function compileCall(
350352 : 0
351353 ) ;
352354 }
355+ case BuiltinSymbols . isArrayLike : { // isArrayLike<T!>() / isArrayLike<T?>(value: T) -> bool
356+ let type = evaluateConstantType ( compiler , typeArguments , operands , reportNode ) ;
357+ compiler . currentType = Type . bool ;
358+ if ( ! type ) return module . createUnreachable ( ) ;
359+ let classReference = type . classReference ;
360+ if ( ! classReference ) return module . createI32 ( 0 ) ;
361+ return module . createI32 (
362+ classReference . lookupInSelf ( "length" ) && (
363+ classReference . lookupOverload ( OperatorKind . INDEXED_GET ) ||
364+ classReference . lookupOverload ( OperatorKind . UNCHECKED_INDEXED_GET )
365+ ) ? 1 : 0
366+ ) ;
367+ }
353368 case BuiltinSymbols . isFunction : { // isFunction<T!> / isFunction<T?>(value: T) -> bool
354369 let type = evaluateConstantType ( compiler , typeArguments , operands , reportNode ) ;
355370 compiler . currentType = Type . bool ;
0 commit comments