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 IsArrayBufferBase() const;
258
262 bool IsArrayBuffer() const;
263
267 bool IsArrayBufferView() const;
268
272 bool IsTypedArray() const;
273
277 bool IsUint8Array() const;
278
283
287 bool IsInt8Array() const;
288
292 bool IsUint16Array() const;
293
297 bool IsInt16Array() const;
298
302 bool IsUint32Array() const;
303
307 bool IsInt32Array() const;
308
312 bool IsFloat16Array() const;
313
317 bool IsFloat32Array() const;
318
322 bool IsFloat64Array() const;
323
327 bool IsBigInt64Array() const;
328
332 bool IsBigUint64Array() const;
333
337 bool IsDataView() const;
338
343
347 bool IsProxy() const;
348
352 bool IsWasmMemoryObject() const;
353
358
362 bool IsWasmModuleObject() const;
363
367 bool IsWasmNull() const;
368
373
380
384 bool IsPrimitive() const;
385
391 Local<Context> context) const;
397 Local<Context> context) const;
402 Local<Context> context) const;
407 Local<Context> context) const;
412 Local<Context> context) const;
419 Local<Context> context) const;
424 Local<Context> context) const;
431 Local<Context> context) const;
438 Local<Context> context) const;
445
450
456 Local<Context> context) const;
457
459 bool BooleanValue(Isolate* isolate) const;
460
465 Local<Context> context) const;
468 Local<Context> context) const;
471
474 Local<Value> that) const;
475 bool StrictEquals(Local<Value> that) const;
476 bool SameValue(Local<Value> that) const;
477
478 template <class T>
479 V8_INLINE static Value* Cast(T* value) {
480 return static_cast<Value*>(value);
481 }
482
484
486
493 uint32_t GetHash();
494
495 private:
496 V8_INLINE bool QuickIsUndefined() const;
497 V8_INLINE bool QuickIsNull() const;
498 V8_INLINE bool QuickIsNullOrUndefined() const;
499#if V8_STATIC_ROOTS_BOOL
500 V8_INLINE bool QuickIsTrue() const;
501 V8_INLINE bool QuickIsFalse() const;
502#endif // V8_STATIC_ROOTS_BOOL
503 V8_INLINE bool QuickIsString() const;
504 bool FullIsUndefined() const;
505 bool FullIsNull() const;
506 bool FullIsTrue() const;
507 bool FullIsFalse() const;
508 bool FullIsString() const;
509
510 static void CheckCast(Data* that);
511};
512
528 public:
529 explicit TypecheckWitness(Isolate* isolate);
530
537 V8_INLINE bool Matches(Local<Value> candidate) const;
538
542 void Update(Local<Value> baseline);
543
544 private:
545 Local<Data> cached_map_;
546};
547
548template <>
550#ifdef V8_ENABLE_CHECKS
551 CheckCast(value);
552#endif
553 return static_cast<Value*>(value);
554}
555
556bool Value::IsUndefined() const {
557#ifdef V8_ENABLE_CHECKS
558 return FullIsUndefined();
559#else
560 return QuickIsUndefined();
561#endif
562}
563
564bool Value::QuickIsUndefined() const {
565 using A = internal::Address;
566 using I = internal::Internals;
568#if V8_STATIC_ROOTS_BOOL
569 return I::is_identical(obj, I::StaticReadOnlyRoot::kUndefinedValue);
570#else
571 if (!I::HasHeapObjectTag(obj)) return false;
572 if (I::GetInstanceType(obj) != I::kOddballType) return false;
573 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
574#endif // V8_STATIC_ROOTS_BOOL
575}
576
577bool Value::IsNull() const {
578#ifdef V8_ENABLE_CHECKS
579 return FullIsNull();
580#else
581 return QuickIsNull();
582#endif
583}
584
585bool Value::QuickIsNull() const {
586 using A = internal::Address;
587 using I = internal::Internals;
589#if V8_STATIC_ROOTS_BOOL
590 return I::is_identical(obj, I::StaticReadOnlyRoot::kNullValue);
591#else
592 if (!I::HasHeapObjectTag(obj)) return false;
593 if (I::GetInstanceType(obj) != I::kOddballType) return false;
594 return (I::GetOddballKind(obj) == I::kNullOddballKind);
595#endif // V8_STATIC_ROOTS_BOOL
596}
597
599#ifdef V8_ENABLE_CHECKS
600 return FullIsNull() || FullIsUndefined();
601#else
602 return QuickIsNullOrUndefined();
603#endif
604}
605
606bool Value::QuickIsNullOrUndefined() const {
607#if V8_STATIC_ROOTS_BOOL
608 return QuickIsNull() || QuickIsUndefined();
609#else
610 using A = internal::Address;
611 using I = internal::Internals;
613 if (!I::HasHeapObjectTag(obj)) return false;
614 if (I::GetInstanceType(obj) != I::kOddballType) return false;
615 int kind = I::GetOddballKind(obj);
616 return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
617#endif // V8_STATIC_ROOTS_BOOL
618}
619
620bool Value::IsTrue() const {
621#if V8_STATIC_ROOTS_BOOL && !defined(V8_ENABLE_CHECKS)
622 return QuickIsTrue();
623#else
624 return FullIsTrue();
625#endif
626}
627
628#if V8_STATIC_ROOTS_BOOL
629bool Value::QuickIsTrue() const {
630 using A = internal::Address;
631 using I = internal::Internals;
633 return I::is_identical(obj, I::StaticReadOnlyRoot::kTrueValue);
634}
635#endif // V8_STATIC_ROOTS_BOOL
636
637bool Value::IsFalse() const {
638#if V8_STATIC_ROOTS_BOOL && !defined(V8_ENABLE_CHECKS)
639 return QuickIsFalse();
640#else
641 return FullIsFalse();
642#endif
643}
644
645#if V8_STATIC_ROOTS_BOOL
646bool Value::QuickIsFalse() const {
647 using A = internal::Address;
648 using I = internal::Internals;
650 return I::is_identical(obj, I::StaticReadOnlyRoot::kFalseValue);
651}
652#endif // V8_STATIC_ROOTS_BOOL
653
654bool Value::IsString() const {
655#ifdef V8_ENABLE_CHECKS
656 return FullIsString();
657#else
658 return QuickIsString();
659#endif
660}
661
662bool Value::QuickIsString() const {
663 using A = internal::Address;
664 using I = internal::Internals;
666 if (!I::HasHeapObjectTag(obj)) return false;
667#if V8_STATIC_ROOTS_BOOL && !V8_MAP_PACKING
668 return I::CheckInstanceMapRange(obj,
669 I::StaticReadOnlyRoot::kStringMapLowerBound,
670 I::StaticReadOnlyRoot::kStringMapUpperBound);
671#else
672 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
673#endif // V8_STATIC_ROOTS_BOOL
674}
675
679 internal::Address cached =
681 return obj_map == cached;
682}
683
684} // namespace v8
685
686#endif // INCLUDE_V8_VALUE_H_
Definition: v8-data.h:18
Definition: v8-isolate.h:298
Definition: v8-local-handle.h:359
Definition: v8-local-handle.h:730
Definition: v8-maybe.h:39
Definition: v8-value.h:527
void Update(Local< Value > baseline)
TypecheckWitness(Isolate *isolate)
bool Matches(Local< Value > candidate) const
Definition: v8-value.h:676
Definition: v8-value.h:32
MaybeLocal< String > ToDetailString(Local< Context > context) const
bool BooleanValue(Isolate *isolate) const
bool IsRegExp() const
bool IsTypedArray() const
Maybe< int32_t > Int32Value(Local< Context > context) const
bool IsSymbol() const
bool IsSet() const
bool IsBigInt() const
bool IsName() const
bool IsSymbolObject() const
bool IsSharedArrayBuffer() const
Local< String > TypeOf(Isolate *)
bool IsBigInt64Array() const
MaybeLocal< Int32 > ToInt32(Local< Context > context) const
Maybe< double > NumberValue(Local< Context > context) const
MaybeLocal< Numeric > ToNumeric(Local< Context > context) const
MaybeLocal< BigInt > ToBigInt(Local< Context > context) const
bool IsStringObject() const
bool IsBigIntObject() const
bool IsPrimitive() const
bool IsWeakMap() const
bool IsProxy() const
bool IsNullOrUndefined() const
Definition: v8-value.h:598
bool IsTrue() const
Definition: v8-value.h:620
bool IsArray() const
bool IsNumberObject() const
bool IsPromise() const
bool IsBooleanObject() const
bool IsUint32Array() const
Local< Boolean > ToBoolean(Isolate *isolate) const
bool IsWeakRef() const
bool IsArrayBuffer() const
bool IsUint8ClampedArray() const
bool IsWeakSet() const
bool IsString() const
Definition: v8-value.h:654
uint32_t GetHash()
bool IsNumber() const
bool IsObject() const
MaybeLocal< Uint32 > ToArrayIndex(Local< Context > context) const
bool IsMapIterator() const
bool IsNull() const
Definition: v8-value.h:577
bool IsBoolean() const
bool SameValue(Local< Value > that) const
bool IsNativeError() const
bool IsFloat64Array() const
bool IsFalse() const
Definition: v8-value.h:637
bool IsMap() const
Maybe< int64_t > IntegerValue(Local< Context > context) const
bool IsBigUint64Array() const
bool IsInt16Array() const
bool IsExternal() const
bool IsSetIterator() const
MaybeLocal< String > ToString(Local< Context > context) const
bool IsModuleNamespaceObject() const
bool IsDate() const
Maybe< uint32_t > Uint32Value(Local< Context > context) const
bool IsWasmMemoryObject() const
Maybe< bool > Equals(Local< Context > context, Local< Value > that) const
bool IsFloat32Array() const
bool IsArrayBufferView() const
bool IsWasmModuleObject() const
bool IsGeneratorFunction() const
bool IsWasmNull() const
bool IsFunction() const
bool StrictEquals(Local< Value > that) const
static Value * Cast(T *value)
Definition: v8-value.h:479
MaybeLocal< Uint32 > ToUint32(Local< Context > context) const
bool IsUndefined() const
Definition: v8-value.h:556
bool IsFloat16Array() const
bool IsInt32() const
MaybeLocal< Primitive > ToPrimitive(Local< Context > context) const
MaybeLocal< Number > ToNumber(Local< Context > context) const
bool IsDataView() const
bool IsInt8Array() const
Maybe< bool > InstanceOf(Local< Context > context, Local< Object > object)
bool IsArrayBufferBase() const
bool IsArgumentsObject() const
bool IsAsyncFunction() const
bool IsUint32() const
MaybeLocal< Integer > ToInteger(Local< Context > context) const
MaybeLocal< Object > ToObject(Local< Context > context) const
bool IsUint8Array() const
bool IsWasmMemoryMapDescriptor() const
bool IsDeferredModuleNamespaceObject() const
bool IsUint16Array() const
bool IsGeneratorObject() const
bool IsInt32Array() const
Definition: v8-internal.h:979
static Address LoadMap(Address obj)
Definition: v8-internal.h:1284
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1842
uintptr_t Address
Definition: v8-internal.h:38
Definition: libplatform.h:15
#define V8_EXPORT
Definition: v8config.h:874
#define V8_INLINE
Definition: v8config.h:518
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:688