v8 12.4.254 (node 22.4.1)
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 Primitive;
20class Numeric;
21class BigInt;
22class Int32;
23class Integer;
24class Number;
25class Object;
26class String;
27class Uint32;
28
32class V8_EXPORT Value : public Data {
33 public:
40 V8_INLINE bool IsUndefined() const;
41
48 V8_INLINE bool IsNull() const;
49
57 V8_INLINE bool IsNullOrUndefined() const;
58
66 V8_INLINE bool IsTrue() const;
67
75 V8_INLINE bool IsFalse() const;
76
83 bool IsName() const;
84
91 V8_INLINE bool IsString() const;
92
98 bool IsSymbol() const;
99
105 bool IsFunction() const;
106
111 bool IsArray() const;
112
116 bool IsObject() const;
117
123 bool IsBigInt() const;
124
130 bool IsBoolean() const;
131
137 bool IsNumber() const;
138
142 bool IsExternal() const;
143
147 bool IsInt32() const;
148
152 bool IsUint32() const;
153
157 bool IsDate() const;
158
162 bool IsArgumentsObject() const;
163
167 bool IsBigIntObject() const;
168
172 bool IsBooleanObject() const;
173
177 bool IsNumberObject() const;
178
182 bool IsStringObject() const;
183
187 bool IsSymbolObject() const;
188
192 bool IsNativeError() const;
193
197 bool IsRegExp() const;
198
202 bool IsAsyncFunction() const;
203
208
212 bool IsGeneratorObject() const;
213
217 bool IsPromise() const;
218
222 bool IsMap() const;
223
227 bool IsSet() const;
228
232 bool IsMapIterator() const;
233
237 bool IsSetIterator() const;
238
242 bool IsWeakMap() const;
243
247 bool IsWeakSet() const;
248
252 bool IsWeakRef() const;
253
257 bool IsArrayBuffer() const;
258
262 bool IsArrayBufferView() const;
263
267 bool IsTypedArray() const;
268
272 bool IsUint8Array() const;
273
278
282 bool IsInt8Array() const;
283
287 bool IsUint16Array() const;
288
292 bool IsInt16Array() const;
293
297 bool IsUint32Array() const;
298
302 bool IsInt32Array() const;
303
307 bool IsFloat16Array() const;
308
312 bool IsFloat32Array() const;
313
317 bool IsFloat64Array() const;
318
322 bool IsBigInt64Array() const;
323
327 bool IsBigUint64Array() const;
328
332 bool IsDataView() const;
333
338
342 bool IsProxy() const;
343
347 bool IsWasmMemoryObject() const;
348
352 bool IsWasmModuleObject() const;
353
357 bool IsWasmNull() const;
358
363
369 Local<Context> context) const;
375 Local<Context> context) const;
380 Local<Context> context) const;
385 Local<Context> context) const;
390 Local<Context> context) const;
397 Local<Context> context) const;
402 Local<Context> context) const;
409 Local<Context> context) const;
416 Local<Context> context) const;
423
428
434 Local<Context> context) const;
435
437 bool BooleanValue(Isolate* isolate) const;
438
443 Local<Context> context) const;
446 Local<Context> context) const;
449
452 Local<Value> that) const;
453 bool StrictEquals(Local<Value> that) const;
454 bool SameValue(Local<Value> that) const;
455
456 template <class T>
457 V8_INLINE static Value* Cast(T* value) {
458 return static_cast<Value*>(value);
459 }
460
462
464
465 private:
466 V8_INLINE bool QuickIsUndefined() const;
467 V8_INLINE bool QuickIsNull() const;
468 V8_INLINE bool QuickIsNullOrUndefined() const;
469#if V8_STATIC_ROOTS_BOOL
470 V8_INLINE bool QuickIsTrue() const;
471 V8_INLINE bool QuickIsFalse() const;
472#endif // V8_STATIC_ROOTS_BOOL
473 V8_INLINE bool QuickIsString() const;
474 bool FullIsUndefined() const;
475 bool FullIsNull() const;
476 bool FullIsTrue() const;
477 bool FullIsFalse() const;
478 bool FullIsString() const;
479
480 static void CheckCast(Data* that);
481};
482
498 public:
499 explicit TypecheckWitness(Isolate* isolate);
500
507 V8_INLINE bool Matches(Local<Value> candidate) const;
508
512 void Update(Local<Value> baseline);
513
514 private:
515 Local<Data> cached_map_;
516};
517
518template <>
520#ifdef V8_ENABLE_CHECKS
521 CheckCast(value);
522#endif
523 return static_cast<Value*>(value);
524}
525
526bool Value::IsUndefined() const {
527#ifdef V8_ENABLE_CHECKS
528 return FullIsUndefined();
529#else
530 return QuickIsUndefined();
531#endif
532}
533
534bool Value::QuickIsUndefined() const {
535 using A = internal::Address;
536 using I = internal::Internals;
538#if V8_STATIC_ROOTS_BOOL
539 return I::is_identical(obj, I::StaticReadOnlyRoot::kUndefinedValue);
540#else
541 if (!I::HasHeapObjectTag(obj)) return false;
542 if (I::GetInstanceType(obj) != I::kOddballType) return false;
543 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
544#endif // V8_STATIC_ROOTS_BOOL
545}
546
547bool Value::IsNull() const {
548#ifdef V8_ENABLE_CHECKS
549 return FullIsNull();
550#else
551 return QuickIsNull();
552#endif
553}
554
555bool Value::QuickIsNull() const {
556 using A = internal::Address;
557 using I = internal::Internals;
559#if V8_STATIC_ROOTS_BOOL
560 return I::is_identical(obj, I::StaticReadOnlyRoot::kNullValue);
561#else
562 if (!I::HasHeapObjectTag(obj)) return false;
563 if (I::GetInstanceType(obj) != I::kOddballType) return false;
564 return (I::GetOddballKind(obj) == I::kNullOddballKind);
565#endif // V8_STATIC_ROOTS_BOOL
566}
567
569#ifdef V8_ENABLE_CHECKS
570 return FullIsNull() || FullIsUndefined();
571#else
572 return QuickIsNullOrUndefined();
573#endif
574}
575
576bool Value::QuickIsNullOrUndefined() const {
577#if V8_STATIC_ROOTS_BOOL
578 return QuickIsNull() || QuickIsUndefined();
579#else
580 using A = internal::Address;
581 using I = internal::Internals;
583 if (!I::HasHeapObjectTag(obj)) return false;
584 if (I::GetInstanceType(obj) != I::kOddballType) return false;
585 int kind = I::GetOddballKind(obj);
586 return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
587#endif // V8_STATIC_ROOTS_BOOL
588}
589
590bool Value::IsTrue() const {
591#if V8_STATIC_ROOTS_BOOL && !defined(V8_ENABLE_CHECKS)
592 return QuickIsTrue();
593#else
594 return FullIsTrue();
595#endif
596}
597
598#if V8_STATIC_ROOTS_BOOL
599bool Value::QuickIsTrue() const {
600 using A = internal::Address;
601 using I = internal::Internals;
603 return I::is_identical(obj, I::StaticReadOnlyRoot::kTrueValue);
604}
605#endif // V8_STATIC_ROOTS_BOOL
606
607bool Value::IsFalse() const {
608#if V8_STATIC_ROOTS_BOOL && !defined(V8_ENABLE_CHECKS)
609 return QuickIsFalse();
610#else
611 return FullIsFalse();
612#endif
613}
614
615#if V8_STATIC_ROOTS_BOOL
616bool Value::QuickIsFalse() const {
617 using A = internal::Address;
618 using I = internal::Internals;
620 return I::is_identical(obj, I::StaticReadOnlyRoot::kFalseValue);
621}
622#endif // V8_STATIC_ROOTS_BOOL
623
624bool Value::IsString() const {
625#ifdef V8_ENABLE_CHECKS
626 return FullIsString();
627#else
628 return QuickIsString();
629#endif
630}
631
632bool Value::QuickIsString() const {
633 using A = internal::Address;
634 using I = internal::Internals;
636 if (!I::HasHeapObjectTag(obj)) return false;
637#if V8_STATIC_ROOTS_BOOL && !V8_MAP_PACKING
638 return I::CheckInstanceMapRange(obj, I::StaticReadOnlyRoot::kFirstStringMap,
639 I::StaticReadOnlyRoot::kLastStringMap);
640#else
641 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
642#endif // V8_STATIC_ROOTS_BOOL
643}
644
648 internal::Address cached =
650 return obj_map == cached;
651}
652
653} // namespace v8
654
655#endif // INCLUDE_V8_VALUE_H_
V8_INLINE bool Matches(Local< Value > candidate) const
Definition v8-value.h:645
void Update(Local< Value > baseline)
TypecheckWitness(Isolate *isolate)
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:568
bool IsTypedArray() const
bool IsSymbolObject() const
V8_WARN_UNUSED_RESULT MaybeLocal< BigInt > ToBigInt(Local< Context > context) const
bool IsDataView() const
V8_INLINE bool IsTrue() const
Definition v8-value.h:590
bool IsMap() const
bool IsArrayBuffer() const
V8_INLINE bool IsFalse() const
Definition v8-value.h:607
bool IsWeakRef() const
bool IsWasmMemoryObject() const
bool IsSharedArrayBuffer() const
bool IsUint8Array() const
V8_WARN_UNUSED_RESULT MaybeLocal< Uint32 > ToUint32(Local< Context > context) const
V8_WARN_UNUSED_RESULT MaybeLocal< Numeric > ToNumeric(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:624
V8_WARN_UNUSED_RESULT MaybeLocal< Primitive > ToPrimitive(Local< Context > context) const
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:457
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:547
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:526
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
bool IsFloat16Array() 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 LoadMap(Address obj)
static V8_INLINE Address ValueAsAddress(const T *value)
uintptr_t Address
Definition v8-internal.h:31
#define V8_EXPORT
Definition v8config.h:753
#define V8_INLINE
Definition v8config.h:477
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:628