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
353
357 bool IsWasmModuleObject() const;
358
362 bool IsWasmNull() const;
363
368
375
379 bool IsPrimitive() const;
380
386 Local<Context> context) const;
392 Local<Context> context) const;
397 Local<Context> context) const;
402 Local<Context> context) const;
407 Local<Context> context) const;
414 Local<Context> context) const;
419 Local<Context> context) const;
426 Local<Context> context) const;
433 Local<Context> context) const;
440
445
451 Local<Context> context) const;
452
454 bool BooleanValue(Isolate* isolate) const;
455
460 Local<Context> context) const;
463 Local<Context> context) const;
466
469 Local<Value> that) const;
470 bool StrictEquals(Local<Value> that) const;
471 bool SameValue(Local<Value> that) const;
472
473 template <class T>
474 V8_INLINE static Value* Cast(T* value) {
475 return static_cast<Value*>(value);
476 }
477
479
481
488 uint32_t GetHash();
489
490 private:
491 V8_INLINE bool QuickIsUndefined() const;
492 V8_INLINE bool QuickIsNull() const;
493 V8_INLINE bool QuickIsNullOrUndefined() const;
494#if V8_STATIC_ROOTS_BOOL
495 V8_INLINE bool QuickIsTrue() const;
496 V8_INLINE bool QuickIsFalse() const;
497#endif // V8_STATIC_ROOTS_BOOL
498 V8_INLINE bool QuickIsString() const;
499 bool FullIsUndefined() const;
500 bool FullIsNull() const;
501 bool FullIsTrue() const;
502 bool FullIsFalse() const;
503 bool FullIsString() const;
504
505 static void CheckCast(Data* that);
506};
507
523 public:
524 explicit TypecheckWitness(Isolate* isolate);
525
532 V8_INLINE bool Matches(Local<Value> candidate) const;
533
537 void Update(Local<Value> baseline);
538
539 private:
540 Local<Data> cached_map_;
541};
542
543template <>
545#ifdef V8_ENABLE_CHECKS
546 CheckCast(value);
547#endif
548 return static_cast<Value*>(value);
549}
550
551bool Value::IsUndefined() const {
552#ifdef V8_ENABLE_CHECKS
553 return FullIsUndefined();
554#else
555 return QuickIsUndefined();
556#endif
557}
558
559bool Value::QuickIsUndefined() const {
560 using A = internal::Address;
561 using I = internal::Internals;
563#if V8_STATIC_ROOTS_BOOL
564 return I::is_identical(obj, I::StaticReadOnlyRoot::kUndefinedValue);
565#else
566 if (!I::HasHeapObjectTag(obj)) return false;
567 if (I::GetInstanceType(obj) != I::kOddballType) return false;
568 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
569#endif // V8_STATIC_ROOTS_BOOL
570}
571
572bool Value::IsNull() const {
573#ifdef V8_ENABLE_CHECKS
574 return FullIsNull();
575#else
576 return QuickIsNull();
577#endif
578}
579
580bool Value::QuickIsNull() const {
581 using A = internal::Address;
582 using I = internal::Internals;
584#if V8_STATIC_ROOTS_BOOL
585 return I::is_identical(obj, I::StaticReadOnlyRoot::kNullValue);
586#else
587 if (!I::HasHeapObjectTag(obj)) return false;
588 if (I::GetInstanceType(obj) != I::kOddballType) return false;
589 return (I::GetOddballKind(obj) == I::kNullOddballKind);
590#endif // V8_STATIC_ROOTS_BOOL
591}
592
594#ifdef V8_ENABLE_CHECKS
595 return FullIsNull() || FullIsUndefined();
596#else
597 return QuickIsNullOrUndefined();
598#endif
599}
600
601bool Value::QuickIsNullOrUndefined() const {
602#if V8_STATIC_ROOTS_BOOL
603 return QuickIsNull() || QuickIsUndefined();
604#else
605 using A = internal::Address;
606 using I = internal::Internals;
608 if (!I::HasHeapObjectTag(obj)) return false;
609 if (I::GetInstanceType(obj) != I::kOddballType) return false;
610 int kind = I::GetOddballKind(obj);
611 return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
612#endif // V8_STATIC_ROOTS_BOOL
613}
614
615bool Value::IsTrue() const {
616#if V8_STATIC_ROOTS_BOOL && !defined(V8_ENABLE_CHECKS)
617 return QuickIsTrue();
618#else
619 return FullIsTrue();
620#endif
621}
622
623#if V8_STATIC_ROOTS_BOOL
624bool Value::QuickIsTrue() const {
625 using A = internal::Address;
626 using I = internal::Internals;
628 return I::is_identical(obj, I::StaticReadOnlyRoot::kTrueValue);
629}
630#endif // V8_STATIC_ROOTS_BOOL
631
632bool Value::IsFalse() const {
633#if V8_STATIC_ROOTS_BOOL && !defined(V8_ENABLE_CHECKS)
634 return QuickIsFalse();
635#else
636 return FullIsFalse();
637#endif
638}
639
640#if V8_STATIC_ROOTS_BOOL
641bool Value::QuickIsFalse() const {
642 using A = internal::Address;
643 using I = internal::Internals;
645 return I::is_identical(obj, I::StaticReadOnlyRoot::kFalseValue);
646}
647#endif // V8_STATIC_ROOTS_BOOL
648
649bool Value::IsString() const {
650#ifdef V8_ENABLE_CHECKS
651 return FullIsString();
652#else
653 return QuickIsString();
654#endif
655}
656
657bool Value::QuickIsString() const {
658 using A = internal::Address;
659 using I = internal::Internals;
661 if (!I::HasHeapObjectTag(obj)) return false;
662#if V8_STATIC_ROOTS_BOOL && !V8_MAP_PACKING
663 return I::CheckInstanceMapRange(obj,
664 I::StaticReadOnlyRoot::kStringMapLowerBound,
665 I::StaticReadOnlyRoot::kStringMapUpperBound);
666#else
667 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
668#endif // V8_STATIC_ROOTS_BOOL
669}
670
674 internal::Address cached =
676 return obj_map == cached;
677}
678
679} // namespace v8
680
681#endif // INCLUDE_V8_VALUE_H_
Definition: v8-data.h:18
Definition: v8-isolate.h:292
Definition: v8-local-handle.h:366
Definition: v8-local-handle.h:734
Definition: v8-maybe.h:39
Definition: v8-value.h:522
void Update(Local< Value > baseline)
TypecheckWitness(Isolate *isolate)
bool Matches(Local< Value > candidate) const
Definition: v8-value.h:671
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:593
bool IsTrue() const
Definition: v8-value.h:615
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:649
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:572
bool IsBoolean() const
bool SameValue(Local< Value > that) const
bool IsNativeError() const
bool IsFloat64Array() const
bool IsFalse() const
Definition: v8-value.h:632
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:474
MaybeLocal< Uint32 > ToUint32(Local< Context > context) const
bool IsUndefined() const
Definition: v8-value.h:551
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 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:983
static Address LoadMap(Address obj)
Definition: v8-internal.h:1296
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1854
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