Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/node/v8-value.h
$ cat -n /usr/include/node/v8-value.h 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 14 /** 15 * The v8 JavaScript engine. 16 */ 17 namespace v8 { 18 19 class Primitive; 20 class Numeric; 21 class BigInt; 22 class Int32; 23 class Integer; 24 class Number; 25 class Object; 26 class String; 27 class Uint32; 28 29 /** 30 * The superclass of all JavaScript values and objects. 31 */ 32 class V8_EXPORT Value : public Data { 33 public: 34 /** 35 * Returns true if this value is the undefined value. See ECMA-262 36 * 4.3.10. 37 * 38 * This is equivalent to `value === undefined` in JS. 39 */ 40 V8_INLINE bool IsUndefined() const; 41 42 /** 43 * Returns true if this value is the null value. See ECMA-262 44 * 4.3.11. 45 * 46 * This is equivalent to `value === null` in JS. 47 */ 48 V8_INLINE bool IsNull() const; 49 50 /** 51 * Returns true if this value is either the null or the undefined value. 52 * See ECMA-262 53 * 4.3.11. and 4.3.12 54 * 55 * This is equivalent to `value == null` in JS. 56 */ 57 V8_INLINE bool IsNullOrUndefined() const; 58 59 /** 60 * Returns true if this value is true. 61 * 62 * This is not the same as `BooleanValue()`. The latter performs a 63 * conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas 64 * this checks `value === true`. 65 */ 66 V8_INLINE bool IsTrue() const; 67 68 /** 69 * Returns true if this value is false. 70 * 71 * This is not the same as `!BooleanValue()`. The latter performs a 72 * conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas 73 * this checks `value === false`. 74 */ 75 V8_INLINE bool IsFalse() const; 76 77 /** 78 * Returns true if this value is a symbol or a string. 79 * 80 * This is equivalent to 81 * `typeof value === 'string' || typeof value === 'symbol'` in JS. 82 */ 83 bool IsName() const; 84 85 /** 86 * Returns true if this value is an instance of the String type. 87 * See ECMA-262 8.4. 88 * 89 * This is equivalent to `typeof value === 'string'` in JS. 90 */ 91 V8_INLINE bool IsString() const; 92 93 /** 94 * Returns true if this value is a symbol. 95 * 96 * This is equivalent to `typeof value === 'symbol'` in JS. 97 */ 98 bool IsSymbol() const; 99 100 /** 101 * Returns true if this value is a function. 102 * 103 * This is equivalent to `typeof value === 'function'` in JS. 104 */ 105 bool IsFunction() const; 106 107 /** 108 * Returns true if this value is an array. Note that it will return false for 109 * an Proxy for an array. 110 */ 111 bool IsArray() const; 112 113 /** 114 * Returns true if this value is an object. 115 */ 116 bool IsObject() const; 117 118 /** 119 * Returns true if this value is a bigint. 120 * 121 * This is equivalent to `typeof value === 'bigint'` in JS. 122 */ 123 bool IsBigInt() const; 124 125 /** 126 * Returns true if this value is boolean. 127 * 128 * This is equivalent to `typeof value === 'boolean'` in JS. 129 */ 130 bool IsBoolean() const; 131 132 /** 133 * Returns true if this value is a number. 134 * 135 * This is equivalent to `typeof value === 'number'` in JS. 136 */ 137 bool IsNumber() const; 138 139 /** 140 * Returns true if this value is an `External` object. 141 */ 142 bool IsExternal() const; 143 144 /** 145 * Returns true if this value is a 32-bit signed integer. 146 */ 147 bool IsInt32() const; 148 149 /** 150 * Returns true if this value is a 32-bit unsigned integer. 151 */ 152 bool IsUint32() const; 153 154 /** 155 * Returns true if this value is a Date. 156 */ 157 bool IsDate() const; 158 159 /** 160 * Returns true if this value is an Arguments object. 161 */ 162 bool IsArgumentsObject() const; 163 164 /** 165 * Returns true if this value is a BigInt object. 166 */ 167 bool IsBigIntObject() const; 168 169 /** 170 * Returns true if this value is a Boolean object. 171 */ 172 bool IsBooleanObject() const; 173 174 /** 175 * Returns true if this value is a Number object. 176 */ 177 bool IsNumberObject() const; 178 179 /** 180 * Returns true if this value is a String object. 181 */ 182 bool IsStringObject() const; 183 184 /** 185 * Returns true if this value is a Symbol object. 186 */ 187 bool IsSymbolObject() const; 188 189 /** 190 * Returns true if this value is a NativeError. 191 */ 192 bool IsNativeError() const; 193 194 /** 195 * Returns true if this value is a RegExp. 196 */ 197 bool IsRegExp() const; 198 199 /** 200 * Returns true if this value is an async function. 201 */ 202 bool IsAsyncFunction() const; 203 204 /** 205 * Returns true if this value is a Generator function. 206 */ 207 bool IsGeneratorFunction() const; 208 209 /** 210 * Returns true if this value is a Generator object (iterator). 211 */ 212 bool IsGeneratorObject() const; 213 214 /** 215 * Returns true if this value is a Promise. 216 */ 217 bool IsPromise() const; 218 219 /** 220 * Returns true if this value is a Map. 221 */ 222 bool IsMap() const; 223 224 /** 225 * Returns true if this value is a Set. 226 */ 227 bool IsSet() const; 228 229 /** 230 * Returns true if this value is a Map Iterator. 231 */ 232 bool IsMapIterator() const; 233 234 /** 235 * Returns true if this value is a Set Iterator. 236 */ 237 bool IsSetIterator() const; 238 239 /** 240 * Returns true if this value is a WeakMap. 241 */ 242 bool IsWeakMap() const; 243 244 /** 245 * Returns true if this value is a WeakSet. 246 */ 247 bool IsWeakSet() const; 248 249 /** 250 * Returns true if this value is a WeakRef. 251 */ 252 bool IsWeakRef() const; 253 254 /** 255 * Returns true if this value is an ArrayBuffer. 256 */ 257 bool IsArrayBuffer() const; 258 259 /** 260 * Returns true if this value is an ArrayBufferView. 261 */ 262 bool IsArrayBufferView() const; 263 264 /** 265 * Returns true if this value is one of TypedArrays. 266 */ 267 bool IsTypedArray() const; 268 269 /** 270 * Returns true if this value is an Uint8Array. 271 */ 272 bool IsUint8Array() const; 273 274 /** 275 * Returns true if this value is an Uint8ClampedArray. 276 */ 277 bool IsUint8ClampedArray() const; 278 279 /** 280 * Returns true if this value is an Int8Array. 281 */ 282 bool IsInt8Array() const; 283 284 /** 285 * Returns true if this value is an Uint16Array. 286 */ 287 bool IsUint16Array() const; 288 289 /** 290 * Returns true if this value is an Int16Array. 291 */ 292 bool IsInt16Array() const; 293 294 /** 295 * Returns true if this value is an Uint32Array. 296 */ 297 bool IsUint32Array() const; 298 299 /** 300 * Returns true if this value is an Int32Array. 301 */ 302 bool IsInt32Array() const; 303 304 /** 305 * Returns true if this value is a Float16Array. 306 */ 307 bool IsFloat16Array() const; 308 309 /** 310 * Returns true if this value is a Float32Array. 311 */ 312 bool IsFloat32Array() const; 313 314 /** 315 * Returns true if this value is a Float64Array. 316 */ 317 bool IsFloat64Array() const; 318 319 /** 320 * Returns true if this value is a BigInt64Array. 321 */ 322 bool IsBigInt64Array() const; 323 324 /** 325 * Returns true if this value is a BigUint64Array. 326 */ 327 bool IsBigUint64Array() const; 328 329 /** 330 * Returns true if this value is a DataView. 331 */ 332 bool IsDataView() const; 333 334 /** 335 * Returns true if this value is a SharedArrayBuffer. 336 */ 337 bool IsSharedArrayBuffer() const; 338 339 /** 340 * Returns true if this value is a JavaScript Proxy. 341 */ 342 bool IsProxy() const; 343 344 /** 345 * Returns true if this value is a WasmMemoryObject. 346 */ 347 bool IsWasmMemoryObject() const; 348 349 /** 350 * Returns true if this value is a WasmModuleObject. 351 */ 352 bool IsWasmModuleObject() const; 353 354 /** 355 * Returns true if this value is the WasmNull object. 356 */ 357 bool IsWasmNull() const; 358 359 /** 360 * Returns true if the value is a Module Namespace Object. 361 */ 362 bool IsModuleNamespaceObject() const; 363 364 /** 365 * Perform `ToPrimitive(value)` as specified in: 366 * https://tc39.es/ecma262/#sec-toprimitive. 367 */ 368 V8_WARN_UNUSED_RESULT MaybeLocal
ToPrimitive( 369 Local
context) const; 370 /** 371 * Perform `ToNumeric(value)` as specified in: 372 * https://tc39.es/ecma262/#sec-tonumeric. 373 */ 374 V8_WARN_UNUSED_RESULT MaybeLocal
ToNumeric( 375 Local
context) const; 376 /** 377 * Perform the equivalent of `BigInt(value)` in JS. 378 */ 379 V8_WARN_UNUSED_RESULT MaybeLocal
ToBigInt( 380 Local
context) const; 381 /** 382 * Perform the equivalent of `Number(value)` in JS. 383 */ 384 V8_WARN_UNUSED_RESULT MaybeLocal
ToNumber( 385 Local
context) const; 386 /** 387 * Perform the equivalent of `String(value)` in JS. 388 */ 389 V8_WARN_UNUSED_RESULT MaybeLocal
ToString( 390 Local
context) const; 391 /** 392 * Provide a string representation of this value usable for debugging. 393 * This operation has no observable side effects and will succeed 394 * unless e.g. execution is being terminated. 395 */ 396 V8_WARN_UNUSED_RESULT MaybeLocal
ToDetailString( 397 Local
context) const; 398 /** 399 * Perform the equivalent of `Tagged
(value)` in JS. 400 */ 401 V8_WARN_UNUSED_RESULT MaybeLocal
ToObject( 402 Local
context) const; 403 /** 404 * Perform the equivalent of `Number(value)` in JS and convert the result 405 * to an integer. Negative values are rounded up, positive values are rounded 406 * down. NaN is converted to 0. Infinite values yield undefined results. 407 */ 408 V8_WARN_UNUSED_RESULT MaybeLocal
ToInteger( 409 Local
context) const; 410 /** 411 * Perform the equivalent of `Number(value)` in JS and convert the result 412 * to an unsigned 32-bit integer by performing the steps in 413 * https://tc39.es/ecma262/#sec-touint32. 414 */ 415 V8_WARN_UNUSED_RESULT MaybeLocal
ToUint32( 416 Local
context) const; 417 /** 418 * Perform the equivalent of `Number(value)` in JS and convert the result 419 * to a signed 32-bit integer by performing the steps in 420 * https://tc39.es/ecma262/#sec-toint32. 421 */ 422 V8_WARN_UNUSED_RESULT MaybeLocal
ToInt32(Local
context) const; 423 424 /** 425 * Perform the equivalent of `Boolean(value)` in JS. This can never fail. 426 */ 427 Local
ToBoolean(Isolate* isolate) const; 428 429 /** 430 * Attempts to convert a string to an array index. 431 * Returns an empty handle if the conversion fails. 432 */ 433 V8_WARN_UNUSED_RESULT MaybeLocal
ToArrayIndex( 434 Local
context) const; 435 436 /** Returns the equivalent of `ToBoolean()->Value()`. */ 437 bool BooleanValue(Isolate* isolate) const; 438 439 /** Returns the equivalent of `ToNumber()->Value()`. */ 440 V8_WARN_UNUSED_RESULT Maybe
NumberValue(Local
context) const; 441 /** Returns the equivalent of `ToInteger()->Value()`. */ 442 V8_WARN_UNUSED_RESULT Maybe
IntegerValue( 443 Local
context) const; 444 /** Returns the equivalent of `ToUint32()->Value()`. */ 445 V8_WARN_UNUSED_RESULT Maybe
Uint32Value( 446 Local
context) const; 447 /** Returns the equivalent of `ToInt32()->Value()`. */ 448 V8_WARN_UNUSED_RESULT Maybe
Int32Value(Local
context) const; 449 450 /** JS == */ 451 V8_WARN_UNUSED_RESULT Maybe
Equals(Local
context, 452 Local
that) const; 453 bool StrictEquals(Local
that) const; 454 bool SameValue(Local
that) const; 455 456 template
457 V8_INLINE static Value* Cast(T* value) { 458 return static_cast
(value); 459 } 460 461 Local
TypeOf(Isolate*); 462 463 Maybe
InstanceOf(Local
context, Local
object); 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 483 /** 484 * Can be used to avoid repeated expensive type checks for groups of objects 485 * that are expected to be similar (e.g. when Blink converts a bunch of 486 * JavaScript objects to "ScriptWrappable" after a "HasInstance" check) by 487 * making use of V8-internal "hidden classes". An object that has passed the 488 * full check can be remembered via {Update}; further objects can be queried 489 * using {Matches}. 490 * Note that the answer will be conservative/"best-effort": when {Matches} 491 * returns true, then the {candidate} can be relied upon to have the same 492 * shape/constructor/prototype/etc. as the {baseline}. Otherwise, no reliable 493 * statement can be made (the objects might still have indistinguishable shapes 494 * for all intents and purposes, but this mechanism, being optimized for speed, 495 * couldn't determine that quickly). 496 */ 497 class V8_EXPORT TypecheckWitness { 498 public: 499 explicit TypecheckWitness(Isolate* isolate); 500 501 /** 502 * Checks whether {candidate} can cheaply be identified as being "similar" 503 * to the {baseline} that was passed to {Update} earlier. 504 * It's safe to call this on an uninitialized {TypecheckWitness} instance: 505 * it will then return {false} for any input. 506 */ 507 V8_INLINE bool Matches(Local
candidate) const; 508 509 /** 510 * Remembers a new baseline for future {Matches} queries. 511 */ 512 void Update(Local
baseline); 513 514 private: 515 Local
cached_map_; 516 }; 517 518 template <> 519 V8_INLINE Value* Value::Cast(Data* value) { 520 #ifdef V8_ENABLE_CHECKS 521 CheckCast(value); 522 #endif 523 return static_cast
(value); 524 } 525 526 bool Value::IsUndefined() const { 527 #ifdef V8_ENABLE_CHECKS 528 return FullIsUndefined(); 529 #else 530 return QuickIsUndefined(); 531 #endif 532 } 533 534 bool Value::QuickIsUndefined() const { 535 using A = internal::Address; 536 using I = internal::Internals; 537 A obj = internal::ValueHelper::ValueAsAddress(this); 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 547 bool Value::IsNull() const { 548 #ifdef V8_ENABLE_CHECKS 549 return FullIsNull(); 550 #else 551 return QuickIsNull(); 552 #endif 553 } 554 555 bool Value::QuickIsNull() const { 556 using A = internal::Address; 557 using I = internal::Internals; 558 A obj = internal::ValueHelper::ValueAsAddress(this); 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 568 bool Value::IsNullOrUndefined() const { 569 #ifdef V8_ENABLE_CHECKS 570 return FullIsNull() || FullIsUndefined(); 571 #else 572 return QuickIsNullOrUndefined(); 573 #endif 574 } 575 576 bool 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; 582 A obj = internal::ValueHelper::ValueAsAddress(this); 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 590 bool 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 599 bool Value::QuickIsTrue() const { 600 using A = internal::Address; 601 using I = internal::Internals; 602 A obj = internal::ValueHelper::ValueAsAddress(this); 603 return I::is_identical(obj, I::StaticReadOnlyRoot::kTrueValue); 604 } 605 #endif // V8_STATIC_ROOTS_BOOL 606 607 bool 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 616 bool Value::QuickIsFalse() const { 617 using A = internal::Address; 618 using I = internal::Internals; 619 A obj = internal::ValueHelper::ValueAsAddress(this); 620 return I::is_identical(obj, I::StaticReadOnlyRoot::kFalseValue); 621 } 622 #endif // V8_STATIC_ROOTS_BOOL 623 624 bool Value::IsString() const { 625 #ifdef V8_ENABLE_CHECKS 626 return FullIsString(); 627 #else 628 return QuickIsString(); 629 #endif 630 } 631 632 bool Value::QuickIsString() const { 633 using A = internal::Address; 634 using I = internal::Internals; 635 A obj = internal::ValueHelper::ValueAsAddress(this); 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 645 bool TypecheckWitness::Matches(Local
candidate) const { 646 internal::Address obj = internal::ValueHelper::ValueAsAddress(*candidate); 647 internal::Address obj_map = internal::Internals::LoadMap(obj); 648 internal::Address cached = 649 internal::ValueHelper::ValueAsAddress(*cached_map_); 650 return obj_map == cached; 651 } 652 653 } // namespace v8 654 655 #endif // INCLUDE_V8_VALUE_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™