v8 11.3.244 (node 20.3.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-value.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_VALUE_H_
6#define INCLUDE_V8_VALUE_H_
7
8#include "v8-data.h" // NOLINT(build/include_directory)
9#include "v8-internal.h" // NOLINT(build/include_directory)
10#include "v8-local-handle.h" // NOLINT(build/include_directory)
11#include "v8-maybe.h" // NOLINT(build/include_directory)
12#include "v8config.h" // NOLINT(build/include_directory)
13
17namespace v8 {
18
19class BigInt;
20class Int32;
21class Integer;
22class Number;
23class Object;
24class String;
25class Uint32;
26
30class V8_EXPORT Value : public Data {
31 public:
38 V8_INLINE bool IsUndefined() const;
39
46 V8_INLINE bool IsNull() const;
47
55 V8_INLINE bool IsNullOrUndefined() const;
56
64 bool IsTrue() const;
65
73 bool IsFalse() const;
74
81 bool IsName() const;
82
89 V8_INLINE bool IsString() const;
90
96 bool IsSymbol() const;
97
103 bool IsFunction() const;
104
109 bool IsArray() const;
110
114 bool IsObject() const;
115
121 bool IsBigInt() const;
122
128 bool IsBoolean() const;
129
135 bool IsNumber() const;
136
140 bool IsExternal() const;
141
145 bool IsInt32() const;
146
150 bool IsUint32() const;
151
155 bool IsDate() const;
156
160 bool IsArgumentsObject() const;
161
165 bool IsBigIntObject() const;
166
170 bool IsBooleanObject() const;
171
175 bool IsNumberObject() const;
176
180 bool IsStringObject() const;
181
185 bool IsSymbolObject() const;
186
190 bool IsNativeError() const;
191
195 bool IsRegExp() const;
196
200 bool IsAsyncFunction() const;
201
206
210 bool IsGeneratorObject() const;
211
215 bool IsPromise() const;
216
220 bool IsMap() const;
221
225 bool IsSet() const;
226
230 bool IsMapIterator() const;
231
235 bool IsSetIterator() const;
236
240 bool IsWeakMap() const;
241
245 bool IsWeakSet() const;
246
250 bool IsWeakRef() const;
251
255 bool IsArrayBuffer() const;
256
260 bool IsArrayBufferView() const;
261
265 bool IsTypedArray() const;
266
270 bool IsUint8Array() const;
271
276
280 bool IsInt8Array() const;
281
285 bool IsUint16Array() const;
286
290 bool IsInt16Array() const;
291
295 bool IsUint32Array() const;
296
300 bool IsInt32Array() const;
301
305 bool IsFloat32Array() const;
306
310 bool IsFloat64Array() const;
311
315 bool IsBigInt64Array() const;
316
320 bool IsBigUint64Array() const;
321
325 bool IsDataView() const;
326
331
335 bool IsProxy() const;
336
340 bool IsWasmMemoryObject() const;
341
345 bool IsWasmModuleObject() const;
346
350 bool IsWasmNull() const;
351
356
361 Local<Context> context) const;
366 Local<Context> context) const;
371 Local<Context> context) const;
378 Local<Context> context) const;
383 Local<Context> context) const;
390 Local<Context> context) const;
397 Local<Context> context) const;
404
409
415 Local<Context> context) const;
416
418 bool BooleanValue(Isolate* isolate) const;
419
424 Local<Context> context) const;
427 Local<Context> context) const;
430
433 Local<Value> that) const;
434 bool StrictEquals(Local<Value> that) const;
435 bool SameValue(Local<Value> that) const;
436
437 template <class T>
438 V8_INLINE static Value* Cast(T* value) {
439 return static_cast<Value*>(value);
440 }
441
443
445
446 private:
447 V8_INLINE bool QuickIsUndefined() const;
448 V8_INLINE bool QuickIsNull() const;
449 V8_INLINE bool QuickIsNullOrUndefined() const;
450 V8_INLINE bool QuickIsString() const;
451 bool FullIsUndefined() const;
452 bool FullIsNull() const;
453 bool FullIsString() const;
454
455 static void CheckCast(Data* that);
456};
457
458template <>
460#ifdef V8_ENABLE_CHECKS
461 CheckCast(value);
462#endif
463 return static_cast<Value*>(value);
464}
465
466bool Value::IsUndefined() const {
467#ifdef V8_ENABLE_CHECKS
468 return FullIsUndefined();
469#else
470 return QuickIsUndefined();
471#endif
472}
473
474bool Value::QuickIsUndefined() const {
475 using A = internal::Address;
476 using I = internal::Internals;
478#if V8_STATIC_ROOTS_BOOL
479 return I::is_identical(obj, I::StaticReadOnlyRoot::kUndefinedValue);
480#else
481 if (!I::HasHeapObjectTag(obj)) return false;
482 if (I::GetInstanceType(obj) != I::kOddballType) return false;
483 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
484#endif // V8_STATIC_ROOTS_BOOL
485}
486
487bool Value::IsNull() const {
488#ifdef V8_ENABLE_CHECKS
489 return FullIsNull();
490#else
491 return QuickIsNull();
492#endif
493}
494
495bool Value::QuickIsNull() const {
496 using A = internal::Address;
497 using I = internal::Internals;
499#if V8_STATIC_ROOTS_BOOL
500 return I::is_identical(obj, I::StaticReadOnlyRoot::kNullValue);
501#else
502 if (!I::HasHeapObjectTag(obj)) return false;
503 if (I::GetInstanceType(obj) != I::kOddballType) return false;
504 return (I::GetOddballKind(obj) == I::kNullOddballKind);
505#endif // V8_STATIC_ROOTS_BOOL
506}
507
509#ifdef V8_ENABLE_CHECKS
510 return FullIsNull() || FullIsUndefined();
511#else
512 return QuickIsNullOrUndefined();
513#endif
514}
515
516bool Value::QuickIsNullOrUndefined() const {
517#if V8_STATIC_ROOTS_BOOL
518 return QuickIsNull() || QuickIsUndefined();
519#else
520 using A = internal::Address;
521 using I = internal::Internals;
523 if (!I::HasHeapObjectTag(obj)) return false;
524 if (I::GetInstanceType(obj) != I::kOddballType) return false;
525 int kind = I::GetOddballKind(obj);
526 return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
527#endif // V8_STATIC_ROOTS_BOOL
528}
529
530bool Value::IsString() const {
531#ifdef V8_ENABLE_CHECKS
532 return FullIsString();
533#else
534 return QuickIsString();
535#endif
536}
537
538bool Value::QuickIsString() const {
539 using A = internal::Address;
540 using I = internal::Internals;
542 if (!I::HasHeapObjectTag(obj)) return false;
543#if V8_STATIC_ROOTS_BOOL && !V8_MAP_PACKING
544 return I::CheckInstanceMapRange(obj, I::StaticReadOnlyRoot::kFirstStringMap,
545 I::StaticReadOnlyRoot::kLastStringMap);
546#else
547 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
548#endif // V8_STATIC_ROOTS_BOOL
549}
550
551} // namespace v8
552
553#endif // INCLUDE_V8_VALUE_H_
bool IsArgumentsObject() const
V8_WARN_UNUSED_RESULT MaybeLocal< Int32 > ToInt32(Local< Context > context) const
bool IsInt16Array() const
bool IsBigUint64Array() const
V8_WARN_UNUSED_RESULT Maybe< double > NumberValue(Local< Context > context) const
bool IsModuleNamespaceObject() const
bool IsSet() const
V8_INLINE bool IsNullOrUndefined() const
Definition v8-value.h:508
bool IsTypedArray() const
bool IsSymbolObject() const
V8_WARN_UNUSED_RESULT MaybeLocal< BigInt > ToBigInt(Local< Context > context) const
bool IsDataView() const
bool IsTrue() const
bool IsMap() const
bool IsArrayBuffer() const
bool IsFalse() const
bool IsWeakRef() const
bool IsWasmMemoryObject() const
bool IsSharedArrayBuffer() const
bool IsUint8Array() const
V8_WARN_UNUSED_RESULT MaybeLocal< Uint32 > ToUint32(Local< Context > context) const
bool IsInt32() const
bool IsWasmModuleObject() const
bool IsArrayBufferView() const
bool IsBooleanObject() const
bool IsInt8Array() const
bool IsInt32Array() const
bool IsUint32() const
bool IsBigIntObject() const
bool IsRegExp() const
bool IsNumber() const
Local< String > TypeOf(Isolate *)
bool IsObject() const
bool IsPromise() const
V8_WARN_UNUSED_RESULT MaybeLocal< String > ToDetailString(Local< Context > context) const
bool IsWeakMap() const
V8_INLINE bool IsString() const
Definition v8-value.h:530
V8_WARN_UNUSED_RESULT Maybe< bool > Equals(Local< Context > context, Local< Value > that) const
bool IsDate() const
static V8_INLINE Value * Cast(T *value)
Definition v8-value.h:438
bool IsNativeError() const
bool BooleanValue(Isolate *isolate) const
V8_WARN_UNUSED_RESULT MaybeLocal< Number > ToNumber(Local< Context > context) const
bool IsSetIterator() const
bool IsUint8ClampedArray() const
bool IsWasmNull() const
bool IsStringObject() const
bool IsGeneratorFunction() const
V8_WARN_UNUSED_RESULT MaybeLocal< Object > ToObject(Local< Context > context) const
bool IsUint32Array() const
bool IsNumberObject() const
V8_WARN_UNUSED_RESULT MaybeLocal< Integer > ToInteger(Local< Context > context) const
V8_WARN_UNUSED_RESULT Maybe< int64_t > IntegerValue(Local< Context > context) const
bool IsFloat32Array() const
bool IsBigInt() const
bool IsProxy() const
V8_INLINE bool IsNull() const
Definition v8-value.h:487
bool IsName() const
bool IsBigInt64Array() const
bool IsWeakSet() const
bool StrictEquals(Local< Value > that) const
bool IsBoolean() const
bool IsExternal() const
V8_WARN_UNUSED_RESULT Maybe< uint32_t > Uint32Value(Local< Context > context) const
V8_WARN_UNUSED_RESULT MaybeLocal< String > ToString(Local< Context > context) const
V8_INLINE bool IsUndefined() const
Definition v8-value.h:466
bool IsMapIterator() const
bool IsGeneratorObject() const
bool IsFunction() const
bool IsSymbol() const
Maybe< bool > InstanceOf(Local< Context > context, Local< Object > object)
bool IsArray() const
bool IsFloat64Array() const
bool SameValue(Local< Value > that) const
V8_WARN_UNUSED_RESULT MaybeLocal< Uint32 > ToArrayIndex(Local< Context > context) const
bool IsUint16Array() const
bool IsAsyncFunction() const
V8_WARN_UNUSED_RESULT Maybe< int32_t > Int32Value(Local< Context > context) const
Local< Boolean > ToBoolean(Isolate *isolate) const
static V8_INLINE Address ValueAsAddress(const T *value)
uintptr_t Address
Definition v8-internal.h:29
#define V8_EXPORT
Definition v8config.h:719
#define V8_INLINE
Definition v8config.h:460
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:609