11cb0ef41Sopenharmony_ci// Copyright 2021 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_ci#ifndef INCLUDE_V8_VALUE_H_
61cb0ef41Sopenharmony_ci#define INCLUDE_V8_VALUE_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "v8-data.h"          // NOLINT(build/include_directory)
91cb0ef41Sopenharmony_ci#include "v8-internal.h"      // NOLINT(build/include_directory)
101cb0ef41Sopenharmony_ci#include "v8-local-handle.h"  // NOLINT(build/include_directory)
111cb0ef41Sopenharmony_ci#include "v8-maybe.h"         // NOLINT(build/include_directory)
121cb0ef41Sopenharmony_ci#include "v8config.h"         // NOLINT(build/include_directory)
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci/**
151cb0ef41Sopenharmony_ci * The v8 JavaScript engine.
161cb0ef41Sopenharmony_ci */
171cb0ef41Sopenharmony_cinamespace v8 {
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciclass BigInt;
201cb0ef41Sopenharmony_ciclass Int32;
211cb0ef41Sopenharmony_ciclass Integer;
221cb0ef41Sopenharmony_ciclass Number;
231cb0ef41Sopenharmony_ciclass Object;
241cb0ef41Sopenharmony_ciclass String;
251cb0ef41Sopenharmony_ciclass Uint32;
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci/**
281cb0ef41Sopenharmony_ci * The superclass of all JavaScript values and objects.
291cb0ef41Sopenharmony_ci */
301cb0ef41Sopenharmony_ciclass V8_EXPORT Value : public Data {
311cb0ef41Sopenharmony_ci public:
321cb0ef41Sopenharmony_ci  /**
331cb0ef41Sopenharmony_ci   * Returns true if this value is the undefined value.  See ECMA-262
341cb0ef41Sopenharmony_ci   * 4.3.10.
351cb0ef41Sopenharmony_ci   *
361cb0ef41Sopenharmony_ci   * This is equivalent to `value === undefined` in JS.
371cb0ef41Sopenharmony_ci   */
381cb0ef41Sopenharmony_ci  V8_INLINE bool IsUndefined() const;
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  /**
411cb0ef41Sopenharmony_ci   * Returns true if this value is the null value.  See ECMA-262
421cb0ef41Sopenharmony_ci   * 4.3.11.
431cb0ef41Sopenharmony_ci   *
441cb0ef41Sopenharmony_ci   * This is equivalent to `value === null` in JS.
451cb0ef41Sopenharmony_ci   */
461cb0ef41Sopenharmony_ci  V8_INLINE bool IsNull() const;
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  /**
491cb0ef41Sopenharmony_ci   * Returns true if this value is either the null or the undefined value.
501cb0ef41Sopenharmony_ci   * See ECMA-262
511cb0ef41Sopenharmony_ci   * 4.3.11. and 4.3.12
521cb0ef41Sopenharmony_ci   *
531cb0ef41Sopenharmony_ci   * This is equivalent to `value == null` in JS.
541cb0ef41Sopenharmony_ci   */
551cb0ef41Sopenharmony_ci  V8_INLINE bool IsNullOrUndefined() const;
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  /**
581cb0ef41Sopenharmony_ci   * Returns true if this value is true.
591cb0ef41Sopenharmony_ci   *
601cb0ef41Sopenharmony_ci   * This is not the same as `BooleanValue()`. The latter performs a
611cb0ef41Sopenharmony_ci   * conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas
621cb0ef41Sopenharmony_ci   * this checks `value === true`.
631cb0ef41Sopenharmony_ci   */
641cb0ef41Sopenharmony_ci  bool IsTrue() const;
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  /**
671cb0ef41Sopenharmony_ci   * Returns true if this value is false.
681cb0ef41Sopenharmony_ci   *
691cb0ef41Sopenharmony_ci   * This is not the same as `!BooleanValue()`. The latter performs a
701cb0ef41Sopenharmony_ci   * conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas
711cb0ef41Sopenharmony_ci   * this checks `value === false`.
721cb0ef41Sopenharmony_ci   */
731cb0ef41Sopenharmony_ci  bool IsFalse() const;
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci  /**
761cb0ef41Sopenharmony_ci   * Returns true if this value is a symbol or a string.
771cb0ef41Sopenharmony_ci   *
781cb0ef41Sopenharmony_ci   * This is equivalent to
791cb0ef41Sopenharmony_ci   * `typeof value === 'string' || typeof value === 'symbol'` in JS.
801cb0ef41Sopenharmony_ci   */
811cb0ef41Sopenharmony_ci  bool IsName() const;
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  /**
841cb0ef41Sopenharmony_ci   * Returns true if this value is an instance of the String type.
851cb0ef41Sopenharmony_ci   * See ECMA-262 8.4.
861cb0ef41Sopenharmony_ci   *
871cb0ef41Sopenharmony_ci   * This is equivalent to `typeof value === 'string'` in JS.
881cb0ef41Sopenharmony_ci   */
891cb0ef41Sopenharmony_ci  V8_INLINE bool IsString() const;
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  /**
921cb0ef41Sopenharmony_ci   * Returns true if this value is a symbol.
931cb0ef41Sopenharmony_ci   *
941cb0ef41Sopenharmony_ci   * This is equivalent to `typeof value === 'symbol'` in JS.
951cb0ef41Sopenharmony_ci   */
961cb0ef41Sopenharmony_ci  bool IsSymbol() const;
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci  /**
991cb0ef41Sopenharmony_ci   * Returns true if this value is a function.
1001cb0ef41Sopenharmony_ci   *
1011cb0ef41Sopenharmony_ci   * This is equivalent to `typeof value === 'function'` in JS.
1021cb0ef41Sopenharmony_ci   */
1031cb0ef41Sopenharmony_ci  bool IsFunction() const;
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci  /**
1061cb0ef41Sopenharmony_ci   * Returns true if this value is an array. Note that it will return false for
1071cb0ef41Sopenharmony_ci   * an Proxy for an array.
1081cb0ef41Sopenharmony_ci   */
1091cb0ef41Sopenharmony_ci  bool IsArray() const;
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ci  /**
1121cb0ef41Sopenharmony_ci   * Returns true if this value is an object.
1131cb0ef41Sopenharmony_ci   */
1141cb0ef41Sopenharmony_ci  bool IsObject() const;
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ci  /**
1171cb0ef41Sopenharmony_ci   * Returns true if this value is a bigint.
1181cb0ef41Sopenharmony_ci   *
1191cb0ef41Sopenharmony_ci   * This is equivalent to `typeof value === 'bigint'` in JS.
1201cb0ef41Sopenharmony_ci   */
1211cb0ef41Sopenharmony_ci  bool IsBigInt() const;
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci  /**
1241cb0ef41Sopenharmony_ci   * Returns true if this value is boolean.
1251cb0ef41Sopenharmony_ci   *
1261cb0ef41Sopenharmony_ci   * This is equivalent to `typeof value === 'boolean'` in JS.
1271cb0ef41Sopenharmony_ci   */
1281cb0ef41Sopenharmony_ci  bool IsBoolean() const;
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci  /**
1311cb0ef41Sopenharmony_ci   * Returns true if this value is a number.
1321cb0ef41Sopenharmony_ci   *
1331cb0ef41Sopenharmony_ci   * This is equivalent to `typeof value === 'number'` in JS.
1341cb0ef41Sopenharmony_ci   */
1351cb0ef41Sopenharmony_ci  bool IsNumber() const;
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci  /**
1381cb0ef41Sopenharmony_ci   * Returns true if this value is an `External` object.
1391cb0ef41Sopenharmony_ci   */
1401cb0ef41Sopenharmony_ci  bool IsExternal() const;
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci  /**
1431cb0ef41Sopenharmony_ci   * Returns true if this value is a 32-bit signed integer.
1441cb0ef41Sopenharmony_ci   */
1451cb0ef41Sopenharmony_ci  bool IsInt32() const;
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ci  /**
1481cb0ef41Sopenharmony_ci   * Returns true if this value is a 32-bit unsigned integer.
1491cb0ef41Sopenharmony_ci   */
1501cb0ef41Sopenharmony_ci  bool IsUint32() const;
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci  /**
1531cb0ef41Sopenharmony_ci   * Returns true if this value is a Date.
1541cb0ef41Sopenharmony_ci   */
1551cb0ef41Sopenharmony_ci  bool IsDate() const;
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci  /**
1581cb0ef41Sopenharmony_ci   * Returns true if this value is an Arguments object.
1591cb0ef41Sopenharmony_ci   */
1601cb0ef41Sopenharmony_ci  bool IsArgumentsObject() const;
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci  /**
1631cb0ef41Sopenharmony_ci   * Returns true if this value is a BigInt object.
1641cb0ef41Sopenharmony_ci   */
1651cb0ef41Sopenharmony_ci  bool IsBigIntObject() const;
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci  /**
1681cb0ef41Sopenharmony_ci   * Returns true if this value is a Boolean object.
1691cb0ef41Sopenharmony_ci   */
1701cb0ef41Sopenharmony_ci  bool IsBooleanObject() const;
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ci  /**
1731cb0ef41Sopenharmony_ci   * Returns true if this value is a Number object.
1741cb0ef41Sopenharmony_ci   */
1751cb0ef41Sopenharmony_ci  bool IsNumberObject() const;
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ci  /**
1781cb0ef41Sopenharmony_ci   * Returns true if this value is a String object.
1791cb0ef41Sopenharmony_ci   */
1801cb0ef41Sopenharmony_ci  bool IsStringObject() const;
1811cb0ef41Sopenharmony_ci
1821cb0ef41Sopenharmony_ci  /**
1831cb0ef41Sopenharmony_ci   * Returns true if this value is a Symbol object.
1841cb0ef41Sopenharmony_ci   */
1851cb0ef41Sopenharmony_ci  bool IsSymbolObject() const;
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci  /**
1881cb0ef41Sopenharmony_ci   * Returns true if this value is a NativeError.
1891cb0ef41Sopenharmony_ci   */
1901cb0ef41Sopenharmony_ci  bool IsNativeError() const;
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ci  /**
1931cb0ef41Sopenharmony_ci   * Returns true if this value is a RegExp.
1941cb0ef41Sopenharmony_ci   */
1951cb0ef41Sopenharmony_ci  bool IsRegExp() const;
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ci  /**
1981cb0ef41Sopenharmony_ci   * Returns true if this value is an async function.
1991cb0ef41Sopenharmony_ci   */
2001cb0ef41Sopenharmony_ci  bool IsAsyncFunction() const;
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ci  /**
2031cb0ef41Sopenharmony_ci   * Returns true if this value is a Generator function.
2041cb0ef41Sopenharmony_ci   */
2051cb0ef41Sopenharmony_ci  bool IsGeneratorFunction() const;
2061cb0ef41Sopenharmony_ci
2071cb0ef41Sopenharmony_ci  /**
2081cb0ef41Sopenharmony_ci   * Returns true if this value is a Generator object (iterator).
2091cb0ef41Sopenharmony_ci   */
2101cb0ef41Sopenharmony_ci  bool IsGeneratorObject() const;
2111cb0ef41Sopenharmony_ci
2121cb0ef41Sopenharmony_ci  /**
2131cb0ef41Sopenharmony_ci   * Returns true if this value is a Promise.
2141cb0ef41Sopenharmony_ci   */
2151cb0ef41Sopenharmony_ci  bool IsPromise() const;
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ci  /**
2181cb0ef41Sopenharmony_ci   * Returns true if this value is a Map.
2191cb0ef41Sopenharmony_ci   */
2201cb0ef41Sopenharmony_ci  bool IsMap() const;
2211cb0ef41Sopenharmony_ci
2221cb0ef41Sopenharmony_ci  /**
2231cb0ef41Sopenharmony_ci   * Returns true if this value is a Set.
2241cb0ef41Sopenharmony_ci   */
2251cb0ef41Sopenharmony_ci  bool IsSet() const;
2261cb0ef41Sopenharmony_ci
2271cb0ef41Sopenharmony_ci  /**
2281cb0ef41Sopenharmony_ci   * Returns true if this value is a Map Iterator.
2291cb0ef41Sopenharmony_ci   */
2301cb0ef41Sopenharmony_ci  bool IsMapIterator() const;
2311cb0ef41Sopenharmony_ci
2321cb0ef41Sopenharmony_ci  /**
2331cb0ef41Sopenharmony_ci   * Returns true if this value is a Set Iterator.
2341cb0ef41Sopenharmony_ci   */
2351cb0ef41Sopenharmony_ci  bool IsSetIterator() const;
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_ci  /**
2381cb0ef41Sopenharmony_ci   * Returns true if this value is a WeakMap.
2391cb0ef41Sopenharmony_ci   */
2401cb0ef41Sopenharmony_ci  bool IsWeakMap() const;
2411cb0ef41Sopenharmony_ci
2421cb0ef41Sopenharmony_ci  /**
2431cb0ef41Sopenharmony_ci   * Returns true if this value is a WeakSet.
2441cb0ef41Sopenharmony_ci   */
2451cb0ef41Sopenharmony_ci  bool IsWeakSet() const;
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_ci  /**
2481cb0ef41Sopenharmony_ci   * Returns true if this value is a WeakRef.
2491cb0ef41Sopenharmony_ci   */
2501cb0ef41Sopenharmony_ci  bool IsWeakRef() const;
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci  /**
2531cb0ef41Sopenharmony_ci   * Returns true if this value is an ArrayBuffer.
2541cb0ef41Sopenharmony_ci   */
2551cb0ef41Sopenharmony_ci  bool IsArrayBuffer() const;
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_ci  /**
2581cb0ef41Sopenharmony_ci   * Returns true if this value is an ArrayBufferView.
2591cb0ef41Sopenharmony_ci   */
2601cb0ef41Sopenharmony_ci  bool IsArrayBufferView() const;
2611cb0ef41Sopenharmony_ci
2621cb0ef41Sopenharmony_ci  /**
2631cb0ef41Sopenharmony_ci   * Returns true if this value is one of TypedArrays.
2641cb0ef41Sopenharmony_ci   */
2651cb0ef41Sopenharmony_ci  bool IsTypedArray() const;
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ci  /**
2681cb0ef41Sopenharmony_ci   * Returns true if this value is an Uint8Array.
2691cb0ef41Sopenharmony_ci   */
2701cb0ef41Sopenharmony_ci  bool IsUint8Array() const;
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci  /**
2731cb0ef41Sopenharmony_ci   * Returns true if this value is an Uint8ClampedArray.
2741cb0ef41Sopenharmony_ci   */
2751cb0ef41Sopenharmony_ci  bool IsUint8ClampedArray() const;
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ci  /**
2781cb0ef41Sopenharmony_ci   * Returns true if this value is an Int8Array.
2791cb0ef41Sopenharmony_ci   */
2801cb0ef41Sopenharmony_ci  bool IsInt8Array() const;
2811cb0ef41Sopenharmony_ci
2821cb0ef41Sopenharmony_ci  /**
2831cb0ef41Sopenharmony_ci   * Returns true if this value is an Uint16Array.
2841cb0ef41Sopenharmony_ci   */
2851cb0ef41Sopenharmony_ci  bool IsUint16Array() const;
2861cb0ef41Sopenharmony_ci
2871cb0ef41Sopenharmony_ci  /**
2881cb0ef41Sopenharmony_ci   * Returns true if this value is an Int16Array.
2891cb0ef41Sopenharmony_ci   */
2901cb0ef41Sopenharmony_ci  bool IsInt16Array() const;
2911cb0ef41Sopenharmony_ci
2921cb0ef41Sopenharmony_ci  /**
2931cb0ef41Sopenharmony_ci   * Returns true if this value is an Uint32Array.
2941cb0ef41Sopenharmony_ci   */
2951cb0ef41Sopenharmony_ci  bool IsUint32Array() const;
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_ci  /**
2981cb0ef41Sopenharmony_ci   * Returns true if this value is an Int32Array.
2991cb0ef41Sopenharmony_ci   */
3001cb0ef41Sopenharmony_ci  bool IsInt32Array() const;
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci  /**
3031cb0ef41Sopenharmony_ci   * Returns true if this value is a Float32Array.
3041cb0ef41Sopenharmony_ci   */
3051cb0ef41Sopenharmony_ci  bool IsFloat32Array() const;
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci  /**
3081cb0ef41Sopenharmony_ci   * Returns true if this value is a Float64Array.
3091cb0ef41Sopenharmony_ci   */
3101cb0ef41Sopenharmony_ci  bool IsFloat64Array() const;
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci  /**
3131cb0ef41Sopenharmony_ci   * Returns true if this value is a BigInt64Array.
3141cb0ef41Sopenharmony_ci   */
3151cb0ef41Sopenharmony_ci  bool IsBigInt64Array() const;
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci  /**
3181cb0ef41Sopenharmony_ci   * Returns true if this value is a BigUint64Array.
3191cb0ef41Sopenharmony_ci   */
3201cb0ef41Sopenharmony_ci  bool IsBigUint64Array() const;
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci  /**
3231cb0ef41Sopenharmony_ci   * Returns true if this value is a DataView.
3241cb0ef41Sopenharmony_ci   */
3251cb0ef41Sopenharmony_ci  bool IsDataView() const;
3261cb0ef41Sopenharmony_ci
3271cb0ef41Sopenharmony_ci  /**
3281cb0ef41Sopenharmony_ci   * Returns true if this value is a SharedArrayBuffer.
3291cb0ef41Sopenharmony_ci   */
3301cb0ef41Sopenharmony_ci  bool IsSharedArrayBuffer() const;
3311cb0ef41Sopenharmony_ci
3321cb0ef41Sopenharmony_ci  /**
3331cb0ef41Sopenharmony_ci   * Returns true if this value is a JavaScript Proxy.
3341cb0ef41Sopenharmony_ci   */
3351cb0ef41Sopenharmony_ci  bool IsProxy() const;
3361cb0ef41Sopenharmony_ci
3371cb0ef41Sopenharmony_ci  /**
3381cb0ef41Sopenharmony_ci   * Returns true if this value is a WasmMemoryObject.
3391cb0ef41Sopenharmony_ci   */
3401cb0ef41Sopenharmony_ci  bool IsWasmMemoryObject() const;
3411cb0ef41Sopenharmony_ci
3421cb0ef41Sopenharmony_ci  /**
3431cb0ef41Sopenharmony_ci   * Returns true if this value is a WasmModuleObject.
3441cb0ef41Sopenharmony_ci   */
3451cb0ef41Sopenharmony_ci  bool IsWasmModuleObject() const;
3461cb0ef41Sopenharmony_ci
3471cb0ef41Sopenharmony_ci  /**
3481cb0ef41Sopenharmony_ci   * Returns true if this value is the WasmNull object.
3491cb0ef41Sopenharmony_ci   */
3501cb0ef41Sopenharmony_ci  bool IsWasmNull() const;
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ci  /**
3531cb0ef41Sopenharmony_ci   * Returns true if the value is a Module Namespace Object.
3541cb0ef41Sopenharmony_ci   */
3551cb0ef41Sopenharmony_ci  bool IsModuleNamespaceObject() const;
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_ci  /**
3581cb0ef41Sopenharmony_ci   * Perform the equivalent of `BigInt(value)` in JS.
3591cb0ef41Sopenharmony_ci   */
3601cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
3611cb0ef41Sopenharmony_ci      Local<Context> context) const;
3621cb0ef41Sopenharmony_ci  /**
3631cb0ef41Sopenharmony_ci   * Perform the equivalent of `Number(value)` in JS.
3641cb0ef41Sopenharmony_ci   */
3651cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
3661cb0ef41Sopenharmony_ci      Local<Context> context) const;
3671cb0ef41Sopenharmony_ci  /**
3681cb0ef41Sopenharmony_ci   * Perform the equivalent of `String(value)` in JS.
3691cb0ef41Sopenharmony_ci   */
3701cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
3711cb0ef41Sopenharmony_ci      Local<Context> context) const;
3721cb0ef41Sopenharmony_ci  /**
3731cb0ef41Sopenharmony_ci   * Provide a string representation of this value usable for debugging.
3741cb0ef41Sopenharmony_ci   * This operation has no observable side effects and will succeed
3751cb0ef41Sopenharmony_ci   * unless e.g. execution is being terminated.
3761cb0ef41Sopenharmony_ci   */
3771cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
3781cb0ef41Sopenharmony_ci      Local<Context> context) const;
3791cb0ef41Sopenharmony_ci  /**
3801cb0ef41Sopenharmony_ci   * Perform the equivalent of `Object(value)` in JS.
3811cb0ef41Sopenharmony_ci   */
3821cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
3831cb0ef41Sopenharmony_ci      Local<Context> context) const;
3841cb0ef41Sopenharmony_ci  /**
3851cb0ef41Sopenharmony_ci   * Perform the equivalent of `Number(value)` in JS and convert the result
3861cb0ef41Sopenharmony_ci   * to an integer. Negative values are rounded up, positive values are rounded
3871cb0ef41Sopenharmony_ci   * down. NaN is converted to 0. Infinite values yield undefined results.
3881cb0ef41Sopenharmony_ci   */
3891cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
3901cb0ef41Sopenharmony_ci      Local<Context> context) const;
3911cb0ef41Sopenharmony_ci  /**
3921cb0ef41Sopenharmony_ci   * Perform the equivalent of `Number(value)` in JS and convert the result
3931cb0ef41Sopenharmony_ci   * to an unsigned 32-bit integer by performing the steps in
3941cb0ef41Sopenharmony_ci   * https://tc39.es/ecma262/#sec-touint32.
3951cb0ef41Sopenharmony_ci   */
3961cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
3971cb0ef41Sopenharmony_ci      Local<Context> context) const;
3981cb0ef41Sopenharmony_ci  /**
3991cb0ef41Sopenharmony_ci   * Perform the equivalent of `Number(value)` in JS and convert the result
4001cb0ef41Sopenharmony_ci   * to a signed 32-bit integer by performing the steps in
4011cb0ef41Sopenharmony_ci   * https://tc39.es/ecma262/#sec-toint32.
4021cb0ef41Sopenharmony_ci   */
4031cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci  /**
4061cb0ef41Sopenharmony_ci   * Perform the equivalent of `Boolean(value)` in JS. This can never fail.
4071cb0ef41Sopenharmony_ci   */
4081cb0ef41Sopenharmony_ci  Local<Boolean> ToBoolean(Isolate* isolate) const;
4091cb0ef41Sopenharmony_ci
4101cb0ef41Sopenharmony_ci  /**
4111cb0ef41Sopenharmony_ci   * Attempts to convert a string to an array index.
4121cb0ef41Sopenharmony_ci   * Returns an empty handle if the conversion fails.
4131cb0ef41Sopenharmony_ci   */
4141cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
4151cb0ef41Sopenharmony_ci      Local<Context> context) const;
4161cb0ef41Sopenharmony_ci
4171cb0ef41Sopenharmony_ci  /** Returns the equivalent of `ToBoolean()->Value()`. */
4181cb0ef41Sopenharmony_ci  bool BooleanValue(Isolate* isolate) const;
4191cb0ef41Sopenharmony_ci
4201cb0ef41Sopenharmony_ci  /** Returns the equivalent of `ToNumber()->Value()`. */
4211cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
4221cb0ef41Sopenharmony_ci  /** Returns the equivalent of `ToInteger()->Value()`. */
4231cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
4241cb0ef41Sopenharmony_ci      Local<Context> context) const;
4251cb0ef41Sopenharmony_ci  /** Returns the equivalent of `ToUint32()->Value()`. */
4261cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
4271cb0ef41Sopenharmony_ci      Local<Context> context) const;
4281cb0ef41Sopenharmony_ci  /** Returns the equivalent of `ToInt32()->Value()`. */
4291cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci  /** JS == */
4321cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
4331cb0ef41Sopenharmony_ci                                           Local<Value> that) const;
4341cb0ef41Sopenharmony_ci  bool StrictEquals(Local<Value> that) const;
4351cb0ef41Sopenharmony_ci  bool SameValue(Local<Value> that) const;
4361cb0ef41Sopenharmony_ci
4371cb0ef41Sopenharmony_ci  template <class T>
4381cb0ef41Sopenharmony_ci  V8_INLINE static Value* Cast(T* value) {
4391cb0ef41Sopenharmony_ci    return static_cast<Value*>(value);
4401cb0ef41Sopenharmony_ci  }
4411cb0ef41Sopenharmony_ci
4421cb0ef41Sopenharmony_ci  Local<String> TypeOf(Isolate*);
4431cb0ef41Sopenharmony_ci
4441cb0ef41Sopenharmony_ci  Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
4451cb0ef41Sopenharmony_ci
4461cb0ef41Sopenharmony_ci private:
4471cb0ef41Sopenharmony_ci  V8_INLINE bool QuickIsUndefined() const;
4481cb0ef41Sopenharmony_ci  V8_INLINE bool QuickIsNull() const;
4491cb0ef41Sopenharmony_ci  V8_INLINE bool QuickIsNullOrUndefined() const;
4501cb0ef41Sopenharmony_ci  V8_INLINE bool QuickIsString() const;
4511cb0ef41Sopenharmony_ci  bool FullIsUndefined() const;
4521cb0ef41Sopenharmony_ci  bool FullIsNull() const;
4531cb0ef41Sopenharmony_ci  bool FullIsString() const;
4541cb0ef41Sopenharmony_ci
4551cb0ef41Sopenharmony_ci  static void CheckCast(Data* that);
4561cb0ef41Sopenharmony_ci};
4571cb0ef41Sopenharmony_ci
4581cb0ef41Sopenharmony_citemplate <>
4591cb0ef41Sopenharmony_ciV8_INLINE Value* Value::Cast(Data* value) {
4601cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
4611cb0ef41Sopenharmony_ci  CheckCast(value);
4621cb0ef41Sopenharmony_ci#endif
4631cb0ef41Sopenharmony_ci  return static_cast<Value*>(value);
4641cb0ef41Sopenharmony_ci}
4651cb0ef41Sopenharmony_ci
4661cb0ef41Sopenharmony_cibool Value::IsUndefined() const {
4671cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
4681cb0ef41Sopenharmony_ci  return FullIsUndefined();
4691cb0ef41Sopenharmony_ci#else
4701cb0ef41Sopenharmony_ci  return QuickIsUndefined();
4711cb0ef41Sopenharmony_ci#endif
4721cb0ef41Sopenharmony_ci}
4731cb0ef41Sopenharmony_ci
4741cb0ef41Sopenharmony_cibool Value::QuickIsUndefined() const {
4751cb0ef41Sopenharmony_ci  using A = internal::Address;
4761cb0ef41Sopenharmony_ci  using I = internal::Internals;
4771cb0ef41Sopenharmony_ci  A obj = internal::ValueHelper::ValueAsAddress(this);
4781cb0ef41Sopenharmony_ci#if V8_STATIC_ROOTS_BOOL
4791cb0ef41Sopenharmony_ci  return I::is_identical(obj, I::StaticReadOnlyRoot::kUndefinedValue);
4801cb0ef41Sopenharmony_ci#else
4811cb0ef41Sopenharmony_ci  if (!I::HasHeapObjectTag(obj)) return false;
4821cb0ef41Sopenharmony_ci  if (I::GetInstanceType(obj) != I::kOddballType) return false;
4831cb0ef41Sopenharmony_ci  return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
4841cb0ef41Sopenharmony_ci#endif  // V8_STATIC_ROOTS_BOOL
4851cb0ef41Sopenharmony_ci}
4861cb0ef41Sopenharmony_ci
4871cb0ef41Sopenharmony_cibool Value::IsNull() const {
4881cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
4891cb0ef41Sopenharmony_ci  return FullIsNull();
4901cb0ef41Sopenharmony_ci#else
4911cb0ef41Sopenharmony_ci  return QuickIsNull();
4921cb0ef41Sopenharmony_ci#endif
4931cb0ef41Sopenharmony_ci}
4941cb0ef41Sopenharmony_ci
4951cb0ef41Sopenharmony_cibool Value::QuickIsNull() const {
4961cb0ef41Sopenharmony_ci  using A = internal::Address;
4971cb0ef41Sopenharmony_ci  using I = internal::Internals;
4981cb0ef41Sopenharmony_ci  A obj = internal::ValueHelper::ValueAsAddress(this);
4991cb0ef41Sopenharmony_ci#if V8_STATIC_ROOTS_BOOL
5001cb0ef41Sopenharmony_ci  return I::is_identical(obj, I::StaticReadOnlyRoot::kNullValue);
5011cb0ef41Sopenharmony_ci#else
5021cb0ef41Sopenharmony_ci  if (!I::HasHeapObjectTag(obj)) return false;
5031cb0ef41Sopenharmony_ci  if (I::GetInstanceType(obj) != I::kOddballType) return false;
5041cb0ef41Sopenharmony_ci  return (I::GetOddballKind(obj) == I::kNullOddballKind);
5051cb0ef41Sopenharmony_ci#endif  // V8_STATIC_ROOTS_BOOL
5061cb0ef41Sopenharmony_ci}
5071cb0ef41Sopenharmony_ci
5081cb0ef41Sopenharmony_cibool Value::IsNullOrUndefined() const {
5091cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
5101cb0ef41Sopenharmony_ci  return FullIsNull() || FullIsUndefined();
5111cb0ef41Sopenharmony_ci#else
5121cb0ef41Sopenharmony_ci  return QuickIsNullOrUndefined();
5131cb0ef41Sopenharmony_ci#endif
5141cb0ef41Sopenharmony_ci}
5151cb0ef41Sopenharmony_ci
5161cb0ef41Sopenharmony_cibool Value::QuickIsNullOrUndefined() const {
5171cb0ef41Sopenharmony_ci#if V8_STATIC_ROOTS_BOOL
5181cb0ef41Sopenharmony_ci  return QuickIsNull() || QuickIsUndefined();
5191cb0ef41Sopenharmony_ci#else
5201cb0ef41Sopenharmony_ci  using A = internal::Address;
5211cb0ef41Sopenharmony_ci  using I = internal::Internals;
5221cb0ef41Sopenharmony_ci  A obj = internal::ValueHelper::ValueAsAddress(this);
5231cb0ef41Sopenharmony_ci  if (!I::HasHeapObjectTag(obj)) return false;
5241cb0ef41Sopenharmony_ci  if (I::GetInstanceType(obj) != I::kOddballType) return false;
5251cb0ef41Sopenharmony_ci  int kind = I::GetOddballKind(obj);
5261cb0ef41Sopenharmony_ci  return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
5271cb0ef41Sopenharmony_ci#endif  // V8_STATIC_ROOTS_BOOL
5281cb0ef41Sopenharmony_ci}
5291cb0ef41Sopenharmony_ci
5301cb0ef41Sopenharmony_cibool Value::IsString() const {
5311cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_CHECKS
5321cb0ef41Sopenharmony_ci  return FullIsString();
5331cb0ef41Sopenharmony_ci#else
5341cb0ef41Sopenharmony_ci  return QuickIsString();
5351cb0ef41Sopenharmony_ci#endif
5361cb0ef41Sopenharmony_ci}
5371cb0ef41Sopenharmony_ci
5381cb0ef41Sopenharmony_cibool Value::QuickIsString() const {
5391cb0ef41Sopenharmony_ci  using A = internal::Address;
5401cb0ef41Sopenharmony_ci  using I = internal::Internals;
5411cb0ef41Sopenharmony_ci  A obj = internal::ValueHelper::ValueAsAddress(this);
5421cb0ef41Sopenharmony_ci  if (!I::HasHeapObjectTag(obj)) return false;
5431cb0ef41Sopenharmony_ci#if V8_STATIC_ROOTS_BOOL && !V8_MAP_PACKING
5441cb0ef41Sopenharmony_ci  return I::CheckInstanceMapRange(obj, I::StaticReadOnlyRoot::kFirstStringMap,
5451cb0ef41Sopenharmony_ci                                  I::StaticReadOnlyRoot::kLastStringMap);
5461cb0ef41Sopenharmony_ci#else
5471cb0ef41Sopenharmony_ci  return (I::GetInstanceType(obj) < I::kFirstNonstringType);
5481cb0ef41Sopenharmony_ci#endif  // V8_STATIC_ROOTS_BOOL
5491cb0ef41Sopenharmony_ci}
5501cb0ef41Sopenharmony_ci
5511cb0ef41Sopenharmony_ci}  // namespace v8
5521cb0ef41Sopenharmony_ci
5531cb0ef41Sopenharmony_ci#endif  // INCLUDE_V8_VALUE_H_
554