11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciextern macro IsBigInt(HeapObject): bool; 61cb0ef41Sopenharmony_ciextern macro IsConstructor(HeapObject): bool; 71cb0ef41Sopenharmony_ciextern macro IsCustomElementsReceiverInstanceType(int32): bool; 81cb0ef41Sopenharmony_ciextern macro IsExtensibleMap(Map): bool; 91cb0ef41Sopenharmony_ciextern macro IsNumberNormalized(Number): bool; 101cb0ef41Sopenharmony_ciextern macro IsSafeInteger(Object): bool; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci@export 131cb0ef41Sopenharmony_cimacro IsAccessorInfo(o: HeapObject): bool { 141cb0ef41Sopenharmony_ci return Is<AccessorInfo>(o); 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci@export 181cb0ef41Sopenharmony_cimacro IsAccessorPair(o: HeapObject): bool { 191cb0ef41Sopenharmony_ci return Is<AccessorPair>(o); 201cb0ef41Sopenharmony_ci} 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci@export 231cb0ef41Sopenharmony_cimacro IsAllocationSite(o: HeapObject): bool { 241cb0ef41Sopenharmony_ci return Is<AllocationSite>(o); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci@export 281cb0ef41Sopenharmony_cimacro IsCell(o: HeapObject): bool { 291cb0ef41Sopenharmony_ci return Is<Cell>(o); 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci@export 331cb0ef41Sopenharmony_cimacro IsCode(o: HeapObject): bool { 341cb0ef41Sopenharmony_ci return Is<Code>(o); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci@export 381cb0ef41Sopenharmony_cimacro IsCodeDataContainer(o: HeapObject): bool { 391cb0ef41Sopenharmony_ci return Is<CodeDataContainer>(o); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci@export 431cb0ef41Sopenharmony_cimacro IsContext(o: HeapObject): bool { 441cb0ef41Sopenharmony_ci return Is<Context>(o); 451cb0ef41Sopenharmony_ci} 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci@export 481cb0ef41Sopenharmony_cimacro IsCoverageInfo(o: HeapObject): bool { 491cb0ef41Sopenharmony_ci return Is<CoverageInfo>(o); 501cb0ef41Sopenharmony_ci} 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci@export 531cb0ef41Sopenharmony_cimacro IsDebugInfo(o: HeapObject): bool { 541cb0ef41Sopenharmony_ci return Is<DebugInfo>(o); 551cb0ef41Sopenharmony_ci} 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci@export 581cb0ef41Sopenharmony_cimacro IsFixedDoubleArray(o: HeapObject): bool { 591cb0ef41Sopenharmony_ci return Is<FixedDoubleArray>(o); 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci@export 631cb0ef41Sopenharmony_cimacro IsFeedbackCell(o: HeapObject): bool { 641cb0ef41Sopenharmony_ci return Is<FeedbackCell>(o); 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci@export 681cb0ef41Sopenharmony_cimacro IsFeedbackVector(o: HeapObject): bool { 691cb0ef41Sopenharmony_ci return Is<FeedbackVector>(o); 701cb0ef41Sopenharmony_ci} 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci@export 731cb0ef41Sopenharmony_cimacro IsHeapNumber(o: HeapObject): bool { 741cb0ef41Sopenharmony_ci return Is<HeapNumber>(o); 751cb0ef41Sopenharmony_ci} 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci@export 781cb0ef41Sopenharmony_cimacro IsNativeContext(o: HeapObject): bool { 791cb0ef41Sopenharmony_ci return Is<NativeContext>(o); 801cb0ef41Sopenharmony_ci} 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci@export 831cb0ef41Sopenharmony_cimacro IsNumber(o: Object): bool { 841cb0ef41Sopenharmony_ci return Is<Number>(o); 851cb0ef41Sopenharmony_ci} 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci@export 881cb0ef41Sopenharmony_cimacro IsPrivateSymbol(o: HeapObject): bool { 891cb0ef41Sopenharmony_ci return Is<PrivateSymbol>(o); 901cb0ef41Sopenharmony_ci} 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci@export 931cb0ef41Sopenharmony_cimacro IsPromiseCapability(o: HeapObject): bool { 941cb0ef41Sopenharmony_ci return Is<PromiseCapability>(o); 951cb0ef41Sopenharmony_ci} 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci@export 981cb0ef41Sopenharmony_cimacro IsPromiseFulfillReactionJobTask(o: HeapObject): bool { 991cb0ef41Sopenharmony_ci return Is<PromiseFulfillReactionJobTask>(o); 1001cb0ef41Sopenharmony_ci} 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci@export 1031cb0ef41Sopenharmony_cimacro IsPromiseReaction(o: HeapObject): bool { 1041cb0ef41Sopenharmony_ci return Is<PromiseReaction>(o); 1051cb0ef41Sopenharmony_ci} 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ci@export 1081cb0ef41Sopenharmony_cimacro IsPromiseRejectReactionJobTask(o: HeapObject): bool { 1091cb0ef41Sopenharmony_ci return Is<PromiseRejectReactionJobTask>(o); 1101cb0ef41Sopenharmony_ci} 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci@export 1131cb0ef41Sopenharmony_cimacro IsSharedFunctionInfo(o: HeapObject): bool { 1141cb0ef41Sopenharmony_ci return Is<SharedFunctionInfo>(o); 1151cb0ef41Sopenharmony_ci} 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci@export 1181cb0ef41Sopenharmony_cimacro IsSymbol(o: HeapObject): bool { 1191cb0ef41Sopenharmony_ci return Is<Symbol>(o); 1201cb0ef41Sopenharmony_ci} 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ciextern macro TaggedToHeapObject(Object): HeapObject 1231cb0ef41Sopenharmony_ci labels CastError; 1241cb0ef41Sopenharmony_ciextern macro TaggedToSmi(Object): Smi 1251cb0ef41Sopenharmony_ci labels CastError; 1261cb0ef41Sopenharmony_ciextern macro TaggedToPositiveSmi(Object): PositiveSmi 1271cb0ef41Sopenharmony_ci labels CastError; 1281cb0ef41Sopenharmony_ciextern macro TaggedToDirectString(Object): DirectString 1291cb0ef41Sopenharmony_ci labels CastError; 1301cb0ef41Sopenharmony_ciextern macro HeapObjectToCallable(HeapObject): Callable 1311cb0ef41Sopenharmony_ci labels CastError; 1321cb0ef41Sopenharmony_ciextern macro HeapObjectToConstructor(HeapObject): Constructor 1331cb0ef41Sopenharmony_ci labels CastError; 1341cb0ef41Sopenharmony_ciextern macro HeapObjectToJSFunctionWithPrototypeSlot(HeapObject): 1351cb0ef41Sopenharmony_ci JSFunctionWithPrototypeSlot 1361cb0ef41Sopenharmony_ci labels CastError; 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_cimacro Cast<A : type extends WeakHeapObject>(o: A|Object): A labels CastError { 1391cb0ef41Sopenharmony_ci if (!IsWeakOrCleared(o)) goto CastError; 1401cb0ef41Sopenharmony_ci return %RawDownCast<A>(o); 1411cb0ef41Sopenharmony_ci} 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_cimacro Cast<A : type extends Object>(implicit context: Context)(o: MaybeObject): 1441cb0ef41Sopenharmony_ci A labels CastError { 1451cb0ef41Sopenharmony_ci typeswitch (o) { 1461cb0ef41Sopenharmony_ci case (WeakHeapObject): { 1471cb0ef41Sopenharmony_ci goto CastError; 1481cb0ef41Sopenharmony_ci } 1491cb0ef41Sopenharmony_ci case (o: Object): { 1501cb0ef41Sopenharmony_ci return Cast<A>(o) otherwise CastError; 1511cb0ef41Sopenharmony_ci } 1521cb0ef41Sopenharmony_ci } 1531cb0ef41Sopenharmony_ci} 1541cb0ef41Sopenharmony_ci 1551cb0ef41Sopenharmony_ciCast<Undefined>(o: MaybeObject): Undefined labels CastError { 1561cb0ef41Sopenharmony_ci if (TaggedNotEqual(o, Undefined)) goto CastError; 1571cb0ef41Sopenharmony_ci return %RawDownCast<Undefined>(o); 1581cb0ef41Sopenharmony_ci} 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_cimacro Cast<A : type extends Object>(implicit context: Context)(o: Object): A 1611cb0ef41Sopenharmony_ci labels CastError { 1621cb0ef41Sopenharmony_ci return Cast<A>(TaggedToHeapObject(o) otherwise CastError) 1631cb0ef41Sopenharmony_ci otherwise CastError; 1641cb0ef41Sopenharmony_ci} 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_ci// This is required for casting MaybeObject to Object. 1671cb0ef41Sopenharmony_ciCast<Smi>(o: Object): Smi 1681cb0ef41Sopenharmony_ci labels CastError { 1691cb0ef41Sopenharmony_ci return TaggedToSmi(o) otherwise CastError; 1701cb0ef41Sopenharmony_ci} 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ciCast<PositiveSmi>(o: Object): PositiveSmi 1731cb0ef41Sopenharmony_ci labels CastError { 1741cb0ef41Sopenharmony_ci return TaggedToPositiveSmi(o) otherwise CastError; 1751cb0ef41Sopenharmony_ci} 1761cb0ef41Sopenharmony_ci 1771cb0ef41Sopenharmony_ciCast<Zero>(o: Object): Zero labels CastError { 1781cb0ef41Sopenharmony_ci if (TaggedEqual(o, SmiConstant(0))) return %RawDownCast<Zero>(o); 1791cb0ef41Sopenharmony_ci goto CastError; 1801cb0ef41Sopenharmony_ci} 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ciCast<Number>(o: Object): Number 1831cb0ef41Sopenharmony_ci labels CastError { 1841cb0ef41Sopenharmony_ci typeswitch (o) { 1851cb0ef41Sopenharmony_ci case (s: Smi): { 1861cb0ef41Sopenharmony_ci return s; 1871cb0ef41Sopenharmony_ci } 1881cb0ef41Sopenharmony_ci case (n: HeapNumber): { 1891cb0ef41Sopenharmony_ci return n; 1901cb0ef41Sopenharmony_ci } 1911cb0ef41Sopenharmony_ci case (Object): { 1921cb0ef41Sopenharmony_ci goto CastError; 1931cb0ef41Sopenharmony_ci } 1941cb0ef41Sopenharmony_ci } 1951cb0ef41Sopenharmony_ci} 1961cb0ef41Sopenharmony_ci 1971cb0ef41Sopenharmony_ciCast<Undefined>(o: Object): Undefined 1981cb0ef41Sopenharmony_ci labels CastError { 1991cb0ef41Sopenharmony_ci const o: MaybeObject = o; 2001cb0ef41Sopenharmony_ci return Cast<Undefined>(o) otherwise CastError; 2011cb0ef41Sopenharmony_ci} 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_ciCast<Numeric>(o: Object): Numeric labels CastError { 2041cb0ef41Sopenharmony_ci typeswitch (o) { 2051cb0ef41Sopenharmony_ci case (o: Number): { 2061cb0ef41Sopenharmony_ci return o; 2071cb0ef41Sopenharmony_ci } 2081cb0ef41Sopenharmony_ci case (o: BigInt): { 2091cb0ef41Sopenharmony_ci return o; 2101cb0ef41Sopenharmony_ci } 2111cb0ef41Sopenharmony_ci case (HeapObject): { 2121cb0ef41Sopenharmony_ci goto CastError; 2131cb0ef41Sopenharmony_ci } 2141cb0ef41Sopenharmony_ci } 2151cb0ef41Sopenharmony_ci} 2161cb0ef41Sopenharmony_ci 2171cb0ef41Sopenharmony_ciCast<TheHole>(o: Object): TheHole labels CastError { 2181cb0ef41Sopenharmony_ci if (o == TheHole) return %RawDownCast<TheHole>(o); 2191cb0ef41Sopenharmony_ci goto CastError; 2201cb0ef41Sopenharmony_ci} 2211cb0ef41Sopenharmony_ci 2221cb0ef41Sopenharmony_ciCast<TheHole>(o: HeapObject): TheHole labels CastError { 2231cb0ef41Sopenharmony_ci const o: Object = o; 2241cb0ef41Sopenharmony_ci return Cast<TheHole>(o) otherwise CastError; 2251cb0ef41Sopenharmony_ci} 2261cb0ef41Sopenharmony_ci 2271cb0ef41Sopenharmony_ciCast<True>(o: Object): True labels CastError { 2281cb0ef41Sopenharmony_ci if (o == True) return %RawDownCast<True>(o); 2291cb0ef41Sopenharmony_ci goto CastError; 2301cb0ef41Sopenharmony_ci} 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_ciCast<True>(o: HeapObject): True labels CastError { 2331cb0ef41Sopenharmony_ci const o: Object = o; 2341cb0ef41Sopenharmony_ci return Cast<True>(o) otherwise CastError; 2351cb0ef41Sopenharmony_ci} 2361cb0ef41Sopenharmony_ci 2371cb0ef41Sopenharmony_ciCast<False>(o: Object): False labels CastError { 2381cb0ef41Sopenharmony_ci if (o == False) return %RawDownCast<False>(o); 2391cb0ef41Sopenharmony_ci goto CastError; 2401cb0ef41Sopenharmony_ci} 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_ciCast<False>(o: HeapObject): False labels CastError { 2431cb0ef41Sopenharmony_ci const o: Object = o; 2441cb0ef41Sopenharmony_ci return Cast<False>(o) otherwise CastError; 2451cb0ef41Sopenharmony_ci} 2461cb0ef41Sopenharmony_ci 2471cb0ef41Sopenharmony_ciCast<Boolean>(o: Object): Boolean labels CastError { 2481cb0ef41Sopenharmony_ci typeswitch (o) { 2491cb0ef41Sopenharmony_ci case (o: True): { 2501cb0ef41Sopenharmony_ci return o; 2511cb0ef41Sopenharmony_ci } 2521cb0ef41Sopenharmony_ci case (o: False): { 2531cb0ef41Sopenharmony_ci return o; 2541cb0ef41Sopenharmony_ci } 2551cb0ef41Sopenharmony_ci case (Object): { 2561cb0ef41Sopenharmony_ci goto CastError; 2571cb0ef41Sopenharmony_ci } 2581cb0ef41Sopenharmony_ci } 2591cb0ef41Sopenharmony_ci} 2601cb0ef41Sopenharmony_ci 2611cb0ef41Sopenharmony_ciCast<Boolean>(o: HeapObject): Boolean labels CastError { 2621cb0ef41Sopenharmony_ci const o: Object = o; 2631cb0ef41Sopenharmony_ci return Cast<Boolean>(o) otherwise CastError; 2641cb0ef41Sopenharmony_ci} 2651cb0ef41Sopenharmony_ci 2661cb0ef41Sopenharmony_ci// TODO(turbofan): These trivial casts for union types should be generated 2671cb0ef41Sopenharmony_ci// automatically. 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ciCast<JSPrimitive>(o: Object): JSPrimitive labels CastError { 2701cb0ef41Sopenharmony_ci typeswitch (o) { 2711cb0ef41Sopenharmony_ci case (o: Numeric): { 2721cb0ef41Sopenharmony_ci return o; 2731cb0ef41Sopenharmony_ci } 2741cb0ef41Sopenharmony_ci case (o: String): { 2751cb0ef41Sopenharmony_ci return o; 2761cb0ef41Sopenharmony_ci } 2771cb0ef41Sopenharmony_ci case (o: Symbol): { 2781cb0ef41Sopenharmony_ci return o; 2791cb0ef41Sopenharmony_ci } 2801cb0ef41Sopenharmony_ci case (o: Boolean): { 2811cb0ef41Sopenharmony_ci return o; 2821cb0ef41Sopenharmony_ci } 2831cb0ef41Sopenharmony_ci case (o: Undefined): { 2841cb0ef41Sopenharmony_ci return o; 2851cb0ef41Sopenharmony_ci } 2861cb0ef41Sopenharmony_ci case (o: Null): { 2871cb0ef41Sopenharmony_ci return o; 2881cb0ef41Sopenharmony_ci } 2891cb0ef41Sopenharmony_ci case (Object): { 2901cb0ef41Sopenharmony_ci goto CastError; 2911cb0ef41Sopenharmony_ci } 2921cb0ef41Sopenharmony_ci } 2931cb0ef41Sopenharmony_ci} 2941cb0ef41Sopenharmony_ci 2951cb0ef41Sopenharmony_ciCast<JSAny>(o: Object): JSAny labels CastError { 2961cb0ef41Sopenharmony_ci typeswitch (o) { 2971cb0ef41Sopenharmony_ci case (o: JSPrimitive): { 2981cb0ef41Sopenharmony_ci return o; 2991cb0ef41Sopenharmony_ci } 3001cb0ef41Sopenharmony_ci case (o: JSReceiver): { 3011cb0ef41Sopenharmony_ci return o; 3021cb0ef41Sopenharmony_ci } 3031cb0ef41Sopenharmony_ci case (Object): { 3041cb0ef41Sopenharmony_ci goto CastError; 3051cb0ef41Sopenharmony_ci } 3061cb0ef41Sopenharmony_ci } 3071cb0ef41Sopenharmony_ci} 3081cb0ef41Sopenharmony_ci 3091cb0ef41Sopenharmony_ciCast<JSAny|TheHole>(o: Object): JSAny|TheHole labels CastError { 3101cb0ef41Sopenharmony_ci typeswitch (o) { 3111cb0ef41Sopenharmony_ci case (o: JSAny): { 3121cb0ef41Sopenharmony_ci return o; 3131cb0ef41Sopenharmony_ci } 3141cb0ef41Sopenharmony_ci case (o: TheHole): { 3151cb0ef41Sopenharmony_ci return o; 3161cb0ef41Sopenharmony_ci } 3171cb0ef41Sopenharmony_ci case (Object): { 3181cb0ef41Sopenharmony_ci goto CastError; 3191cb0ef41Sopenharmony_ci } 3201cb0ef41Sopenharmony_ci } 3211cb0ef41Sopenharmony_ci} 3221cb0ef41Sopenharmony_ci 3231cb0ef41Sopenharmony_ciCast<Number|TheHole>(o: Object): Number|TheHole labels CastError { 3241cb0ef41Sopenharmony_ci typeswitch (o) { 3251cb0ef41Sopenharmony_ci case (o: Number): { 3261cb0ef41Sopenharmony_ci return o; 3271cb0ef41Sopenharmony_ci } 3281cb0ef41Sopenharmony_ci case (o: TheHole): { 3291cb0ef41Sopenharmony_ci return o; 3301cb0ef41Sopenharmony_ci } 3311cb0ef41Sopenharmony_ci case (Object): { 3321cb0ef41Sopenharmony_ci goto CastError; 3331cb0ef41Sopenharmony_ci } 3341cb0ef41Sopenharmony_ci } 3351cb0ef41Sopenharmony_ci} 3361cb0ef41Sopenharmony_ci 3371cb0ef41Sopenharmony_ciCast<Context|Zero|Undefined>(o: Object): Context|Zero|Undefined 3381cb0ef41Sopenharmony_ci labels CastError { 3391cb0ef41Sopenharmony_ci typeswitch (o) { 3401cb0ef41Sopenharmony_ci case (o: Context): { 3411cb0ef41Sopenharmony_ci return o; 3421cb0ef41Sopenharmony_ci } 3431cb0ef41Sopenharmony_ci case (o: Zero): { 3441cb0ef41Sopenharmony_ci return o; 3451cb0ef41Sopenharmony_ci } 3461cb0ef41Sopenharmony_ci case (o: Undefined): { 3471cb0ef41Sopenharmony_ci return o; 3481cb0ef41Sopenharmony_ci } 3491cb0ef41Sopenharmony_ci case (Object): { 3501cb0ef41Sopenharmony_ci goto CastError; 3511cb0ef41Sopenharmony_ci } 3521cb0ef41Sopenharmony_ci } 3531cb0ef41Sopenharmony_ci} 3541cb0ef41Sopenharmony_ci 3551cb0ef41Sopenharmony_cimacro Cast<A : type extends HeapObject>(o: HeapObject): A 3561cb0ef41Sopenharmony_ci labels CastError; 3571cb0ef41Sopenharmony_ci 3581cb0ef41Sopenharmony_ciCast<HeapObject>(o: HeapObject): HeapObject 3591cb0ef41Sopenharmony_cilabels _CastError { 3601cb0ef41Sopenharmony_ci return o; 3611cb0ef41Sopenharmony_ci} 3621cb0ef41Sopenharmony_ci 3631cb0ef41Sopenharmony_ciCast<Null>(o: HeapObject): Null 3641cb0ef41Sopenharmony_ci labels CastError { 3651cb0ef41Sopenharmony_ci if (o != Null) goto CastError; 3661cb0ef41Sopenharmony_ci return %RawDownCast<Null>(o); 3671cb0ef41Sopenharmony_ci} 3681cb0ef41Sopenharmony_ci 3691cb0ef41Sopenharmony_ciCast<Undefined>(o: HeapObject): Undefined 3701cb0ef41Sopenharmony_ci labels CastError { 3711cb0ef41Sopenharmony_ci const o: MaybeObject = o; 3721cb0ef41Sopenharmony_ci return Cast<Undefined>(o) otherwise CastError; 3731cb0ef41Sopenharmony_ci} 3741cb0ef41Sopenharmony_ci 3751cb0ef41Sopenharmony_ciCast<EmptyFixedArray>(o: Object): EmptyFixedArray 3761cb0ef41Sopenharmony_ci labels CastError { 3771cb0ef41Sopenharmony_ci if (o != kEmptyFixedArray) goto CastError; 3781cb0ef41Sopenharmony_ci return %RawDownCast<EmptyFixedArray>(o); 3791cb0ef41Sopenharmony_ci} 3801cb0ef41Sopenharmony_ciCast<EmptyFixedArray>(o: HeapObject): EmptyFixedArray 3811cb0ef41Sopenharmony_ci labels CastError { 3821cb0ef41Sopenharmony_ci const o: Object = o; 3831cb0ef41Sopenharmony_ci return Cast<EmptyFixedArray>(o) otherwise CastError; 3841cb0ef41Sopenharmony_ci} 3851cb0ef41Sopenharmony_ci 3861cb0ef41Sopenharmony_ciCast<(FixedDoubleArray | EmptyFixedArray)>(o: HeapObject): FixedDoubleArray| 3871cb0ef41Sopenharmony_ci EmptyFixedArray labels CastError { 3881cb0ef41Sopenharmony_ci typeswitch (o) { 3891cb0ef41Sopenharmony_ci case (o: EmptyFixedArray): { 3901cb0ef41Sopenharmony_ci return o; 3911cb0ef41Sopenharmony_ci } 3921cb0ef41Sopenharmony_ci case (o: FixedDoubleArray): { 3931cb0ef41Sopenharmony_ci return o; 3941cb0ef41Sopenharmony_ci } 3951cb0ef41Sopenharmony_ci case (HeapObject): { 3961cb0ef41Sopenharmony_ci goto CastError; 3971cb0ef41Sopenharmony_ci } 3981cb0ef41Sopenharmony_ci } 3991cb0ef41Sopenharmony_ci} 4001cb0ef41Sopenharmony_ci 4011cb0ef41Sopenharmony_ciCast<Callable>(o: HeapObject): Callable 4021cb0ef41Sopenharmony_ci labels CastError { 4031cb0ef41Sopenharmony_ci return HeapObjectToCallable(o) otherwise CastError; 4041cb0ef41Sopenharmony_ci} 4051cb0ef41Sopenharmony_ci 4061cb0ef41Sopenharmony_ciCast<Undefined|Callable>(o: HeapObject): Undefined|Callable 4071cb0ef41Sopenharmony_ci labels CastError { 4081cb0ef41Sopenharmony_ci if (o == Undefined) return Undefined; 4091cb0ef41Sopenharmony_ci return HeapObjectToCallable(o) otherwise CastError; 4101cb0ef41Sopenharmony_ci} 4111cb0ef41Sopenharmony_ci 4121cb0ef41Sopenharmony_ciCast<Undefined|JSFunction>(o: HeapObject): Undefined|JSFunction 4131cb0ef41Sopenharmony_ci labels CastError { 4141cb0ef41Sopenharmony_ci if (o == Undefined) return Undefined; 4151cb0ef41Sopenharmony_ci return Cast<JSFunction>(o) otherwise CastError; 4161cb0ef41Sopenharmony_ci} 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_cimacro Cast<T : type extends Symbol>(o: Symbol): T labels CastError; 4191cb0ef41Sopenharmony_ciCast<PublicSymbol>(s: Symbol): PublicSymbol labels CastError { 4201cb0ef41Sopenharmony_ci if (s.flags.is_private) goto CastError; 4211cb0ef41Sopenharmony_ci return %RawDownCast<PublicSymbol>(s); 4221cb0ef41Sopenharmony_ci} 4231cb0ef41Sopenharmony_ciCast<PrivateSymbol>(s: Symbol): PrivateSymbol labels CastError { 4241cb0ef41Sopenharmony_ci if (s.flags.is_private) return %RawDownCast<PrivateSymbol>(s); 4251cb0ef41Sopenharmony_ci goto CastError; 4261cb0ef41Sopenharmony_ci} 4271cb0ef41Sopenharmony_ciCast<PublicSymbol>(o: HeapObject): PublicSymbol labels CastError { 4281cb0ef41Sopenharmony_ci const s = Cast<Symbol>(o) otherwise CastError; 4291cb0ef41Sopenharmony_ci return Cast<PublicSymbol>(s) otherwise CastError; 4301cb0ef41Sopenharmony_ci} 4311cb0ef41Sopenharmony_ciCast<PrivateSymbol>(o: HeapObject): PrivateSymbol labels CastError { 4321cb0ef41Sopenharmony_ci const s = Cast<Symbol>(o) otherwise CastError; 4331cb0ef41Sopenharmony_ci return Cast<PrivateSymbol>(s) otherwise CastError; 4341cb0ef41Sopenharmony_ci} 4351cb0ef41Sopenharmony_ci 4361cb0ef41Sopenharmony_ciCast<DirectString>(o: String): DirectString 4371cb0ef41Sopenharmony_ci labels CastError { 4381cb0ef41Sopenharmony_ci return TaggedToDirectString(o) otherwise CastError; 4391cb0ef41Sopenharmony_ci} 4401cb0ef41Sopenharmony_ci 4411cb0ef41Sopenharmony_ciCast<Constructor>(o: HeapObject): Constructor 4421cb0ef41Sopenharmony_ci labels CastError { 4431cb0ef41Sopenharmony_ci return HeapObjectToConstructor(o) otherwise CastError; 4441cb0ef41Sopenharmony_ci} 4451cb0ef41Sopenharmony_ci 4461cb0ef41Sopenharmony_ciCast<JSFunctionWithPrototypeSlot>(o: HeapObject): JSFunctionWithPrototypeSlot 4471cb0ef41Sopenharmony_ci labels CastError { 4481cb0ef41Sopenharmony_ci return HeapObjectToJSFunctionWithPrototypeSlot(o) otherwise CastError; 4491cb0ef41Sopenharmony_ci} 4501cb0ef41Sopenharmony_ci 4511cb0ef41Sopenharmony_ciCast<BigInt>(o: HeapObject): BigInt labels CastError { 4521cb0ef41Sopenharmony_ci if (IsBigInt(o)) return %RawDownCast<BigInt>(o); 4531cb0ef41Sopenharmony_ci goto CastError; 4541cb0ef41Sopenharmony_ci} 4551cb0ef41Sopenharmony_ci 4561cb0ef41Sopenharmony_ciCast<JSRegExpResult>(implicit context: Context)(o: HeapObject): JSRegExpResult 4571cb0ef41Sopenharmony_ci labels CastError { 4581cb0ef41Sopenharmony_ci if (regexp::IsRegExpResult(o)) return %RawDownCast<JSRegExpResult>(o); 4591cb0ef41Sopenharmony_ci goto CastError; 4601cb0ef41Sopenharmony_ci} 4611cb0ef41Sopenharmony_ci 4621cb0ef41Sopenharmony_ciCast<JSSloppyArgumentsObject>(implicit context: Context)(o: HeapObject): 4631cb0ef41Sopenharmony_ci JSSloppyArgumentsObject 4641cb0ef41Sopenharmony_ci labels CastError { 4651cb0ef41Sopenharmony_ci const map: Map = o.map; 4661cb0ef41Sopenharmony_ci if (IsFastAliasedArgumentsMap(map) || IsSloppyArgumentsMap(map) || 4671cb0ef41Sopenharmony_ci IsSlowAliasedArgumentsMap(map)) { 4681cb0ef41Sopenharmony_ci return %RawDownCast<JSSloppyArgumentsObject>(o); 4691cb0ef41Sopenharmony_ci } 4701cb0ef41Sopenharmony_ci goto CastError; 4711cb0ef41Sopenharmony_ci} 4721cb0ef41Sopenharmony_ci 4731cb0ef41Sopenharmony_ciCast<JSStrictArgumentsObject>(implicit context: Context)(o: HeapObject): 4741cb0ef41Sopenharmony_ci JSStrictArgumentsObject 4751cb0ef41Sopenharmony_ci labels CastError { 4761cb0ef41Sopenharmony_ci const map: Map = o.map; 4771cb0ef41Sopenharmony_ci if (!IsStrictArgumentsMap(map)) goto CastError; 4781cb0ef41Sopenharmony_ci return %RawDownCast<JSStrictArgumentsObject>(o); 4791cb0ef41Sopenharmony_ci} 4801cb0ef41Sopenharmony_ci 4811cb0ef41Sopenharmony_ciCast<JSArgumentsObjectWithLength>(implicit context: Context)(o: HeapObject): 4821cb0ef41Sopenharmony_ci JSArgumentsObjectWithLength 4831cb0ef41Sopenharmony_ci labels CastError { 4841cb0ef41Sopenharmony_ci typeswitch (o) { 4851cb0ef41Sopenharmony_ci case (o: JSStrictArgumentsObject): { 4861cb0ef41Sopenharmony_ci return o; 4871cb0ef41Sopenharmony_ci } 4881cb0ef41Sopenharmony_ci case (o: JSSloppyArgumentsObject): { 4891cb0ef41Sopenharmony_ci return o; 4901cb0ef41Sopenharmony_ci } 4911cb0ef41Sopenharmony_ci case (HeapObject): { 4921cb0ef41Sopenharmony_ci goto CastError; 4931cb0ef41Sopenharmony_ci } 4941cb0ef41Sopenharmony_ci } 4951cb0ef41Sopenharmony_ci} 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ciCast<FastJSRegExp>(implicit context: Context)(o: HeapObject): FastJSRegExp 4981cb0ef41Sopenharmony_ci labels CastError { 4991cb0ef41Sopenharmony_ci // TODO(jgruber): Remove or redesign this. There is no single 'fast' regexp, 5001cb0ef41Sopenharmony_ci // the conditions to make a regexp object fast differ based on the callsite. 5011cb0ef41Sopenharmony_ci // For now, run the strict variant since replace (the only current callsite) 5021cb0ef41Sopenharmony_ci // accesses flag getters. 5031cb0ef41Sopenharmony_ci if (regexp::IsFastRegExpStrict(o)) { 5041cb0ef41Sopenharmony_ci return %RawDownCast<FastJSRegExp>(o); 5051cb0ef41Sopenharmony_ci } 5061cb0ef41Sopenharmony_ci goto CastError; 5071cb0ef41Sopenharmony_ci} 5081cb0ef41Sopenharmony_ci 5091cb0ef41Sopenharmony_ciCast<FastJSArray>(implicit context: Context)(o: HeapObject): FastJSArray 5101cb0ef41Sopenharmony_ci labels CastError { 5111cb0ef41Sopenharmony_ci if (IsForceSlowPath()) goto CastError; 5121cb0ef41Sopenharmony_ci 5131cb0ef41Sopenharmony_ci if (!Is<JSArray>(o)) goto CastError; 5141cb0ef41Sopenharmony_ci 5151cb0ef41Sopenharmony_ci // Bailout if receiver has slow elements. 5161cb0ef41Sopenharmony_ci const map: Map = o.map; 5171cb0ef41Sopenharmony_ci const elementsKind: ElementsKind = LoadMapElementsKind(map); 5181cb0ef41Sopenharmony_ci if (!IsFastElementsKind(elementsKind)) goto CastError; 5191cb0ef41Sopenharmony_ci 5201cb0ef41Sopenharmony_ci // Verify that our prototype is the initial array prototype. 5211cb0ef41Sopenharmony_ci if (!IsPrototypeInitialArrayPrototype(map)) goto CastError; 5221cb0ef41Sopenharmony_ci 5231cb0ef41Sopenharmony_ci if (IsNoElementsProtectorCellInvalid()) goto CastError; 5241cb0ef41Sopenharmony_ci return %RawDownCast<FastJSArray>(o); 5251cb0ef41Sopenharmony_ci} 5261cb0ef41Sopenharmony_ci 5271cb0ef41Sopenharmony_ciCast<FastJSArrayForRead>(implicit context: Context)(o: HeapObject): 5281cb0ef41Sopenharmony_ci FastJSArrayForRead 5291cb0ef41Sopenharmony_ci labels CastError { 5301cb0ef41Sopenharmony_ci if (!Is<JSArray>(o)) goto CastError; 5311cb0ef41Sopenharmony_ci 5321cb0ef41Sopenharmony_ci // Bailout if receiver has slow elements. 5331cb0ef41Sopenharmony_ci const map: Map = o.map; 5341cb0ef41Sopenharmony_ci const elementsKind: ElementsKind = LoadMapElementsKind(map); 5351cb0ef41Sopenharmony_ci if (!IsElementsKindLessThanOrEqual( 5361cb0ef41Sopenharmony_ci elementsKind, ElementsKind::LAST_ANY_NONEXTENSIBLE_ELEMENTS_KIND)) 5371cb0ef41Sopenharmony_ci goto CastError; 5381cb0ef41Sopenharmony_ci 5391cb0ef41Sopenharmony_ci // Verify that our prototype is the initial array prototype. 5401cb0ef41Sopenharmony_ci if (!IsPrototypeInitialArrayPrototype(map)) goto CastError; 5411cb0ef41Sopenharmony_ci 5421cb0ef41Sopenharmony_ci if (IsNoElementsProtectorCellInvalid()) goto CastError; 5431cb0ef41Sopenharmony_ci return %RawDownCast<FastJSArrayForRead>(o); 5441cb0ef41Sopenharmony_ci} 5451cb0ef41Sopenharmony_ci 5461cb0ef41Sopenharmony_ciCast<FastJSArrayForCopy>(implicit context: Context)(o: HeapObject): 5471cb0ef41Sopenharmony_ci FastJSArrayForCopy 5481cb0ef41Sopenharmony_ci labels CastError { 5491cb0ef41Sopenharmony_ci if (IsArraySpeciesProtectorCellInvalid()) goto CastError; 5501cb0ef41Sopenharmony_ci // TODO(victorgomes): Check if we can cast from FastJSArrayForRead instead. 5511cb0ef41Sopenharmony_ci const a = Cast<FastJSArray>(o) otherwise CastError; 5521cb0ef41Sopenharmony_ci return %RawDownCast<FastJSArrayForCopy>(a); 5531cb0ef41Sopenharmony_ci} 5541cb0ef41Sopenharmony_ci 5551cb0ef41Sopenharmony_ciCast<FastJSArrayForConcat>(implicit context: Context)(o: HeapObject): 5561cb0ef41Sopenharmony_ci FastJSArrayForConcat 5571cb0ef41Sopenharmony_ci labels CastError { 5581cb0ef41Sopenharmony_ci if (IsIsConcatSpreadableProtectorCellInvalid()) goto CastError; 5591cb0ef41Sopenharmony_ci const a = Cast<FastJSArrayForCopy>(o) otherwise CastError; 5601cb0ef41Sopenharmony_ci return %RawDownCast<FastJSArrayForConcat>(a); 5611cb0ef41Sopenharmony_ci} 5621cb0ef41Sopenharmony_ci 5631cb0ef41Sopenharmony_ciCast<FastJSArrayWithNoCustomIteration>(implicit context: Context)( 5641cb0ef41Sopenharmony_ci o: HeapObject): FastJSArrayWithNoCustomIteration 5651cb0ef41Sopenharmony_ci labels CastError { 5661cb0ef41Sopenharmony_ci if (IsArrayIteratorProtectorCellInvalid()) goto CastError; 5671cb0ef41Sopenharmony_ci const a = Cast<FastJSArray>(o) otherwise CastError; 5681cb0ef41Sopenharmony_ci return %RawDownCast<FastJSArrayWithNoCustomIteration>(a); 5691cb0ef41Sopenharmony_ci} 5701cb0ef41Sopenharmony_ci 5711cb0ef41Sopenharmony_ciCast<FastJSArrayForReadWithNoCustomIteration>(implicit context: Context)( 5721cb0ef41Sopenharmony_ci o: HeapObject): FastJSArrayForReadWithNoCustomIteration 5731cb0ef41Sopenharmony_ci labels CastError { 5741cb0ef41Sopenharmony_ci if (IsArrayIteratorProtectorCellInvalid()) goto CastError; 5751cb0ef41Sopenharmony_ci const a = Cast<FastJSArrayForRead>(o) otherwise CastError; 5761cb0ef41Sopenharmony_ci return %RawDownCast<FastJSArrayForReadWithNoCustomIteration>(a); 5771cb0ef41Sopenharmony_ci} 5781cb0ef41Sopenharmony_ci 5791cb0ef41Sopenharmony_cimacro Cast<T: type>(o: String): T labels CastError; 5801cb0ef41Sopenharmony_ci 5811cb0ef41Sopenharmony_ciCast<SeqOneByteString>(o: HeapObject): SeqOneByteString labels CastError { 5821cb0ef41Sopenharmony_ci return Cast<SeqOneByteString>(Cast<String>(o) otherwise CastError) 5831cb0ef41Sopenharmony_ci otherwise CastError; 5841cb0ef41Sopenharmony_ci} 5851cb0ef41Sopenharmony_ci 5861cb0ef41Sopenharmony_ciCast<SeqOneByteString>(o: String): SeqOneByteString labels CastError { 5871cb0ef41Sopenharmony_ci const instanceType = o.StringInstanceType(); 5881cb0ef41Sopenharmony_ci // Using & instead of && enables Turbofan to merge the two checks into one. 5891cb0ef41Sopenharmony_ci if (!(instanceType.representation == StringRepresentationTag::kSeqStringTag & 5901cb0ef41Sopenharmony_ci instanceType.is_one_byte)) { 5911cb0ef41Sopenharmony_ci goto CastError; 5921cb0ef41Sopenharmony_ci } 5931cb0ef41Sopenharmony_ci return %RawDownCast<SeqOneByteString>(o); 5941cb0ef41Sopenharmony_ci} 5951cb0ef41Sopenharmony_ci 5961cb0ef41Sopenharmony_ciCast<SeqTwoByteString>(o: HeapObject): SeqTwoByteString labels CastError { 5971cb0ef41Sopenharmony_ci return Cast<SeqTwoByteString>(Cast<String>(o) otherwise CastError) 5981cb0ef41Sopenharmony_ci otherwise CastError; 5991cb0ef41Sopenharmony_ci} 6001cb0ef41Sopenharmony_ci 6011cb0ef41Sopenharmony_ciCast<SeqTwoByteString>(o: String): SeqTwoByteString labels CastError { 6021cb0ef41Sopenharmony_ci const instanceType = o.StringInstanceType(); 6031cb0ef41Sopenharmony_ci // Using & instead of && enables Turbofan to merge the two checks into one. 6041cb0ef41Sopenharmony_ci if (!(instanceType.representation == StringRepresentationTag::kSeqStringTag & 6051cb0ef41Sopenharmony_ci !instanceType.is_one_byte)) { 6061cb0ef41Sopenharmony_ci goto CastError; 6071cb0ef41Sopenharmony_ci } 6081cb0ef41Sopenharmony_ci return %RawDownCast<SeqTwoByteString>(o); 6091cb0ef41Sopenharmony_ci} 6101cb0ef41Sopenharmony_ci 6111cb0ef41Sopenharmony_ciCast<ThinString>(o: HeapObject): ThinString labels CastError { 6121cb0ef41Sopenharmony_ci return Cast<ThinString>(Cast<String>(o) otherwise CastError) 6131cb0ef41Sopenharmony_ci otherwise CastError; 6141cb0ef41Sopenharmony_ci} 6151cb0ef41Sopenharmony_ci 6161cb0ef41Sopenharmony_ciCast<ThinString>(o: String): ThinString labels CastError { 6171cb0ef41Sopenharmony_ci const instanceType = o.StringInstanceType(); 6181cb0ef41Sopenharmony_ci if (instanceType.representation != StringRepresentationTag::kThinStringTag) { 6191cb0ef41Sopenharmony_ci goto CastError; 6201cb0ef41Sopenharmony_ci } 6211cb0ef41Sopenharmony_ci return %RawDownCast<ThinString>(o); 6221cb0ef41Sopenharmony_ci} 6231cb0ef41Sopenharmony_ci 6241cb0ef41Sopenharmony_ciCast<ConsString>(o: HeapObject): ConsString labels CastError { 6251cb0ef41Sopenharmony_ci return Cast<ConsString>(Cast<String>(o) otherwise CastError) 6261cb0ef41Sopenharmony_ci otherwise CastError; 6271cb0ef41Sopenharmony_ci} 6281cb0ef41Sopenharmony_ci 6291cb0ef41Sopenharmony_ciCast<ConsString>(o: String): ConsString labels CastError { 6301cb0ef41Sopenharmony_ci const instanceType = o.StringInstanceType(); 6311cb0ef41Sopenharmony_ci if (instanceType.representation != StringRepresentationTag::kConsStringTag) { 6321cb0ef41Sopenharmony_ci goto CastError; 6331cb0ef41Sopenharmony_ci } 6341cb0ef41Sopenharmony_ci return %RawDownCast<ConsString>(o); 6351cb0ef41Sopenharmony_ci} 6361cb0ef41Sopenharmony_ci 6371cb0ef41Sopenharmony_ciCast<SlicedString>(o: HeapObject): SlicedString labels CastError { 6381cb0ef41Sopenharmony_ci return Cast<SlicedString>(Cast<String>(o) otherwise CastError) 6391cb0ef41Sopenharmony_ci otherwise CastError; 6401cb0ef41Sopenharmony_ci} 6411cb0ef41Sopenharmony_ci 6421cb0ef41Sopenharmony_ciCast<SlicedString>(o: String): SlicedString labels CastError { 6431cb0ef41Sopenharmony_ci const instanceType = o.StringInstanceType(); 6441cb0ef41Sopenharmony_ci if (instanceType.representation != 6451cb0ef41Sopenharmony_ci StringRepresentationTag::kSlicedStringTag) { 6461cb0ef41Sopenharmony_ci goto CastError; 6471cb0ef41Sopenharmony_ci } 6481cb0ef41Sopenharmony_ci return %RawDownCast<SlicedString>(o); 6491cb0ef41Sopenharmony_ci} 6501cb0ef41Sopenharmony_ci 6511cb0ef41Sopenharmony_ciCast<ExternalOneByteString>(o: HeapObject): 6521cb0ef41Sopenharmony_ci ExternalOneByteString labels CastError { 6531cb0ef41Sopenharmony_ci return Cast<ExternalOneByteString>(Cast<String>(o) otherwise CastError) 6541cb0ef41Sopenharmony_ci otherwise CastError; 6551cb0ef41Sopenharmony_ci} 6561cb0ef41Sopenharmony_ci 6571cb0ef41Sopenharmony_ciCast<ExternalOneByteString>(o: String): ExternalOneByteString labels CastError { 6581cb0ef41Sopenharmony_ci const instanceType = o.StringInstanceType(); 6591cb0ef41Sopenharmony_ci // Using & instead of && enables Turbofan to merge the two checks into one. 6601cb0ef41Sopenharmony_ci if (!(instanceType.representation == 6611cb0ef41Sopenharmony_ci StringRepresentationTag::kExternalStringTag & 6621cb0ef41Sopenharmony_ci instanceType.is_one_byte)) { 6631cb0ef41Sopenharmony_ci goto CastError; 6641cb0ef41Sopenharmony_ci } 6651cb0ef41Sopenharmony_ci return %RawDownCast<ExternalOneByteString>(o); 6661cb0ef41Sopenharmony_ci} 6671cb0ef41Sopenharmony_ci 6681cb0ef41Sopenharmony_ciCast<ExternalTwoByteString>(o: HeapObject): 6691cb0ef41Sopenharmony_ci ExternalTwoByteString labels CastError { 6701cb0ef41Sopenharmony_ci return Cast<ExternalTwoByteString>(Cast<String>(o) otherwise CastError) 6711cb0ef41Sopenharmony_ci otherwise CastError; 6721cb0ef41Sopenharmony_ci} 6731cb0ef41Sopenharmony_ci 6741cb0ef41Sopenharmony_ciCast<ExternalTwoByteString>(o: String): ExternalTwoByteString labels CastError { 6751cb0ef41Sopenharmony_ci const instanceType = o.StringInstanceType(); 6761cb0ef41Sopenharmony_ci // Using & instead of && enables Turbofan to merge the two checks into one. 6771cb0ef41Sopenharmony_ci if (!(instanceType.representation == 6781cb0ef41Sopenharmony_ci StringRepresentationTag::kExternalStringTag & 6791cb0ef41Sopenharmony_ci !instanceType.is_one_byte)) { 6801cb0ef41Sopenharmony_ci goto CastError; 6811cb0ef41Sopenharmony_ci } 6821cb0ef41Sopenharmony_ci return %RawDownCast<ExternalTwoByteString>(o); 6831cb0ef41Sopenharmony_ci} 6841cb0ef41Sopenharmony_ci 6851cb0ef41Sopenharmony_ciCast<JSReceiver|Null>(o: HeapObject): JSReceiver|Null 6861cb0ef41Sopenharmony_ci labels CastError { 6871cb0ef41Sopenharmony_ci typeswitch (o) { 6881cb0ef41Sopenharmony_ci case (o: Null): { 6891cb0ef41Sopenharmony_ci return o; 6901cb0ef41Sopenharmony_ci } 6911cb0ef41Sopenharmony_ci case (o: JSReceiver): { 6921cb0ef41Sopenharmony_ci return o; 6931cb0ef41Sopenharmony_ci } 6941cb0ef41Sopenharmony_ci case (HeapObject): { 6951cb0ef41Sopenharmony_ci goto CastError; 6961cb0ef41Sopenharmony_ci } 6971cb0ef41Sopenharmony_ci } 6981cb0ef41Sopenharmony_ci} 6991cb0ef41Sopenharmony_ci 7001cb0ef41Sopenharmony_ciCast<JSReceiver|Symbol>(implicit context: Context)(o: Object): JSReceiver|Symbol 7011cb0ef41Sopenharmony_ci labels CastError { 7021cb0ef41Sopenharmony_ci typeswitch (o) { 7031cb0ef41Sopenharmony_ci case (o: JSReceiver): { 7041cb0ef41Sopenharmony_ci return o; 7051cb0ef41Sopenharmony_ci } 7061cb0ef41Sopenharmony_ci case (o: Symbol): { 7071cb0ef41Sopenharmony_ci return o; 7081cb0ef41Sopenharmony_ci } 7091cb0ef41Sopenharmony_ci case (Object): { 7101cb0ef41Sopenharmony_ci goto CastError; 7111cb0ef41Sopenharmony_ci } 7121cb0ef41Sopenharmony_ci } 7131cb0ef41Sopenharmony_ci} 7141cb0ef41Sopenharmony_ci 7151cb0ef41Sopenharmony_ciCast<Smi|PromiseReaction>(o: Object): Smi|PromiseReaction labels CastError { 7161cb0ef41Sopenharmony_ci typeswitch (o) { 7171cb0ef41Sopenharmony_ci case (o: Smi): { 7181cb0ef41Sopenharmony_ci return o; 7191cb0ef41Sopenharmony_ci } 7201cb0ef41Sopenharmony_ci case (o: PromiseReaction): { 7211cb0ef41Sopenharmony_ci return o; 7221cb0ef41Sopenharmony_ci } 7231cb0ef41Sopenharmony_ci case (Object): { 7241cb0ef41Sopenharmony_ci goto CastError; 7251cb0ef41Sopenharmony_ci } 7261cb0ef41Sopenharmony_ci } 7271cb0ef41Sopenharmony_ci} 7281cb0ef41Sopenharmony_ci 7291cb0ef41Sopenharmony_ciCast<String|Callable>(implicit context: Context)(o: Object): String| 7301cb0ef41Sopenharmony_ci Callable labels CastError { 7311cb0ef41Sopenharmony_ci typeswitch (o) { 7321cb0ef41Sopenharmony_ci case (o: String): { 7331cb0ef41Sopenharmony_ci return o; 7341cb0ef41Sopenharmony_ci } 7351cb0ef41Sopenharmony_ci case (o: Callable): { 7361cb0ef41Sopenharmony_ci return o; 7371cb0ef41Sopenharmony_ci } 7381cb0ef41Sopenharmony_ci case (Object): { 7391cb0ef41Sopenharmony_ci goto CastError; 7401cb0ef41Sopenharmony_ci } 7411cb0ef41Sopenharmony_ci } 7421cb0ef41Sopenharmony_ci} 7431cb0ef41Sopenharmony_ci 7441cb0ef41Sopenharmony_ciCast<Zero|PromiseReaction>(implicit context: Context)(o: Object): Zero| 7451cb0ef41Sopenharmony_ci PromiseReaction labels CastError { 7461cb0ef41Sopenharmony_ci typeswitch (o) { 7471cb0ef41Sopenharmony_ci case (o: Zero): { 7481cb0ef41Sopenharmony_ci return o; 7491cb0ef41Sopenharmony_ci } 7501cb0ef41Sopenharmony_ci case (o: PromiseReaction): { 7511cb0ef41Sopenharmony_ci return o; 7521cb0ef41Sopenharmony_ci } 7531cb0ef41Sopenharmony_ci case (Object): { 7541cb0ef41Sopenharmony_ci goto CastError; 7551cb0ef41Sopenharmony_ci } 7561cb0ef41Sopenharmony_ci } 7571cb0ef41Sopenharmony_ci} 7581cb0ef41Sopenharmony_ci 7591cb0ef41Sopenharmony_ciCast<JSFunction|JSBoundFunction|JSWrappedFunction>(implicit context: Context)( 7601cb0ef41Sopenharmony_ci o: Object): JSFunction|JSBoundFunction|JSWrappedFunction labels CastError { 7611cb0ef41Sopenharmony_ci typeswitch (o) { 7621cb0ef41Sopenharmony_ci case (o: JSFunction): { 7631cb0ef41Sopenharmony_ci return o; 7641cb0ef41Sopenharmony_ci } 7651cb0ef41Sopenharmony_ci case (o: JSBoundFunction): { 7661cb0ef41Sopenharmony_ci return o; 7671cb0ef41Sopenharmony_ci } 7681cb0ef41Sopenharmony_ci case (o: JSWrappedFunction): { 7691cb0ef41Sopenharmony_ci return o; 7701cb0ef41Sopenharmony_ci } 7711cb0ef41Sopenharmony_ci case (Object): { 7721cb0ef41Sopenharmony_ci goto CastError; 7731cb0ef41Sopenharmony_ci } 7741cb0ef41Sopenharmony_ci } 7751cb0ef41Sopenharmony_ci} 7761cb0ef41Sopenharmony_ci 7771cb0ef41Sopenharmony_ciCast<FixedArray|Undefined>(o: HeapObject): FixedArray| 7781cb0ef41Sopenharmony_ci Undefined labels CastError { 7791cb0ef41Sopenharmony_ci typeswitch (o) { 7801cb0ef41Sopenharmony_ci case (o: Undefined): { 7811cb0ef41Sopenharmony_ci return o; 7821cb0ef41Sopenharmony_ci } 7831cb0ef41Sopenharmony_ci case (o: FixedArray): { 7841cb0ef41Sopenharmony_ci return o; 7851cb0ef41Sopenharmony_ci } 7861cb0ef41Sopenharmony_ci case (Object): { 7871cb0ef41Sopenharmony_ci goto CastError; 7881cb0ef41Sopenharmony_ci } 7891cb0ef41Sopenharmony_ci } 7901cb0ef41Sopenharmony_ci} 7911cb0ef41Sopenharmony_ci 7921cb0ef41Sopenharmony_ciCast<JSProxy|Null>(o: HeapObject): JSProxy|Null labels CastError { 7931cb0ef41Sopenharmony_ci typeswitch (o) { 7941cb0ef41Sopenharmony_ci case (o: Null): { 7951cb0ef41Sopenharmony_ci return o; 7961cb0ef41Sopenharmony_ci } 7971cb0ef41Sopenharmony_ci case (o: JSProxy): { 7981cb0ef41Sopenharmony_ci return o; 7991cb0ef41Sopenharmony_ci } 8001cb0ef41Sopenharmony_ci case (Object): { 8011cb0ef41Sopenharmony_ci goto CastError; 8021cb0ef41Sopenharmony_ci } 8031cb0ef41Sopenharmony_ci } 8041cb0ef41Sopenharmony_ci} 8051cb0ef41Sopenharmony_ci 8061cb0ef41Sopenharmony_cimacro Is<A : type extends Object, B : type extends Object>( 8071cb0ef41Sopenharmony_ci implicit context: Context)(o: B): bool { 8081cb0ef41Sopenharmony_ci Cast<A>(o) otherwise return false; 8091cb0ef41Sopenharmony_ci return true; 8101cb0ef41Sopenharmony_ci} 8111cb0ef41Sopenharmony_ci 8121cb0ef41Sopenharmony_cimacro UnsafeCast<A : type extends Object>(implicit context: Context)(o: Object): 8131cb0ef41Sopenharmony_ci A { 8141cb0ef41Sopenharmony_ci dcheck(Is<A>(o)); 8151cb0ef41Sopenharmony_ci return %RawDownCast<A>(o); 8161cb0ef41Sopenharmony_ci} 8171cb0ef41Sopenharmony_ci 8181cb0ef41Sopenharmony_cimacro UnsafeConstCast<T: type>(r: const &T):&T { 8191cb0ef41Sopenharmony_ci return %RawDownCast<&T>(r); 8201cb0ef41Sopenharmony_ci} 8211cb0ef41Sopenharmony_ci 8221cb0ef41Sopenharmony_ciUnsafeCast<RegExpMatchInfo>(implicit context: Context)(o: Object): 8231cb0ef41Sopenharmony_ci RegExpMatchInfo { 8241cb0ef41Sopenharmony_ci dcheck(Is<FixedArray>(o)); 8251cb0ef41Sopenharmony_ci return %RawDownCast<RegExpMatchInfo>(o); 8261cb0ef41Sopenharmony_ci} 8271cb0ef41Sopenharmony_ci 8281cb0ef41Sopenharmony_cimacro UnsafeCast<A : type extends WeakHeapObject>(o: A|Object): A { 8291cb0ef41Sopenharmony_ci dcheck(IsWeakOrCleared(o)); 8301cb0ef41Sopenharmony_ci return %RawDownCast<A>(o); 8311cb0ef41Sopenharmony_ci} 8321cb0ef41Sopenharmony_ci 8331cb0ef41Sopenharmony_cimacro 8341cb0ef41Sopenharmony_ciCastOrDefault<T: type, Arg: type, Default: type>(implicit context: Context)( 8351cb0ef41Sopenharmony_ci x: Arg, default: Default): T|Default { 8361cb0ef41Sopenharmony_ci return Cast<T>(x) otherwise return default; 8371cb0ef41Sopenharmony_ci} 8381cb0ef41Sopenharmony_ci 8391cb0ef41Sopenharmony_ci// This is required for casting MaybeObject to Object. 8401cb0ef41Sopenharmony_ciCast<Object>(o: Object): Object 8411cb0ef41Sopenharmony_cilabels _CastError { 8421cb0ef41Sopenharmony_ci return o; 8431cb0ef41Sopenharmony_ci} 844