node-linux-s390x 21.7.3 → 22.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +335 -1514
  2. package/README.md +22 -18
  3. package/bin/node +0 -0
  4. package/include/node/common.gypi +29 -2
  5. package/include/node/config.gypi +7 -5
  6. package/include/node/cppgc/internal/api-constants.h +1 -1
  7. package/include/node/cppgc/type-traits.h +25 -4
  8. package/include/node/node.h +23 -2
  9. package/include/node/node_api.h +1 -1
  10. package/include/node/node_buffer.h +1 -1
  11. package/include/node/node_version.h +4 -4
  12. package/include/node/v8-array-buffer.h +6 -0
  13. package/include/node/v8-callbacks.h +6 -12
  14. package/include/node/v8-container.h +54 -0
  15. package/include/node/v8-context.h +51 -22
  16. package/include/node/v8-embedder-heap.h +19 -3
  17. package/include/node/v8-embedder-state-scope.h +2 -1
  18. package/include/node/v8-exception.h +15 -9
  19. package/include/node/v8-forward.h +1 -0
  20. package/include/node/v8-function-callback.h +129 -20
  21. package/include/node/v8-handle-base.h +32 -80
  22. package/include/node/v8-internal.h +472 -65
  23. package/include/node/v8-isolate.h +86 -51
  24. package/include/node/v8-local-handle.h +257 -31
  25. package/include/node/v8-memory-span.h +157 -2
  26. package/include/node/v8-message.h +22 -3
  27. package/include/node/v8-object.h +29 -10
  28. package/include/node/v8-persistent-handle.h +5 -3
  29. package/include/node/v8-platform.h +81 -44
  30. package/include/node/v8-script.h +61 -11
  31. package/include/node/v8-snapshot.h +94 -23
  32. package/include/node/v8-statistics.h +10 -24
  33. package/include/node/v8-template.h +410 -131
  34. package/include/node/v8-traced-handle.h +81 -46
  35. package/include/node/v8-typed-array.h +115 -7
  36. package/include/node/v8-value.h +92 -4
  37. package/include/node/v8-version.h +4 -4
  38. package/include/node/v8config.h +35 -10
  39. package/package.json +1 -1
  40. package/share/doc/node/gdbinit +77 -38
  41. package/share/doc/node/lldb_commands.py +59 -29
  42. package/share/man/man1/node.1 +7 -6
@@ -84,6 +84,29 @@ class V8_EXPORT Context : public Data {
84
84
  * created by a previous call to Context::New with the same global
85
85
  * template. The state of the global object will be completely reset
86
86
  * and only object identify will remain.
87
+ *
88
+ * \param internal_fields_deserializer An optional callback used
89
+ * to deserialize fields set by
90
+ * v8::Object::SetAlignedPointerInInternalField() in wrapper objects
91
+ * from the default context snapshot. It should match the
92
+ * SerializeInternalFieldsCallback() used by
93
+ * v8::SnapshotCreator::SetDefaultContext() when the default context
94
+ * snapshot is created. It does not need to be configured if the default
95
+ * context snapshot contains no wrapper objects with pointer internal
96
+ * fields, or if no custom startup snapshot is configured
97
+ * in the v8::CreateParams used to create the isolate.
98
+ *
99
+ * \param microtask_queue An optional microtask queue used to manage
100
+ * the microtasks created in this context. If not set the per-isolate
101
+ * default microtask queue would be used.
102
+ *
103
+ * \param context_data_deserializer An optional callback used
104
+ * to deserialize embedder data set by
105
+ * v8::Context::SetAlignedPointerInEmbedderData() in the default
106
+ * context from the default context snapshot. It does not need to be
107
+ * configured if the default context snapshot contains no pointer embedder
108
+ * data, or if no custom startup snapshot is configured in the
109
+ * v8::CreateParams used to create the isolate.
87
110
  */
88
111
  static Local<Context> New(
89
112
  Isolate* isolate, ExtensionConfiguration* extensions = nullptr,
@@ -91,7 +114,9 @@ class V8_EXPORT Context : public Data {
91
114
  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
92
115
  DeserializeInternalFieldsCallback internal_fields_deserializer =
93
116
  DeserializeInternalFieldsCallback(),
94
- MicrotaskQueue* microtask_queue = nullptr);
117
+ MicrotaskQueue* microtask_queue = nullptr,
118
+ DeserializeContextDataCallback context_data_deserializer =
119
+ DeserializeContextDataCallback());
95
120
 
96
121
  /**
97
122
  * Create a new context from a (non-default) context snapshot. There
@@ -103,21 +128,37 @@ class V8_EXPORT Context : public Data {
103
128
  * \param context_snapshot_index The index of the context snapshot to
104
129
  * deserialize from. Use v8::Context::New for the default snapshot.
105
130
  *
106
- * \param embedder_fields_deserializer Optional callback to deserialize
107
- * internal fields. It should match the SerializeInternalFieldCallback used
108
- * to serialize.
131
+ * \param internal_fields_deserializer An optional callback used
132
+ * to deserialize fields set by
133
+ * v8::Object::SetAlignedPointerInInternalField() in wrapper objects
134
+ * from the default context snapshot. It does not need to be
135
+ * configured if there are no wrapper objects with no internal
136
+ * pointer fields in the default context snapshot or if no startup
137
+ * snapshot is configured when the isolate is created.
109
138
  *
110
139
  * \param extensions See v8::Context::New.
111
140
  *
112
141
  * \param global_object See v8::Context::New.
142
+ *
143
+ * \param internal_fields_deserializer Similar to
144
+ * internal_fields_deserializer in v8::Context::New but applies to
145
+ * the context specified by the context_snapshot_index.
146
+ *
147
+ * \param microtask_queue See v8::Context::New.
148
+ *
149
+ * \param context_data_deserializer Similar to
150
+ * context_data_deserializer in v8::Context::New but applies to
151
+ * the context specified by the context_snapshot_index.
113
152
  */
114
153
  static MaybeLocal<Context> FromSnapshot(
115
154
  Isolate* isolate, size_t context_snapshot_index,
116
- DeserializeInternalFieldsCallback embedder_fields_deserializer =
155
+ DeserializeInternalFieldsCallback internal_fields_deserializer =
117
156
  DeserializeInternalFieldsCallback(),
118
157
  ExtensionConfiguration* extensions = nullptr,
119
158
  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
120
- MicrotaskQueue* microtask_queue = nullptr);
159
+ MicrotaskQueue* microtask_queue = nullptr,
160
+ DeserializeContextDataCallback context_data_deserializer =
161
+ DeserializeContextDataCallback());
121
162
 
122
163
  /**
123
164
  * Returns an global object that isn't backed by an actual context.
@@ -182,7 +223,7 @@ class V8_EXPORT Context : public Data {
182
223
  * parameter. Returns true if the operation completed successfully.
183
224
  */
184
225
  virtual bool FreezeEmbedderObjectAndGetChildren(
185
- Local<Object> obj, std::vector<Local<Object>>& children_out) = 0;
226
+ Local<Object> obj, LocalVector<Object>& children_out) = 0;
186
227
  };
187
228
 
188
229
  /**
@@ -309,18 +350,6 @@ class V8_EXPORT Context : public Data {
309
350
  Local<Context> context);
310
351
  void SetAbortScriptExecution(AbortScriptExecutionCallback callback);
311
352
 
312
- /**
313
- * Returns the value that was set or restored by
314
- * SetContinuationPreservedEmbedderData(), if any.
315
- */
316
- Local<Value> GetContinuationPreservedEmbedderData() const;
317
-
318
- /**
319
- * Sets a value that will be stored on continuations and reset while the
320
- * continuation runs.
321
- */
322
- void SetContinuationPreservedEmbedderData(Local<Value> context);
323
-
324
353
  /**
325
354
  * Set or clear hooks to be invoked for promise lifecycle operations.
326
355
  * To clear a hook, set it to an empty v8::Function. Each function will
@@ -436,12 +465,12 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) {
436
465
 
437
466
  template <class T>
438
467
  MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
439
- auto slot = GetDataFromSnapshotOnce(index);
440
- if (slot) {
468
+ if (auto slot = GetDataFromSnapshotOnce(index); slot) {
441
469
  internal::PerformCastCheck(
442
470
  internal::ValueHelper::SlotAsValue<T, false>(slot));
471
+ return Local<T>::FromSlot(slot);
443
472
  }
444
- return Local<T>::FromSlot(slot);
473
+ return {};
445
474
  }
446
475
 
447
476
  Context* Context::Cast(v8::Data* data) {
@@ -9,6 +9,9 @@
9
9
  #include "v8config.h" // NOLINT(build/include_directory)
10
10
 
11
11
  namespace v8 {
12
+ namespace internal {
13
+ class TracedHandles;
14
+ } // namespace internal
12
15
 
13
16
  class Isolate;
14
17
  class Value;
@@ -18,8 +21,17 @@ class Value;
18
21
  */
19
22
  class V8_EXPORT EmbedderRootsHandler {
20
23
  public:
24
+ enum class RootHandling {
25
+ kQueryEmbedderForNonDroppableReferences,
26
+ kDontQueryEmbedderForAnyReference,
27
+ };
28
+
21
29
  virtual ~EmbedderRootsHandler() = default;
22
30
 
31
+ EmbedderRootsHandler() = default;
32
+ explicit EmbedderRootsHandler(RootHandling default_traced_reference_handling)
33
+ : default_traced_reference_handling_(default_traced_reference_handling) {}
34
+
23
35
  /**
24
36
  * Returns true if the |TracedReference| handle should be considered as root
25
37
  * for the currently running non-tracing garbage collection and false
@@ -31,9 +43,7 @@ class V8_EXPORT EmbedderRootsHandler {
31
43
  * |TracedReference|.
32
44
  *
33
45
  * Note that the `handle` is different from the handle that the embedder holds
34
- * for retaining the object. The embedder may use |WrapperClassId()| to
35
- * distinguish cases where it wants handles to be treated as roots from not
36
- * being treated as roots.
46
+ * for retaining the object.
37
47
  *
38
48
  * The concrete implementations must be thread-safe.
39
49
  */
@@ -59,6 +69,12 @@ class V8_EXPORT EmbedderRootsHandler {
59
69
  ResetRoot(handle);
60
70
  return true;
61
71
  }
72
+
73
+ private:
74
+ const RootHandling default_traced_reference_handling_ =
75
+ RootHandling::kQueryEmbedderForNonDroppableReferences;
76
+
77
+ friend class internal::TracedHandles;
62
78
  };
63
79
 
64
80
  } // namespace v8
@@ -7,12 +7,13 @@
7
7
 
8
8
  #include <memory>
9
9
 
10
- #include "v8-context.h" // NOLINT(build/include_directory)
11
10
  #include "v8-internal.h" // NOLINT(build/include_directory)
12
11
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
13
12
 
14
13
  namespace v8 {
15
14
 
15
+ class Context;
16
+
16
17
  namespace internal {
17
18
  class EmbedderState;
18
19
  } // namespace internal
@@ -30,14 +30,21 @@ class ThreadLocalTop;
30
30
  */
31
31
  class V8_EXPORT Exception {
32
32
  public:
33
- static Local<Value> RangeError(Local<String> message);
34
- static Local<Value> ReferenceError(Local<String> message);
35
- static Local<Value> SyntaxError(Local<String> message);
36
- static Local<Value> TypeError(Local<String> message);
37
- static Local<Value> WasmCompileError(Local<String> message);
38
- static Local<Value> WasmLinkError(Local<String> message);
39
- static Local<Value> WasmRuntimeError(Local<String> message);
40
- static Local<Value> Error(Local<String> message);
33
+ static Local<Value> RangeError(Local<String> message,
34
+ Local<Value> options = {});
35
+ static Local<Value> ReferenceError(Local<String> message,
36
+ Local<Value> options = {});
37
+ static Local<Value> SyntaxError(Local<String> message,
38
+ Local<Value> options = {});
39
+ static Local<Value> TypeError(Local<String> message,
40
+ Local<Value> options = {});
41
+ static Local<Value> WasmCompileError(Local<String> message,
42
+ Local<Value> options = {});
43
+ static Local<Value> WasmLinkError(Local<String> message,
44
+ Local<Value> options = {});
45
+ static Local<Value> WasmRuntimeError(Local<String> message,
46
+ Local<Value> options = {});
47
+ static Local<Value> Error(Local<String> message, Local<Value> options = {});
41
48
 
42
49
  /**
43
50
  * Creates an error message for the given exception.
@@ -206,7 +213,6 @@ class V8_EXPORT TryCatch {
206
213
  bool can_continue_ : 1;
207
214
  bool capture_message_ : 1;
208
215
  bool rethrow_ : 1;
209
- bool has_terminated_ : 1;
210
216
 
211
217
  friend class internal::Isolate;
212
218
  friend class internal::ThreadLocalTop;
@@ -27,6 +27,7 @@ class Context;
27
27
  class DataView;
28
28
  class Data;
29
29
  class Date;
30
+ class DictionaryTemplate;
30
31
  class Extension;
31
32
  class External;
32
33
  class FixedArray;
@@ -5,6 +5,9 @@
5
5
  #ifndef INCLUDE_V8_FUNCTION_CALLBACK_H_
6
6
  #define INCLUDE_V8_FUNCTION_CALLBACK_H_
7
7
 
8
+ #include <cstdint>
9
+ #include <limits>
10
+
8
11
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
9
12
  #include "v8-primitive.h" // NOLINT(build/include_directory)
10
13
  #include "v8config.h" // NOLINT(build/include_directory)
@@ -39,14 +42,21 @@ class ReturnValue {
39
42
  template <typename S>
40
43
  V8_INLINE void Set(const Global<S>& handle);
41
44
  template <typename S>
45
+ V8_INLINE void SetNonEmpty(const Global<S>& handle);
46
+ template <typename S>
42
47
  V8_INLINE void Set(const BasicTracedReference<S>& handle);
43
48
  template <typename S>
49
+ V8_INLINE void SetNonEmpty(const BasicTracedReference<S>& handle);
50
+ template <typename S>
44
51
  V8_INLINE void Set(const Local<S> handle);
52
+ template <typename S>
53
+ V8_INLINE void SetNonEmpty(const Local<S> handle);
45
54
  // Fast primitive setters
46
55
  V8_INLINE void Set(bool value);
47
56
  V8_INLINE void Set(double i);
48
57
  V8_INLINE void Set(int32_t i);
49
58
  V8_INLINE void Set(uint32_t i);
59
+ V8_INLINE void Set(uint16_t);
50
60
  // Fast JS primitive setters
51
61
  V8_INLINE void SetNull();
52
62
  V8_INLINE void SetUndefined();
@@ -72,8 +82,15 @@ class ReturnValue {
72
82
  friend class PropertyCallbackInfo;
73
83
  template <class F, class G, class H>
74
84
  friend class PersistentValueMapBase;
75
- V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
76
- V8_INLINE internal::Address GetDefaultValue();
85
+ V8_INLINE void SetInternal(internal::Address value);
86
+ // Setting the hole value has different meanings depending on the usage:
87
+ // - for function template callbacks it means that the callback returns
88
+ // the undefined value,
89
+ // - for property getter callbacks is means that the callback returns
90
+ // the undefined value (for property setter callbacks the value returned
91
+ // is ignored),
92
+ // - for interceptor callbacks it means that the request was not handled.
93
+ V8_INLINE void SetTheHole();
77
94
  V8_INLINE explicit ReturnValue(internal::Address* slot);
78
95
 
79
96
  // See FunctionCallbackInfo.
@@ -276,44 +293,89 @@ using FunctionCallback = void (*)(const FunctionCallbackInfo<Value>& info);
276
293
  template <typename T>
277
294
  ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {}
278
295
 
296
+ template <typename T>
297
+ void ReturnValue<T>::SetInternal(internal::Address value) {
298
+ #if V8_STATIC_ROOTS_BOOL
299
+ using I = internal::Internals;
300
+ // Ensure that the upper 32-bits are not modified. Compiler should be
301
+ // able to optimize this to a store of a lower 32-bits of the value.
302
+ // This is fine since the callback can return only JavaScript values which
303
+ // are either Smis or heap objects allocated in the main cage.
304
+ *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
305
+ #else
306
+ *value_ = value;
307
+ #endif // V8_STATIC_ROOTS_BOOL
308
+ }
309
+
279
310
  template <typename T>
280
311
  template <typename S>
281
312
  void ReturnValue<T>::Set(const Global<S>& handle) {
282
313
  static_assert(std::is_base_of<T, S>::value, "type check");
283
314
  if (V8_UNLIKELY(handle.IsEmpty())) {
284
- *value_ = GetDefaultValue();
315
+ SetTheHole();
285
316
  } else {
286
- *value_ = handle.ptr();
317
+ SetInternal(handle.ptr());
287
318
  }
288
319
  }
289
320
 
321
+ template <typename T>
322
+ template <typename S>
323
+ void ReturnValue<T>::SetNonEmpty(const Global<S>& handle) {
324
+ static_assert(std::is_base_of<T, S>::value, "type check");
325
+ #ifdef V8_ENABLE_CHECKS
326
+ internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
327
+ #endif // V8_ENABLE_CHECKS
328
+ SetInternal(handle.ptr());
329
+ }
330
+
290
331
  template <typename T>
291
332
  template <typename S>
292
333
  void ReturnValue<T>::Set(const BasicTracedReference<S>& handle) {
293
334
  static_assert(std::is_base_of<T, S>::value, "type check");
294
335
  if (V8_UNLIKELY(handle.IsEmpty())) {
295
- *value_ = GetDefaultValue();
336
+ SetTheHole();
296
337
  } else {
297
- *value_ = handle.ptr();
338
+ SetInternal(handle.ptr());
298
339
  }
299
340
  }
300
341
 
342
+ template <typename T>
343
+ template <typename S>
344
+ void ReturnValue<T>::SetNonEmpty(const BasicTracedReference<S>& handle) {
345
+ static_assert(std::is_base_of<T, S>::value, "type check");
346
+ #ifdef V8_ENABLE_CHECKS
347
+ internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
348
+ #endif // V8_ENABLE_CHECKS
349
+ SetInternal(handle.ptr());
350
+ }
351
+
301
352
  template <typename T>
302
353
  template <typename S>
303
354
  void ReturnValue<T>::Set(const Local<S> handle) {
304
355
  static_assert(std::is_void<T>::value || std::is_base_of<T, S>::value,
305
356
  "type check");
306
357
  if (V8_UNLIKELY(handle.IsEmpty())) {
307
- *value_ = GetDefaultValue();
358
+ SetTheHole();
308
359
  } else {
309
- *value_ = handle.ptr();
360
+ SetInternal(handle.ptr());
310
361
  }
311
362
  }
312
363
 
364
+ template <typename T>
365
+ template <typename S>
366
+ void ReturnValue<T>::SetNonEmpty(const Local<S> handle) {
367
+ static_assert(std::is_void<T>::value || std::is_base_of<T, S>::value,
368
+ "type check");
369
+ #ifdef V8_ENABLE_CHECKS
370
+ internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
371
+ #endif // V8_ENABLE_CHECKS
372
+ SetInternal(handle.ptr());
373
+ }
374
+
313
375
  template <typename T>
314
376
  void ReturnValue<T>::Set(double i) {
315
377
  static_assert(std::is_base_of<T, Number>::value, "type check");
316
- Set(Number::New(GetIsolate(), i));
378
+ SetNonEmpty(Number::New(GetIsolate(), i));
317
379
  }
318
380
 
319
381
  template <typename T>
@@ -321,10 +383,10 @@ void ReturnValue<T>::Set(int32_t i) {
321
383
  static_assert(std::is_base_of<T, Integer>::value, "type check");
322
384
  using I = internal::Internals;
323
385
  if (V8_LIKELY(I::IsValidSmi(i))) {
324
- *value_ = I::IntToSmi(i);
386
+ SetInternal(I::IntToSmi(i));
325
387
  return;
326
388
  }
327
- Set(Integer::New(GetIsolate(), i));
389
+ SetNonEmpty(Integer::New(GetIsolate(), i));
328
390
  }
329
391
 
330
392
  template <typename T>
@@ -336,13 +398,30 @@ void ReturnValue<T>::Set(uint32_t i) {
336
398
  Set(static_cast<int32_t>(i));
337
399
  return;
338
400
  }
339
- Set(Integer::NewFromUnsigned(GetIsolate(), i));
401
+ SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
402
+ }
403
+
404
+ template <typename T>
405
+ void ReturnValue<T>::Set(uint16_t i) {
406
+ static_assert(std::is_base_of<T, Integer>::value, "type check");
407
+ using I = internal::Internals;
408
+ static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
409
+ static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
410
+ SetInternal(I::IntToSmi(i));
340
411
  }
341
412
 
342
413
  template <typename T>
343
414
  void ReturnValue<T>::Set(bool value) {
344
415
  static_assert(std::is_base_of<T, Boolean>::value, "type check");
345
416
  using I = internal::Internals;
417
+ #if V8_STATIC_ROOTS_BOOL
418
+ #ifdef V8_ENABLE_CHECKS
419
+ internal::PerformCastCheck(
420
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
421
+ #endif // V8_ENABLE_CHECKS
422
+ SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
423
+ : I::StaticReadOnlyRoot::kFalseValue);
424
+ #else
346
425
  int root_index;
347
426
  if (value) {
348
427
  root_index = I::kTrueValueRootIndex;
@@ -350,27 +429,62 @@ void ReturnValue<T>::Set(bool value) {
350
429
  root_index = I::kFalseValueRootIndex;
351
430
  }
352
431
  *value_ = I::GetRoot(GetIsolate(), root_index);
432
+ #endif // V8_STATIC_ROOTS_BOOL
433
+ }
434
+
435
+ template <typename T>
436
+ void ReturnValue<T>::SetTheHole() {
437
+ using I = internal::Internals;
438
+ #if V8_STATIC_ROOTS_BOOL
439
+ SetInternal(I::StaticReadOnlyRoot::kTheHoleValue);
440
+ #else
441
+ *value_ = I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex);
442
+ #endif // V8_STATIC_ROOTS_BOOL
353
443
  }
354
444
 
355
445
  template <typename T>
356
446
  void ReturnValue<T>::SetNull() {
357
447
  static_assert(std::is_base_of<T, Primitive>::value, "type check");
358
448
  using I = internal::Internals;
449
+ #if V8_STATIC_ROOTS_BOOL
450
+ #ifdef V8_ENABLE_CHECKS
451
+ internal::PerformCastCheck(
452
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
453
+ #endif // V8_ENABLE_CHECKS
454
+ SetInternal(I::StaticReadOnlyRoot::kNullValue);
455
+ #else
359
456
  *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
457
+ #endif // V8_STATIC_ROOTS_BOOL
360
458
  }
361
459
 
362
460
  template <typename T>
363
461
  void ReturnValue<T>::SetUndefined() {
364
462
  static_assert(std::is_base_of<T, Primitive>::value, "type check");
365
463
  using I = internal::Internals;
464
+ #if V8_STATIC_ROOTS_BOOL
465
+ #ifdef V8_ENABLE_CHECKS
466
+ internal::PerformCastCheck(
467
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
468
+ #endif // V8_ENABLE_CHECKS
469
+ SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
470
+ #else
366
471
  *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
472
+ #endif // V8_STATIC_ROOTS_BOOL
367
473
  }
368
474
 
369
475
  template <typename T>
370
476
  void ReturnValue<T>::SetEmptyString() {
371
477
  static_assert(std::is_base_of<T, String>::value, "type check");
372
478
  using I = internal::Internals;
479
+ #if V8_STATIC_ROOTS_BOOL
480
+ #ifdef V8_ENABLE_CHECKS
481
+ internal::PerformCastCheck(
482
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
483
+ #endif // V8_ENABLE_CHECKS
484
+ SetInternal(I::StaticReadOnlyRoot::kEmptyString);
485
+ #else
373
486
  *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
487
+ #endif // V8_STATIC_ROOTS_BOOL
374
488
  }
375
489
 
376
490
  template <typename T>
@@ -385,10 +499,11 @@ Local<Value> ReturnValue<T>::Get() const {
385
499
  if (I::is_identical(*value_, I::StaticReadOnlyRoot::kTheHoleValue)) {
386
500
  #else
387
501
  if (*value_ == I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex)) {
388
- #endif
502
+ #endif // V8_STATIC_ROOTS_BOOL
389
503
  return Undefined(GetIsolate());
390
504
  }
391
- return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
505
+ return Local<Value>::New(GetIsolate(),
506
+ internal::ValueHelper::SlotAsValue<Value>(value_));
392
507
  }
393
508
 
394
509
  template <typename T>
@@ -397,12 +512,6 @@ void ReturnValue<T>::Set(S* whatever) {
397
512
  static_assert(sizeof(S) < 0, "incompilable to prevent inadvertent misuse");
398
513
  }
399
514
 
400
- template <typename T>
401
- internal::Address ReturnValue<T>::GetDefaultValue() {
402
- using I = internal::Internals;
403
- return I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex);
404
- }
405
-
406
515
  template <typename T>
407
516
  FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Address* implicit_args,
408
517
  internal::Address* values,
@@ -7,92 +7,44 @@
7
7
 
8
8
  #include "v8-internal.h" // NOLINT(build/include_directory)
9
9
 
10
- namespace v8 {
10
+ namespace v8::api_internal {
11
11
 
12
- namespace internal {
13
-
14
- // Helper functions about values contained in handles.
15
- // A value is either an indirect pointer or a direct pointer, depending on
16
- // whether direct local support is enabled.
17
- class ValueHelper final {
12
+ template <bool check_statically_enabled>
13
+ class StackAllocated {
18
14
  public:
19
- #ifdef V8_ENABLE_DIRECT_LOCAL
20
- static constexpr Address kTaggedNullAddress = 1;
21
- static constexpr Address kEmpty = kTaggedNullAddress;
22
- #else
23
- static constexpr Address kEmpty = kNullAddress;
24
- #endif // V8_ENABLE_DIRECT_LOCAL
25
-
26
- template <typename T>
27
- V8_INLINE static bool IsEmpty(T* value) {
28
- return reinterpret_cast<Address>(value) == kEmpty;
29
- }
30
-
31
- // Returns a handle's "value" for all kinds of abstract handles. For Local,
32
- // it is equivalent to `*handle`. The variadic parameters support handle
33
- // types with extra type parameters, like `Persistent<T, M>`.
34
- template <template <typename T, typename... Ms> typename H, typename T,
35
- typename... Ms>
36
- V8_INLINE static T* HandleAsValue(const H<T, Ms...>& handle) {
37
- return handle.template value<T>();
38
- }
39
-
40
- #ifdef V8_ENABLE_DIRECT_LOCAL
41
-
42
- template <typename T>
43
- V8_INLINE static Address ValueAsAddress(const T* value) {
44
- return reinterpret_cast<Address>(value);
45
- }
46
-
47
- template <typename T, bool check_null = true, typename S>
48
- V8_INLINE static T* SlotAsValue(S* slot) {
49
- if (check_null && slot == nullptr) {
50
- return reinterpret_cast<T*>(kTaggedNullAddress);
51
- }
52
- return *reinterpret_cast<T**>(slot);
53
- }
15
+ V8_INLINE StackAllocated() = default;
54
16
 
55
- #else // !V8_ENABLE_DIRECT_LOCAL
56
-
57
- template <typename T>
58
- V8_INLINE static Address ValueAsAddress(const T* value) {
59
- return *reinterpret_cast<const Address*>(value);
60
- }
17
+ protected:
18
+ struct no_checking_tag {};
19
+ static constexpr no_checking_tag do_not_check{};
61
20
 
62
- template <typename T, bool check_null = true, typename S>
63
- V8_INLINE static T* SlotAsValue(S* slot) {
64
- return reinterpret_cast<T*>(slot);
65
- }
21
+ V8_INLINE explicit StackAllocated(no_checking_tag) {}
22
+ V8_INLINE explicit StackAllocated(const StackAllocated& other,
23
+ no_checking_tag) {}
66
24
 
67
- #endif // V8_ENABLE_DIRECT_LOCAL
25
+ V8_INLINE void VerifyOnStack() const {}
68
26
  };
69
27
 
70
- /**
71
- * Helper functions about handles.
72
- */
73
- class HandleHelper final {
28
+ template <>
29
+ class V8_TRIVIAL_ABI StackAllocated<true> : public StackAllocated<false> {
74
30
  public:
75
- /**
76
- * Checks whether two handles are equal.
77
- * They are equal iff they are both empty or they are both non-empty and the
78
- * objects to which they refer are physically equal.
79
- *
80
- * If both handles refer to JS objects, this is the same as strict equality.
81
- * For primitives, such as numbers or strings, a `false` return value does not
82
- * indicate that the values aren't equal in the JavaScript sense.
83
- * Use `Value::StrictEquals()` to check primitives for equality.
84
- */
85
- template <typename T1, typename T2>
86
- V8_INLINE static bool EqualHandles(const T1& lhs, const T2& rhs) {
87
- if (lhs.IsEmpty()) return rhs.IsEmpty();
88
- if (rhs.IsEmpty()) return false;
89
- return lhs.ptr() == rhs.ptr();
90
- }
31
+ V8_INLINE StackAllocated() { VerifyOnStack(); }
91
32
 
92
- static V8_EXPORT void VerifyOnStack(const void* ptr);
93
- };
33
+ #if V8_HAS_ATTRIBUTE_TRIVIAL_ABI
34
+ // In this case, StackAllocated becomes not trivially copyable.
35
+ V8_INLINE StackAllocated(const StackAllocated& other) { VerifyOnStack(); }
36
+ StackAllocated& operator=(const StackAllocated&) = default;
37
+ #endif
94
38
 
95
- } // namespace internal
39
+ protected:
40
+ V8_INLINE explicit StackAllocated(no_checking_tag tag)
41
+ : StackAllocated<false>(tag) {}
42
+ V8_INLINE explicit StackAllocated(const StackAllocated& other,
43
+ no_checking_tag tag)
44
+ : StackAllocated<false>(other, tag) {}
45
+
46
+ V8_EXPORT void VerifyOnStack() const;
47
+ };
96
48
 
97
49
  /**
98
50
  * A base class for abstract handles containing indirect pointers.
@@ -129,9 +81,9 @@ class IndirectHandleBase {
129
81
 
130
82
  // Returns the handler's "value" (direct or indirect pointer, depending on
131
83
  // whether direct local support is enabled).
132
- template <typename T>
84
+ template <typename T, bool check_null = false>
133
85
  V8_INLINE T* value() const {
134
- return internal::ValueHelper::SlotAsValue<T, false>(slot());
86
+ return internal::ValueHelper::SlotAsValue<T, check_null>(slot());
135
87
  }
136
88
 
137
89
  private:
@@ -169,7 +121,7 @@ class DirectHandleBase {
169
121
 
170
122
  // Returns the handler's "value" (direct pointer, as direct local support
171
123
  // is guaranteed to be enabled here).
172
- template <typename T>
124
+ template <typename T, bool check_null = false>
173
125
  V8_INLINE T* value() const {
174
126
  return reinterpret_cast<T*>(ptr_);
175
127
  }
@@ -180,6 +132,6 @@ class DirectHandleBase {
180
132
 
181
133
  #endif // V8_ENABLE_DIRECT_LOCAL
182
134
 
183
- } // namespace v8
135
+ } // namespace v8::api_internal
184
136
 
185
137
  #endif // INCLUDE_V8_HANDLE_BASE_H_