libv8-node 16.10.0.0-x86_64-darwin → 18.8.0.0-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/paths.rb +1 -1
  3. data/lib/libv8/node/version.rb +3 -3
  4. data/vendor/v8/include/cppgc/allocation.h +100 -22
  5. data/vendor/v8/include/cppgc/cross-thread-persistent.h +114 -33
  6. data/vendor/v8/include/cppgc/default-platform.h +2 -10
  7. data/vendor/v8/include/cppgc/explicit-management.h +22 -4
  8. data/vendor/v8/include/cppgc/garbage-collected.h +15 -26
  9. data/vendor/v8/include/cppgc/heap-consistency.h +30 -0
  10. data/vendor/v8/include/cppgc/heap-state.h +12 -0
  11. data/vendor/v8/include/cppgc/heap.h +7 -2
  12. data/vendor/v8/include/cppgc/internal/api-constants.h +8 -0
  13. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +25 -14
  14. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +4 -1
  15. data/vendor/v8/include/cppgc/internal/gc-info.h +90 -10
  16. data/vendor/v8/include/cppgc/internal/logging.h +3 -3
  17. data/vendor/v8/include/cppgc/internal/name-trait.h +11 -0
  18. data/vendor/v8/include/cppgc/internal/persistent-node.h +73 -29
  19. data/vendor/v8/include/cppgc/internal/pointer-policies.h +26 -15
  20. data/vendor/v8/include/cppgc/internal/write-barrier.h +62 -23
  21. data/vendor/v8/include/cppgc/liveness-broker.h +4 -1
  22. data/vendor/v8/include/cppgc/member.h +7 -2
  23. data/vendor/v8/include/cppgc/persistent.h +38 -33
  24. data/vendor/v8/include/cppgc/platform.h +4 -1
  25. data/vendor/v8/include/cppgc/prefinalizer.h +35 -12
  26. data/vendor/v8/include/cppgc/testing.h +9 -2
  27. data/vendor/v8/include/cppgc/type-traits.h +6 -13
  28. data/vendor/v8/include/cppgc/visitor.h +9 -7
  29. data/vendor/v8/include/libplatform/libplatform.h +0 -11
  30. data/vendor/v8/include/libplatform/v8-tracing.h +0 -1
  31. data/vendor/v8/include/v8-array-buffer.h +445 -0
  32. data/vendor/v8/include/v8-callbacks.h +397 -0
  33. data/vendor/v8/include/v8-container.h +129 -0
  34. data/vendor/v8/include/v8-context.h +407 -0
  35. data/vendor/v8/include/v8-cppgc.h +21 -128
  36. data/vendor/v8/include/v8-data.h +80 -0
  37. data/vendor/v8/include/v8-date.h +43 -0
  38. data/vendor/v8/include/v8-debug.h +168 -0
  39. data/vendor/v8/include/v8-embedder-heap.h +218 -0
  40. data/vendor/v8/include/v8-embedder-state-scope.h +51 -0
  41. data/vendor/v8/include/v8-exception.h +217 -0
  42. data/vendor/v8/include/v8-extension.h +62 -0
  43. data/vendor/v8/include/v8-external.h +37 -0
  44. data/vendor/v8/include/v8-fast-api-calls.h +172 -24
  45. data/vendor/v8/include/v8-forward.h +81 -0
  46. data/vendor/v8/include/v8-function-callback.h +475 -0
  47. data/vendor/v8/include/v8-function.h +125 -0
  48. data/vendor/v8/include/v8-initialization.h +315 -0
  49. data/vendor/v8/include/v8-inspector.h +56 -28
  50. data/vendor/v8/include/v8-internal.h +217 -55
  51. data/vendor/v8/include/v8-isolate.h +1709 -0
  52. data/vendor/v8/include/v8-json.h +47 -0
  53. data/vendor/v8/include/v8-local-handle.h +455 -0
  54. data/vendor/v8/include/v8-locker.h +149 -0
  55. data/vendor/v8/include/v8-maybe.h +137 -0
  56. data/vendor/v8/include/v8-memory-span.h +43 -0
  57. data/vendor/v8/include/v8-message.h +216 -0
  58. data/vendor/v8/include/v8-metrics.h +69 -16
  59. data/vendor/v8/include/v8-microtask-queue.h +152 -0
  60. data/vendor/v8/include/v8-microtask.h +28 -0
  61. data/vendor/v8/include/v8-object.h +775 -0
  62. data/vendor/v8/include/v8-persistent-handle.h +590 -0
  63. data/vendor/v8/include/v8-platform.h +400 -17
  64. data/vendor/v8/include/v8-primitive-object.h +118 -0
  65. data/vendor/v8/include/v8-primitive.h +866 -0
  66. data/vendor/v8/include/v8-profiler.h +88 -13
  67. data/vendor/v8/include/v8-promise.h +174 -0
  68. data/vendor/v8/include/v8-proxy.h +50 -0
  69. data/vendor/v8/include/v8-regexp.h +105 -0
  70. data/vendor/v8/include/v8-script.h +747 -0
  71. data/vendor/v8/include/v8-snapshot.h +196 -0
  72. data/vendor/v8/include/v8-statistics.h +217 -0
  73. data/vendor/v8/include/v8-template.h +1079 -0
  74. data/vendor/v8/include/v8-traced-handle.h +420 -0
  75. data/vendor/v8/include/v8-typed-array.h +282 -0
  76. data/vendor/v8/include/v8-unwinder-state.h +4 -3
  77. data/vendor/v8/include/v8-unwinder.h +132 -0
  78. data/vendor/v8/include/v8-util.h +7 -1
  79. data/vendor/v8/include/v8-value-serializer-version.h +1 -1
  80. data/vendor/v8/include/v8-value-serializer.h +279 -0
  81. data/vendor/v8/include/v8-value.h +526 -0
  82. data/vendor/v8/include/v8-version.h +4 -4
  83. data/vendor/v8/include/v8-wasm.h +257 -0
  84. data/vendor/v8/include/v8-weak-callback-info.h +87 -0
  85. data/vendor/v8/include/v8.h +41 -12601
  86. data/vendor/v8/include/v8config.h +102 -12
  87. data/vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a +0 -0
  88. metadata +47 -5
  89. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +0 -30
@@ -0,0 +1,43 @@
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_DATE_H_
6
+ #define INCLUDE_V8_DATE_H_
7
+
8
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
9
+ #include "v8-object.h" // NOLINT(build/include_directory)
10
+ #include "v8config.h" // NOLINT(build/include_directory)
11
+
12
+ namespace v8 {
13
+
14
+ class Context;
15
+
16
+ /**
17
+ * An instance of the built-in Date constructor (ECMA-262, 15.9).
18
+ */
19
+ class V8_EXPORT Date : public Object {
20
+ public:
21
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
22
+ double time);
23
+
24
+ /**
25
+ * A specialization of Value::NumberValue that is more efficient
26
+ * because we know the structure of this object.
27
+ */
28
+ double ValueOf() const;
29
+
30
+ V8_INLINE static Date* Cast(Value* value) {
31
+ #ifdef V8_ENABLE_CHECKS
32
+ CheckCast(value);
33
+ #endif
34
+ return static_cast<Date*>(value);
35
+ }
36
+
37
+ private:
38
+ static void CheckCast(Value* obj);
39
+ };
40
+
41
+ } // namespace v8
42
+
43
+ #endif // INCLUDE_V8_DATE_H_
@@ -0,0 +1,168 @@
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_DEBUG_H_
6
+ #define INCLUDE_V8_DEBUG_H_
7
+
8
+ #include <stdint.h>
9
+
10
+ #include "v8-script.h" // NOLINT(build/include_directory)
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace v8 {
14
+
15
+ class Isolate;
16
+ class String;
17
+
18
+ /**
19
+ * A single JavaScript stack frame.
20
+ */
21
+ class V8_EXPORT StackFrame {
22
+ public:
23
+ /**
24
+ * Returns the source location, 0-based, for the associated function call.
25
+ */
26
+ Location GetLocation() const;
27
+
28
+ /**
29
+ * Returns the number, 1-based, of the line for the associate function call.
30
+ * This method will return Message::kNoLineNumberInfo if it is unable to
31
+ * retrieve the line number, or if kLineNumber was not passed as an option
32
+ * when capturing the StackTrace.
33
+ */
34
+ int GetLineNumber() const { return GetLocation().GetLineNumber() + 1; }
35
+
36
+ /**
37
+ * Returns the 1-based column offset on the line for the associated function
38
+ * call.
39
+ * This method will return Message::kNoColumnInfo if it is unable to retrieve
40
+ * the column number, or if kColumnOffset was not passed as an option when
41
+ * capturing the StackTrace.
42
+ */
43
+ int GetColumn() const { return GetLocation().GetColumnNumber() + 1; }
44
+
45
+ /**
46
+ * Returns the id of the script for the function for this StackFrame.
47
+ * This method will return Message::kNoScriptIdInfo if it is unable to
48
+ * retrieve the script id, or if kScriptId was not passed as an option when
49
+ * capturing the StackTrace.
50
+ */
51
+ int GetScriptId() const;
52
+
53
+ /**
54
+ * Returns the name of the resource that contains the script for the
55
+ * function for this StackFrame.
56
+ */
57
+ Local<String> GetScriptName() const;
58
+
59
+ /**
60
+ * Returns the name of the resource that contains the script for the
61
+ * function for this StackFrame or sourceURL value if the script name
62
+ * is undefined and its source ends with //# sourceURL=... string or
63
+ * deprecated //@ sourceURL=... string.
64
+ */
65
+ Local<String> GetScriptNameOrSourceURL() const;
66
+
67
+ /**
68
+ * Returns the source of the script for the function for this StackFrame.
69
+ */
70
+ Local<String> GetScriptSource() const;
71
+
72
+ /**
73
+ * Returns the source mapping URL (if one is present) of the script for
74
+ * the function for this StackFrame.
75
+ */
76
+ Local<String> GetScriptSourceMappingURL() const;
77
+
78
+ /**
79
+ * Returns the name of the function associated with this stack frame.
80
+ */
81
+ Local<String> GetFunctionName() const;
82
+
83
+ /**
84
+ * Returns whether or not the associated function is compiled via a call to
85
+ * eval().
86
+ */
87
+ bool IsEval() const;
88
+
89
+ /**
90
+ * Returns whether or not the associated function is called as a
91
+ * constructor via "new".
92
+ */
93
+ bool IsConstructor() const;
94
+
95
+ /**
96
+ * Returns whether or not the associated functions is defined in wasm.
97
+ */
98
+ bool IsWasm() const;
99
+
100
+ /**
101
+ * Returns whether or not the associated function is defined by the user.
102
+ */
103
+ bool IsUserJavaScript() const;
104
+ };
105
+
106
+ /**
107
+ * Representation of a JavaScript stack trace. The information collected is a
108
+ * snapshot of the execution stack and the information remains valid after
109
+ * execution continues.
110
+ */
111
+ class V8_EXPORT StackTrace {
112
+ public:
113
+ /**
114
+ * Flags that determine what information is placed captured for each
115
+ * StackFrame when grabbing the current stack trace.
116
+ * Note: these options are deprecated and we always collect all available
117
+ * information (kDetailed).
118
+ */
119
+ enum StackTraceOptions {
120
+ kLineNumber = 1,
121
+ kColumnOffset = 1 << 1 | kLineNumber,
122
+ kScriptName = 1 << 2,
123
+ kFunctionName = 1 << 3,
124
+ kIsEval = 1 << 4,
125
+ kIsConstructor = 1 << 5,
126
+ kScriptNameOrSourceURL = 1 << 6,
127
+ kScriptId = 1 << 7,
128
+ kExposeFramesAcrossSecurityOrigins = 1 << 8,
129
+ kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
130
+ kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
131
+ };
132
+
133
+ /**
134
+ * Returns a StackFrame at a particular index.
135
+ */
136
+ Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
137
+
138
+ /**
139
+ * Returns the number of StackFrames.
140
+ */
141
+ int GetFrameCount() const;
142
+
143
+ /**
144
+ * Grab a snapshot of the current JavaScript execution stack.
145
+ *
146
+ * \param frame_limit The maximum number of stack frames we want to capture.
147
+ * \param options Enumerates the set of things we will capture for each
148
+ * StackFrame.
149
+ */
150
+ static Local<StackTrace> CurrentStackTrace(
151
+ Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
152
+
153
+ /**
154
+ * Returns the first valid script name or source URL starting at the top of
155
+ * the JS stack. The returned string is either an empty handle if no script
156
+ * name/url was found or a non-zero-length string.
157
+ *
158
+ * This method is equivalent to calling StackTrace::CurrentStackTrace and
159
+ * walking the resulting frames from the beginning until a non-empty script
160
+ * name/url is found. The difference is that this method won't allocate
161
+ * a stack trace.
162
+ */
163
+ static Local<String> CurrentScriptNameOrSourceURL(Isolate* isolate);
164
+ };
165
+
166
+ } // namespace v8
167
+
168
+ #endif // INCLUDE_V8_DEBUG_H_
@@ -0,0 +1,218 @@
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_EMBEDDER_HEAP_H_
6
+ #define INCLUDE_V8_EMBEDDER_HEAP_H_
7
+
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+
11
+ #include <utility>
12
+ #include <vector>
13
+
14
+ #include "cppgc/common.h"
15
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
16
+ #include "v8-traced-handle.h" // NOLINT(build/include_directory)
17
+ #include "v8config.h" // NOLINT(build/include_directory)
18
+
19
+ namespace v8 {
20
+
21
+ class Data;
22
+ class Isolate;
23
+ class Value;
24
+
25
+ namespace internal {
26
+ class LocalEmbedderHeapTracer;
27
+ } // namespace internal
28
+
29
+ /**
30
+ * Handler for embedder roots on non-unified heap garbage collections.
31
+ */
32
+ class V8_EXPORT EmbedderRootsHandler {
33
+ public:
34
+ virtual ~EmbedderRootsHandler() = default;
35
+
36
+ /**
37
+ * Returns true if the |TracedReference| handle should be considered as root
38
+ * for the currently running non-tracing garbage collection and false
39
+ * otherwise. The default implementation will keep all |TracedReference|
40
+ * references as roots.
41
+ *
42
+ * If this returns false, then V8 may decide that the object referred to by
43
+ * such a handle is reclaimed. In that case, V8 calls |ResetRoot()| for the
44
+ * |TracedReference|.
45
+ *
46
+ * Note that the `handle` is different from the handle that the embedder holds
47
+ * for retaining the object. The embedder may use |WrapperClassId()| to
48
+ * distinguish cases where it wants handles to be treated as roots from not
49
+ * being treated as roots.
50
+ */
51
+ virtual bool IsRoot(const v8::TracedReference<v8::Value>& handle) = 0;
52
+
53
+ /**
54
+ * Used in combination with |IsRoot|. Called by V8 when an
55
+ * object that is backed by a handle is reclaimed by a non-tracing garbage
56
+ * collection. It is up to the embedder to reset the original handle.
57
+ *
58
+ * Note that the |handle| is different from the handle that the embedder holds
59
+ * for retaining the object. It is up to the embedder to find the original
60
+ * handle via the object or class id.
61
+ */
62
+ virtual void ResetRoot(const v8::TracedReference<v8::Value>& handle) = 0;
63
+ };
64
+
65
+ /**
66
+ * Interface for tracing through the embedder heap. During a V8 garbage
67
+ * collection, V8 collects hidden fields of all potential wrappers, and at the
68
+ * end of its marking phase iterates the collection and asks the embedder to
69
+ * trace through its heap and use reporter to report each JavaScript object
70
+ * reachable from any of the given wrappers.
71
+ */
72
+ class V8_EXPORT EmbedderHeapTracer {
73
+ public:
74
+ using EmbedderStackState = cppgc::EmbedderStackState;
75
+
76
+ enum TraceFlags : uint64_t {
77
+ kNoFlags = 0,
78
+ kReduceMemory = 1 << 0,
79
+ kForced = 1 << 2,
80
+ };
81
+
82
+ /**
83
+ * Interface for iterating through |TracedReference| handles.
84
+ */
85
+ class V8_EXPORT TracedGlobalHandleVisitor {
86
+ public:
87
+ virtual ~TracedGlobalHandleVisitor() = default;
88
+ virtual void VisitTracedReference(const TracedReference<Value>& handle) {}
89
+ };
90
+
91
+ /**
92
+ * Summary of a garbage collection cycle. See |TraceEpilogue| on how the
93
+ * summary is reported.
94
+ */
95
+ struct TraceSummary {
96
+ /**
97
+ * Time spent managing the retained memory in milliseconds. This can e.g.
98
+ * include the time tracing through objects in the embedder.
99
+ */
100
+ double time = 0.0;
101
+
102
+ /**
103
+ * Memory retained by the embedder through the |EmbedderHeapTracer|
104
+ * mechanism in bytes.
105
+ */
106
+ size_t allocated_size = 0;
107
+ };
108
+
109
+ virtual ~EmbedderHeapTracer() = default;
110
+
111
+ /**
112
+ * Iterates all |TracedReference| handles created for the |v8::Isolate| the
113
+ * tracer is attached to.
114
+ */
115
+ void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor);
116
+
117
+ /**
118
+ * Called by the embedder to set the start of the stack which is e.g. used by
119
+ * V8 to determine whether handles are used from stack or heap.
120
+ */
121
+ void SetStackStart(void* stack_start);
122
+
123
+ /**
124
+ * Called by v8 to register internal fields of found wrappers.
125
+ *
126
+ * The embedder is expected to store them somewhere and trace reachable
127
+ * wrappers from them when called through |AdvanceTracing|.
128
+ */
129
+ virtual void RegisterV8References(
130
+ const std::vector<std::pair<void*, void*>>& embedder_fields) = 0;
131
+
132
+ void RegisterEmbedderReference(const BasicTracedReference<v8::Data>& ref);
133
+
134
+ /**
135
+ * Called at the beginning of a GC cycle.
136
+ */
137
+ virtual void TracePrologue(TraceFlags flags) {}
138
+
139
+ /**
140
+ * Called to advance tracing in the embedder.
141
+ *
142
+ * The embedder is expected to trace its heap starting from wrappers reported
143
+ * by RegisterV8References method, and report back all reachable wrappers.
144
+ * Furthermore, the embedder is expected to stop tracing by the given
145
+ * deadline. A deadline of infinity means that tracing should be finished.
146
+ *
147
+ * Returns |true| if tracing is done, and false otherwise.
148
+ */
149
+ virtual bool AdvanceTracing(double deadline_in_ms) = 0;
150
+
151
+ /*
152
+ * Returns true if there no more tracing work to be done (see AdvanceTracing)
153
+ * and false otherwise.
154
+ */
155
+ virtual bool IsTracingDone() = 0;
156
+
157
+ /**
158
+ * Called at the end of a GC cycle.
159
+ *
160
+ * Note that allocation is *not* allowed within |TraceEpilogue|. Can be
161
+ * overriden to fill a |TraceSummary| that is used by V8 to schedule future
162
+ * garbage collections.
163
+ */
164
+ virtual void TraceEpilogue(TraceSummary* trace_summary) {}
165
+
166
+ /**
167
+ * Called upon entering the final marking pause. No more incremental marking
168
+ * steps will follow this call.
169
+ */
170
+ virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
171
+
172
+ /*
173
+ * Called by the embedder to request immediate finalization of the currently
174
+ * running tracing phase that has been started with TracePrologue and not
175
+ * yet finished with TraceEpilogue.
176
+ *
177
+ * Will be a noop when currently not in tracing.
178
+ *
179
+ * This is an experimental feature.
180
+ */
181
+ void FinalizeTracing();
182
+
183
+ /**
184
+ * See documentation on EmbedderRootsHandler.
185
+ */
186
+ virtual bool IsRootForNonTracingGC(
187
+ const v8::TracedReference<v8::Value>& handle);
188
+
189
+ /**
190
+ * See documentation on EmbedderRootsHandler.
191
+ */
192
+ virtual void ResetHandleInNonTracingGC(
193
+ const v8::TracedReference<v8::Value>& handle);
194
+
195
+ /*
196
+ * Called by the embedder to signal newly allocated or freed memory. Not bound
197
+ * to tracing phases. Embedders should trade off when increments are reported
198
+ * as V8 may consult global heuristics on whether to trigger garbage
199
+ * collection on this change.
200
+ */
201
+ void IncreaseAllocatedSize(size_t bytes);
202
+ void DecreaseAllocatedSize(size_t bytes);
203
+
204
+ /*
205
+ * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
206
+ * is not attached to any v8::Isolate.
207
+ */
208
+ v8::Isolate* isolate() const { return isolate_; }
209
+
210
+ protected:
211
+ v8::Isolate* isolate_ = nullptr;
212
+
213
+ friend class internal::LocalEmbedderHeapTracer;
214
+ };
215
+
216
+ } // namespace v8
217
+
218
+ #endif // INCLUDE_V8_EMBEDDER_HEAP_H_
@@ -0,0 +1,51 @@
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_EMBEDDER_STATE_SCOPE_H_
6
+ #define INCLUDE_V8_EMBEDDER_STATE_SCOPE_H_
7
+
8
+ #include <memory>
9
+
10
+ #include "v8-context.h" // NOLINT(build/include_directory)
11
+ #include "v8-internal.h" // NOLINT(build/include_directory)
12
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
13
+
14
+ namespace v8 {
15
+
16
+ namespace internal {
17
+ class EmbedderState;
18
+ } // namespace internal
19
+
20
+ // A StateTag represents a possible state of the embedder.
21
+ enum class EmbedderStateTag : uint8_t {
22
+ // reserved
23
+ EMPTY = 0,
24
+ OTHER = 1,
25
+ // embedder can define any state after
26
+ };
27
+
28
+ // A stack-allocated class that manages an embedder state on the isolate.
29
+ // After an EmbedderState scope has been created, a new embedder state will be
30
+ // pushed on the isolate stack.
31
+ class V8_EXPORT EmbedderStateScope {
32
+ public:
33
+ EmbedderStateScope(Isolate* isolate, Local<v8::Context> context,
34
+ EmbedderStateTag tag);
35
+
36
+ ~EmbedderStateScope();
37
+
38
+ private:
39
+ // Declaring operator new and delete as deleted is not spec compliant.
40
+ // Therefore declare them private instead to disable dynamic alloc
41
+ void* operator new(size_t size);
42
+ void* operator new[](size_t size);
43
+ void operator delete(void*, size_t);
44
+ void operator delete[](void*, size_t);
45
+
46
+ std::unique_ptr<internal::EmbedderState> embedder_state_;
47
+ };
48
+
49
+ } // namespace v8
50
+
51
+ #endif // INCLUDE_V8_EMBEDDER_STATE_SCOPE_H_
@@ -0,0 +1,217 @@
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_EXCEPTION_H_
6
+ #define INCLUDE_V8_EXCEPTION_H_
7
+
8
+ #include <stddef.h>
9
+
10
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace v8 {
14
+
15
+ class Context;
16
+ class Isolate;
17
+ class Message;
18
+ class StackTrace;
19
+ class String;
20
+ class Value;
21
+
22
+ namespace internal {
23
+ class Isolate;
24
+ class ThreadLocalTop;
25
+ } // namespace internal
26
+
27
+ /**
28
+ * Create new error objects by calling the corresponding error object
29
+ * constructor with the message.
30
+ */
31
+ class V8_EXPORT Exception {
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);
41
+
42
+ /**
43
+ * Creates an error message for the given exception.
44
+ * Will try to reconstruct the original stack trace from the exception value,
45
+ * or capture the current stack trace if not available.
46
+ */
47
+ static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
48
+
49
+ /**
50
+ * Returns the original stack trace that was captured at the creation time
51
+ * of a given exception, or an empty handle if not available.
52
+ */
53
+ static Local<StackTrace> GetStackTrace(Local<Value> exception);
54
+ };
55
+
56
+ /**
57
+ * An external exception handler.
58
+ */
59
+ class V8_EXPORT TryCatch {
60
+ public:
61
+ /**
62
+ * Creates a new try/catch block and registers it with v8. Note that
63
+ * all TryCatch blocks should be stack allocated because the memory
64
+ * location itself is compared against JavaScript try/catch blocks.
65
+ */
66
+ explicit TryCatch(Isolate* isolate);
67
+
68
+ /**
69
+ * Unregisters and deletes this try/catch block.
70
+ */
71
+ ~TryCatch();
72
+
73
+ /**
74
+ * Returns true if an exception has been caught by this try/catch block.
75
+ */
76
+ bool HasCaught() const;
77
+
78
+ /**
79
+ * For certain types of exceptions, it makes no sense to continue execution.
80
+ *
81
+ * If CanContinue returns false, the correct action is to perform any C++
82
+ * cleanup needed and then return. If CanContinue returns false and
83
+ * HasTerminated returns true, it is possible to call
84
+ * CancelTerminateExecution in order to continue calling into the engine.
85
+ */
86
+ bool CanContinue() const;
87
+
88
+ /**
89
+ * Returns true if an exception has been caught due to script execution
90
+ * being terminated.
91
+ *
92
+ * There is no JavaScript representation of an execution termination
93
+ * exception. Such exceptions are thrown when the TerminateExecution
94
+ * methods are called to terminate a long-running script.
95
+ *
96
+ * If such an exception has been thrown, HasTerminated will return true,
97
+ * indicating that it is possible to call CancelTerminateExecution in order
98
+ * to continue calling into the engine.
99
+ */
100
+ bool HasTerminated() const;
101
+
102
+ /**
103
+ * Throws the exception caught by this TryCatch in a way that avoids
104
+ * it being caught again by this same TryCatch. As with ThrowException
105
+ * it is illegal to execute any JavaScript operations after calling
106
+ * ReThrow; the caller must return immediately to where the exception
107
+ * is caught.
108
+ */
109
+ Local<Value> ReThrow();
110
+
111
+ /**
112
+ * Returns the exception caught by this try/catch block. If no exception has
113
+ * been caught an empty handle is returned.
114
+ */
115
+ Local<Value> Exception() const;
116
+
117
+ /**
118
+ * Returns the .stack property of an object. If no .stack
119
+ * property is present an empty handle is returned.
120
+ */
121
+ V8_WARN_UNUSED_RESULT static MaybeLocal<Value> StackTrace(
122
+ Local<Context> context, Local<Value> exception);
123
+
124
+ /**
125
+ * Returns the .stack property of the thrown object. If no .stack property is
126
+ * present or if this try/catch block has not caught an exception, an empty
127
+ * handle is returned.
128
+ */
129
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
130
+ Local<Context> context) const;
131
+
132
+ /**
133
+ * Returns the message associated with this exception. If there is
134
+ * no message associated an empty handle is returned.
135
+ */
136
+ Local<v8::Message> Message() const;
137
+
138
+ /**
139
+ * Clears any exceptions that may have been caught by this try/catch block.
140
+ * After this method has been called, HasCaught() will return false. Cancels
141
+ * the scheduled exception if it is caught and ReThrow() is not called before.
142
+ *
143
+ * It is not necessary to clear a try/catch block before using it again; if
144
+ * another exception is thrown the previously caught exception will just be
145
+ * overwritten. However, it is often a good idea since it makes it easier
146
+ * to determine which operation threw a given exception.
147
+ */
148
+ void Reset();
149
+
150
+ /**
151
+ * Set verbosity of the external exception handler.
152
+ *
153
+ * By default, exceptions that are caught by an external exception
154
+ * handler are not reported. Call SetVerbose with true on an
155
+ * external exception handler to have exceptions caught by the
156
+ * handler reported as if they were not caught.
157
+ */
158
+ void SetVerbose(bool value);
159
+
160
+ /**
161
+ * Returns true if verbosity is enabled.
162
+ */
163
+ bool IsVerbose() const;
164
+
165
+ /**
166
+ * Set whether or not this TryCatch should capture a Message object
167
+ * which holds source information about where the exception
168
+ * occurred. True by default.
169
+ */
170
+ void SetCaptureMessage(bool value);
171
+
172
+ TryCatch(const TryCatch&) = delete;
173
+ void operator=(const TryCatch&) = delete;
174
+
175
+ private:
176
+ // Declaring operator new and delete as deleted is not spec compliant.
177
+ // Therefore declare them private instead to disable dynamic alloc
178
+ void* operator new(size_t size);
179
+ void* operator new[](size_t size);
180
+ void operator delete(void*, size_t);
181
+ void operator delete[](void*, size_t);
182
+
183
+ /**
184
+ * There are cases when the raw address of C++ TryCatch object cannot be
185
+ * used for comparisons with addresses into the JS stack. The cases are:
186
+ * 1) ARM, ARM64 and MIPS simulators which have separate JS stack.
187
+ * 2) Address sanitizer allocates local C++ object in the heap when
188
+ * UseAfterReturn mode is enabled.
189
+ * This method returns address that can be used for comparisons with
190
+ * addresses into the JS stack. When neither simulator nor ASAN's
191
+ * UseAfterReturn is enabled, then the address returned will be the address
192
+ * of the C++ try catch handler itself.
193
+ */
194
+ internal::Address JSStackComparableAddressPrivate() {
195
+ return js_stack_comparable_address_;
196
+ }
197
+
198
+ void ResetInternal();
199
+
200
+ internal::Isolate* isolate_;
201
+ TryCatch* next_;
202
+ void* exception_;
203
+ void* message_obj_;
204
+ internal::Address js_stack_comparable_address_;
205
+ bool is_verbose_ : 1;
206
+ bool can_continue_ : 1;
207
+ bool capture_message_ : 1;
208
+ bool rethrow_ : 1;
209
+ bool has_terminated_ : 1;
210
+
211
+ friend class internal::Isolate;
212
+ friend class internal::ThreadLocalTop;
213
+ };
214
+
215
+ } // namespace v8
216
+
217
+ #endif // INCLUDE_V8_EXCEPTION_H_