v8 10.2.154 (node 18.16.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 IsArrayBuffer() const;
251
255 bool IsArrayBufferView() const;
256
260 bool IsTypedArray() const;
261
265 bool IsUint8Array() const;
266
271
275 bool IsInt8Array() const;
276
280 bool IsUint16Array() const;
281
285 bool IsInt16Array() const;
286
290 bool IsUint32Array() const;
291
295 bool IsInt32Array() const;
296
300 bool IsFloat32Array() const;
301
305 bool IsFloat64Array() const;
306
310 bool IsBigInt64Array() const;
311
315 bool IsBigUint64Array() const;
316
320 bool IsDataView() const;
321
326
330 bool IsProxy() const;
331
335 bool IsWasmMemoryObject() const;
336
340 bool IsWasmModuleObject() const;
341
346
351 Local<Context> context) const;
356 Local<Context> context) const;
361 Local<Context> context) const;
368 Local<Context> context) const;
373 Local<Context> context) const;
380 Local<Context> context) const;
387 Local<Context> context) const;
394
399
405 Local<Context> context) const;
406
408 bool BooleanValue(Isolate* isolate) const;
409
414 Local<Context> context) const;
417 Local<Context> context) const;
420
423 Local<Value> that) const;
424 bool StrictEquals(Local<Value> that) const;
425 bool SameValue(Local<Value> that) const;
426
427 template <class T>
428 V8_INLINE static Value* Cast(T* value) {
429 return static_cast<Value*>(value);
430 }
431
433
435
436 private:
437 V8_INLINE bool QuickIsUndefined() const;
438 V8_INLINE bool QuickIsNull() const;
439 V8_INLINE bool QuickIsNullOrUndefined() const;
440 V8_INLINE bool QuickIsString() const;
441 bool FullIsUndefined() const;
442 bool FullIsNull() const;
443 bool FullIsString() const;
444
445 static void CheckCast(Data* that);
446};
447
448template <>
450#ifdef V8_ENABLE_CHECKS
451 CheckCast(value);
452#endif
453 return static_cast<Value*>(value);
454}
455
456bool Value::IsUndefined() const {
457#ifdef V8_ENABLE_CHECKS
458 return FullIsUndefined();
459#else
460 return QuickIsUndefined();
461#endif
462}
463
464bool Value::QuickIsUndefined() const {
465 using A = internal::Address;
466 using I = internal::Internals;
467 A obj = *reinterpret_cast<const A*>(this);
468 if (!I::HasHeapObjectTag(obj)) return false;
469 if (I::GetInstanceType(obj) != I::kOddballType) return false;
470 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
471}
472
473bool Value::IsNull() const {
474#ifdef V8_ENABLE_CHECKS
475 return FullIsNull();
476#else
477 return QuickIsNull();
478#endif
479}
480
481bool Value::QuickIsNull() const {
482 using A = internal::Address;
483 using I = internal::Internals;
484 A obj = *reinterpret_cast<const A*>(this);
485 if (!I::HasHeapObjectTag(obj)) return false;
486 if (I::GetInstanceType(obj) != I::kOddballType) return false;
487 return (I::GetOddballKind(obj) == I::kNullOddballKind);
488}
489
491#ifdef V8_ENABLE_CHECKS
492 return FullIsNull() || FullIsUndefined();
493#else
494 return QuickIsNullOrUndefined();
495#endif
496}
497
498bool Value::QuickIsNullOrUndefined() const {
499 using A = internal::Address;
500 using I = internal::Internals;
501 A obj = *reinterpret_cast<const A*>(this);
502 if (!I::HasHeapObjectTag(obj)) return false;
503 if (I::GetInstanceType(obj) != I::kOddballType) return false;
504 int kind = I::GetOddballKind(obj);
505 return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
506}
507
508bool Value::IsString() const {
509#ifdef V8_ENABLE_CHECKS
510 return FullIsString();
511#else
512 return QuickIsString();
513#endif
514}
515
516bool Value::QuickIsString() const {
517 using A = internal::Address;
518 using I = internal::Internals;
519 A obj = *reinterpret_cast<const A*>(this);
520 if (!I::HasHeapObjectTag(obj)) return false;
521 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
522}
523
524} // namespace v8
525
526#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:490
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 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:508
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:428
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 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:473
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:456
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
uintptr_t Address
Definition v8-internal.h:29
#define V8_EXPORT
Definition v8config.h:578
#define V8_INLINE
Definition v8config.h:425
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:499