libv8-node 15.5.1.0.beta1-arm64-darwin-20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/ext/libv8-node/.location.yml +2 -0
  3. data/ext/libv8-node/location.rb +91 -0
  4. data/ext/libv8-node/paths.rb +30 -0
  5. data/lib/libv8-node.rb +1 -0
  6. data/lib/libv8/node.rb +11 -0
  7. data/lib/libv8/node/version.rb +7 -0
  8. data/vendor/v8/include/cppgc/allocation.h +173 -0
  9. data/vendor/v8/include/cppgc/common.h +26 -0
  10. data/vendor/v8/include/cppgc/custom-space.h +62 -0
  11. data/vendor/v8/include/cppgc/default-platform.h +76 -0
  12. data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
  13. data/vendor/v8/include/cppgc/heap.h +139 -0
  14. data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
  15. data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
  16. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +67 -0
  17. data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
  18. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  19. data/vendor/v8/include/cppgc/internal/gc-info.h +45 -0
  20. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  21. data/vendor/v8/include/cppgc/internal/persistent-node.h +116 -0
  22. data/vendor/v8/include/cppgc/internal/pointer-policies.h +134 -0
  23. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
  24. data/vendor/v8/include/cppgc/internal/process-heap.h +34 -0
  25. data/vendor/v8/include/cppgc/internal/write-barrier.h +78 -0
  26. data/vendor/v8/include/cppgc/liveness-broker.h +68 -0
  27. data/vendor/v8/include/cppgc/macros.h +24 -0
  28. data/vendor/v8/include/cppgc/member.h +226 -0
  29. data/vendor/v8/include/cppgc/persistent.h +341 -0
  30. data/vendor/v8/include/cppgc/platform.h +130 -0
  31. data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
  32. data/vendor/v8/include/cppgc/source-location.h +91 -0
  33. data/vendor/v8/include/cppgc/trace-trait.h +111 -0
  34. data/vendor/v8/include/cppgc/type-traits.h +109 -0
  35. data/vendor/v8/include/cppgc/visitor.h +213 -0
  36. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  37. data/vendor/v8/include/libplatform/libplatform.h +106 -0
  38. data/vendor/v8/include/libplatform/v8-tracing.h +332 -0
  39. data/vendor/v8/include/v8-cppgc.h +226 -0
  40. data/vendor/v8/include/v8-fast-api-calls.h +388 -0
  41. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  42. data/vendor/v8/include/v8-inspector.h +327 -0
  43. data/vendor/v8/include/v8-internal.h +427 -0
  44. data/vendor/v8/include/v8-metrics.h +133 -0
  45. data/vendor/v8/include/v8-platform.h +684 -0
  46. data/vendor/v8/include/v8-profiler.h +1059 -0
  47. data/vendor/v8/include/v8-util.h +652 -0
  48. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  49. data/vendor/v8/include/v8-version-string.h +38 -0
  50. data/vendor/v8/include/v8-version.h +20 -0
  51. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  52. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  53. data/vendor/v8/include/v8.h +12098 -0
  54. data/vendor/v8/include/v8config.h +484 -0
  55. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  56. metadata +112 -0
@@ -0,0 +1,13 @@
1
+ // Copyright 2016 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 V8_V8_INSPECTOR_PROTOCOL_H_
6
+ #define V8_V8_INSPECTOR_PROTOCOL_H_
7
+
8
+ #include "inspector/Debugger.h" // NOLINT(build/include_directory)
9
+ #include "inspector/Runtime.h" // NOLINT(build/include_directory)
10
+ #include "inspector/Schema.h" // NOLINT(build/include_directory)
11
+ #include "v8-inspector.h" // NOLINT(build/include_directory)
12
+
13
+ #endif // V8_V8_INSPECTOR_PROTOCOL_H_
@@ -0,0 +1,327 @@
1
+ // Copyright 2016 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 V8_V8_INSPECTOR_H_
6
+ #define V8_V8_INSPECTOR_H_
7
+
8
+ #include <stdint.h>
9
+ #include <cctype>
10
+
11
+ #include <memory>
12
+ #include <unordered_map>
13
+
14
+ #include "v8.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8_inspector {
17
+
18
+ namespace protocol {
19
+ namespace Debugger {
20
+ namespace API {
21
+ class SearchMatch;
22
+ }
23
+ }
24
+ namespace Runtime {
25
+ namespace API {
26
+ class RemoteObject;
27
+ class StackTrace;
28
+ class StackTraceId;
29
+ }
30
+ }
31
+ namespace Schema {
32
+ namespace API {
33
+ class Domain;
34
+ }
35
+ }
36
+ } // namespace protocol
37
+
38
+ class V8_EXPORT StringView {
39
+ public:
40
+ StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {}
41
+
42
+ StringView(const uint8_t* characters, size_t length)
43
+ : m_is8Bit(true), m_length(length), m_characters8(characters) {}
44
+
45
+ StringView(const uint16_t* characters, size_t length)
46
+ : m_is8Bit(false), m_length(length), m_characters16(characters) {}
47
+
48
+ bool is8Bit() const { return m_is8Bit; }
49
+ size_t length() const { return m_length; }
50
+
51
+ // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used
52
+ // here.
53
+ const uint8_t* characters8() const { return m_characters8; }
54
+ const uint16_t* characters16() const { return m_characters16; }
55
+
56
+ private:
57
+ bool m_is8Bit;
58
+ size_t m_length;
59
+ union {
60
+ const uint8_t* m_characters8;
61
+ const uint16_t* m_characters16;
62
+ };
63
+ };
64
+
65
+ class V8_EXPORT StringBuffer {
66
+ public:
67
+ virtual ~StringBuffer() = default;
68
+ virtual StringView string() const = 0;
69
+ // This method copies contents.
70
+ static std::unique_ptr<StringBuffer> create(StringView);
71
+ };
72
+
73
+ class V8_EXPORT V8ContextInfo {
74
+ public:
75
+ V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId,
76
+ StringView humanReadableName)
77
+ : context(context),
78
+ contextGroupId(contextGroupId),
79
+ humanReadableName(humanReadableName),
80
+ hasMemoryOnConsole(false) {}
81
+
82
+ v8::Local<v8::Context> context;
83
+ // Each v8::Context is a part of a group. The group id must be non-zero.
84
+ int contextGroupId;
85
+ StringView humanReadableName;
86
+ StringView origin;
87
+ StringView auxData;
88
+ bool hasMemoryOnConsole;
89
+
90
+ static int executionContextId(v8::Local<v8::Context> context);
91
+
92
+ // Disallow copying and allocating this one.
93
+ enum NotNullTagEnum { NotNullLiteral };
94
+ void* operator new(size_t) = delete;
95
+ void* operator new(size_t, NotNullTagEnum, void*) = delete;
96
+ void* operator new(size_t, void*) = delete;
97
+ V8ContextInfo(const V8ContextInfo&) = delete;
98
+ V8ContextInfo& operator=(const V8ContextInfo&) = delete;
99
+ };
100
+
101
+ class V8_EXPORT V8StackTrace {
102
+ public:
103
+ virtual StringView firstNonEmptySourceURL() const = 0;
104
+ virtual bool isEmpty() const = 0;
105
+ virtual StringView topSourceURL() const = 0;
106
+ virtual int topLineNumber() const = 0;
107
+ virtual int topColumnNumber() const = 0;
108
+ virtual StringView topScriptId() const = 0;
109
+ virtual StringView topFunctionName() const = 0;
110
+
111
+ virtual ~V8StackTrace() = default;
112
+ virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
113
+ buildInspectorObject() const = 0;
114
+ virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
115
+ buildInspectorObject(int maxAsyncDepth) const = 0;
116
+ virtual std::unique_ptr<StringBuffer> toString() const = 0;
117
+
118
+ // Safe to pass between threads, drops async chain.
119
+ virtual std::unique_ptr<V8StackTrace> clone() = 0;
120
+ };
121
+
122
+ class V8_EXPORT V8InspectorSession {
123
+ public:
124
+ virtual ~V8InspectorSession() = default;
125
+
126
+ // Cross-context inspectable values (DOM nodes in different worlds, etc.).
127
+ class V8_EXPORT Inspectable {
128
+ public:
129
+ virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0;
130
+ virtual ~Inspectable() = default;
131
+ };
132
+ virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;
133
+
134
+ // Dispatching protocol messages.
135
+ static bool canDispatchMethod(StringView method);
136
+ virtual void dispatchProtocolMessage(StringView message) = 0;
137
+ virtual std::vector<uint8_t> state() = 0;
138
+ virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
139
+ supportedDomains() = 0;
140
+
141
+ // Debugger actions.
142
+ virtual void schedulePauseOnNextStatement(StringView breakReason,
143
+ StringView breakDetails) = 0;
144
+ virtual void cancelPauseOnNextStatement() = 0;
145
+ virtual void breakProgram(StringView breakReason,
146
+ StringView breakDetails) = 0;
147
+ virtual void setSkipAllPauses(bool) = 0;
148
+ virtual void resume(bool setTerminateOnResume = false) = 0;
149
+ virtual void stepOver() = 0;
150
+ virtual std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
151
+ searchInTextByLines(StringView text, StringView query, bool caseSensitive,
152
+ bool isRegex) = 0;
153
+
154
+ // Remote objects.
155
+ virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
156
+ v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName,
157
+ bool generatePreview) = 0;
158
+
159
+ virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error,
160
+ StringView objectId, v8::Local<v8::Value>*,
161
+ v8::Local<v8::Context>*,
162
+ std::unique_ptr<StringBuffer>* objectGroup) = 0;
163
+ virtual void releaseObjectGroup(StringView) = 0;
164
+ virtual void triggerPreciseCoverageDeltaUpdate(StringView occassion) = 0;
165
+ };
166
+
167
+ class V8_EXPORT V8InspectorClient {
168
+ public:
169
+ virtual ~V8InspectorClient() = default;
170
+
171
+ virtual void runMessageLoopOnPause(int contextGroupId) {}
172
+ virtual void quitMessageLoopOnPause() {}
173
+ virtual void runIfWaitingForDebugger(int contextGroupId) {}
174
+
175
+ virtual void muteMetrics(int contextGroupId) {}
176
+ virtual void unmuteMetrics(int contextGroupId) {}
177
+
178
+ virtual void beginUserGesture() {}
179
+ virtual void endUserGesture() {}
180
+
181
+ virtual std::unique_ptr<StringBuffer> valueSubtype(v8::Local<v8::Value>) {
182
+ return nullptr;
183
+ }
184
+ virtual bool formatAccessorsAsProperties(v8::Local<v8::Value>) {
185
+ return false;
186
+ }
187
+ virtual bool isInspectableHeapObject(v8::Local<v8::Object>) { return true; }
188
+
189
+ virtual v8::Local<v8::Context> ensureDefaultContextInGroup(
190
+ int contextGroupId) {
191
+ return v8::Local<v8::Context>();
192
+ }
193
+ virtual void beginEnsureAllContextsInGroup(int contextGroupId) {}
194
+ virtual void endEnsureAllContextsInGroup(int contextGroupId) {}
195
+
196
+ virtual void installAdditionalCommandLineAPI(v8::Local<v8::Context>,
197
+ v8::Local<v8::Object>) {}
198
+ virtual void consoleAPIMessage(int contextGroupId,
199
+ v8::Isolate::MessageErrorLevel level,
200
+ const StringView& message,
201
+ const StringView& url, unsigned lineNumber,
202
+ unsigned columnNumber, V8StackTrace*) {}
203
+ virtual v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate*,
204
+ v8::Local<v8::Context>) {
205
+ return v8::MaybeLocal<v8::Value>();
206
+ }
207
+
208
+ virtual void consoleTime(const StringView& title) {}
209
+ virtual void consoleTimeEnd(const StringView& title) {}
210
+ virtual void consoleTimeStamp(const StringView& title) {}
211
+ virtual void consoleClear(int contextGroupId) {}
212
+ virtual double currentTimeMS() { return 0; }
213
+ typedef void (*TimerCallback)(void*);
214
+ virtual void startRepeatingTimer(double, TimerCallback, void* data) {}
215
+ virtual void cancelTimer(void* data) {}
216
+
217
+ // TODO(dgozman): this was added to support service worker shadow page. We
218
+ // should not connect at all.
219
+ virtual bool canExecuteScripts(int contextGroupId) { return true; }
220
+
221
+ virtual void maxAsyncCallStackDepthChanged(int depth) {}
222
+
223
+ virtual std::unique_ptr<StringBuffer> resourceNameToUrl(
224
+ const StringView& resourceName) {
225
+ return nullptr;
226
+ }
227
+ };
228
+
229
+ // These stack trace ids are intended to be passed between debuggers and be
230
+ // resolved later. This allows to track cross-debugger calls and step between
231
+ // them if a single client connects to multiple debuggers.
232
+ struct V8_EXPORT V8StackTraceId {
233
+ uintptr_t id;
234
+ std::pair<int64_t, int64_t> debugger_id;
235
+ bool should_pause = false;
236
+
237
+ V8StackTraceId();
238
+ V8StackTraceId(const V8StackTraceId&) = default;
239
+ V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id);
240
+ V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id,
241
+ bool should_pause);
242
+ explicit V8StackTraceId(StringView);
243
+ V8StackTraceId& operator=(const V8StackTraceId&) = default;
244
+ V8StackTraceId& operator=(V8StackTraceId&&) noexcept = default;
245
+ ~V8StackTraceId() = default;
246
+
247
+ bool IsInvalid() const;
248
+ std::unique_ptr<StringBuffer> ToString();
249
+ };
250
+
251
+ class V8_EXPORT V8Inspector {
252
+ public:
253
+ static std::unique_ptr<V8Inspector> create(v8::Isolate*, V8InspectorClient*);
254
+ virtual ~V8Inspector() = default;
255
+
256
+ // Contexts instrumentation.
257
+ virtual void contextCreated(const V8ContextInfo&) = 0;
258
+ virtual void contextDestroyed(v8::Local<v8::Context>) = 0;
259
+ virtual void resetContextGroup(int contextGroupId) = 0;
260
+ virtual v8::MaybeLocal<v8::Context> contextById(int contextId) = 0;
261
+
262
+ // Various instrumentation.
263
+ virtual void idleStarted() = 0;
264
+ virtual void idleFinished() = 0;
265
+
266
+ // Async stack traces instrumentation.
267
+ virtual void asyncTaskScheduled(StringView taskName, void* task,
268
+ bool recurring) = 0;
269
+ virtual void asyncTaskCanceled(void* task) = 0;
270
+ virtual void asyncTaskStarted(void* task) = 0;
271
+ virtual void asyncTaskFinished(void* task) = 0;
272
+ virtual void allAsyncTasksCanceled() = 0;
273
+
274
+ virtual V8StackTraceId storeCurrentStackTrace(StringView description) = 0;
275
+ virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0;
276
+ virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0;
277
+
278
+ // Exceptions instrumentation.
279
+ virtual unsigned exceptionThrown(v8::Local<v8::Context>, StringView message,
280
+ v8::Local<v8::Value> exception,
281
+ StringView detailedMessage, StringView url,
282
+ unsigned lineNumber, unsigned columnNumber,
283
+ std::unique_ptr<V8StackTrace>,
284
+ int scriptId) = 0;
285
+ virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
286
+ StringView message) = 0;
287
+
288
+ // Connection.
289
+ class V8_EXPORT Channel {
290
+ public:
291
+ virtual ~Channel() = default;
292
+ virtual void sendResponse(int callId,
293
+ std::unique_ptr<StringBuffer> message) = 0;
294
+ virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0;
295
+ virtual void flushProtocolNotifications() = 0;
296
+ };
297
+ virtual std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
298
+ Channel*,
299
+ StringView state) = 0;
300
+
301
+ // API methods.
302
+ virtual std::unique_ptr<V8StackTrace> createStackTrace(
303
+ v8::Local<v8::StackTrace>) = 0;
304
+ virtual std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) = 0;
305
+
306
+ // Performance counters.
307
+ class V8_EXPORT Counters : public std::enable_shared_from_this<Counters> {
308
+ public:
309
+ explicit Counters(v8::Isolate* isolate);
310
+ ~Counters();
311
+ const std::unordered_map<std::string, int>& getCountersMap() const {
312
+ return m_countersMap;
313
+ }
314
+
315
+ private:
316
+ static int* getCounterPtr(const char* name);
317
+
318
+ v8::Isolate* m_isolate;
319
+ std::unordered_map<std::string, int> m_countersMap;
320
+ };
321
+
322
+ virtual std::shared_ptr<Counters> enableCounters() = 0;
323
+ };
324
+
325
+ } // namespace v8_inspector
326
+
327
+ #endif // V8_V8_INSPECTOR_H_
@@ -0,0 +1,427 @@
1
+ // Copyright 2018 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_INTERNAL_H_
6
+ #define INCLUDE_V8_INTERNAL_H_
7
+
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+ #include <string.h>
11
+ #include <type_traits>
12
+
13
+ #include "v8-version.h" // NOLINT(build/include_directory)
14
+ #include "v8config.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8 {
17
+
18
+ class Context;
19
+ class Data;
20
+ class Isolate;
21
+
22
+ namespace internal {
23
+
24
+ class Isolate;
25
+
26
+ typedef uintptr_t Address;
27
+ static const Address kNullAddress = 0;
28
+
29
+ /**
30
+ * Configuration of tagging scheme.
31
+ */
32
+ const int kApiSystemPointerSize = sizeof(void*);
33
+ const int kApiDoubleSize = sizeof(double);
34
+ const int kApiInt32Size = sizeof(int32_t);
35
+ const int kApiInt64Size = sizeof(int64_t);
36
+
37
+ // Tag information for HeapObject.
38
+ const int kHeapObjectTag = 1;
39
+ const int kWeakHeapObjectTag = 3;
40
+ const int kHeapObjectTagSize = 2;
41
+ const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
42
+
43
+ // Tag information for Smi.
44
+ const int kSmiTag = 0;
45
+ const int kSmiTagSize = 1;
46
+ const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
47
+
48
+ template <size_t tagged_ptr_size>
49
+ struct SmiTagging;
50
+
51
+ constexpr intptr_t kIntptrAllBitsSet = intptr_t{-1};
52
+ constexpr uintptr_t kUintptrAllBitsSet =
53
+ static_cast<uintptr_t>(kIntptrAllBitsSet);
54
+
55
+ // Smi constants for systems where tagged pointer is a 32-bit value.
56
+ template <>
57
+ struct SmiTagging<4> {
58
+ enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
59
+
60
+ static constexpr intptr_t kSmiMinValue =
61
+ static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
62
+ static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
63
+
64
+ V8_INLINE static int SmiToInt(const internal::Address value) {
65
+ int shift_bits = kSmiTagSize + kSmiShiftSize;
66
+ // Truncate and shift down (requires >> to be sign extending).
67
+ return static_cast<int32_t>(static_cast<uint32_t>(value)) >> shift_bits;
68
+ }
69
+ V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
70
+ // Is value in range [kSmiMinValue, kSmiMaxValue].
71
+ // Use unsigned operations in order to avoid undefined behaviour in case of
72
+ // signed integer overflow.
73
+ return (static_cast<uintptr_t>(value) -
74
+ static_cast<uintptr_t>(kSmiMinValue)) <=
75
+ (static_cast<uintptr_t>(kSmiMaxValue) -
76
+ static_cast<uintptr_t>(kSmiMinValue));
77
+ }
78
+ };
79
+
80
+ // Smi constants for systems where tagged pointer is a 64-bit value.
81
+ template <>
82
+ struct SmiTagging<8> {
83
+ enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
84
+
85
+ static constexpr intptr_t kSmiMinValue =
86
+ static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
87
+ static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
88
+
89
+ V8_INLINE static int SmiToInt(const internal::Address value) {
90
+ int shift_bits = kSmiTagSize + kSmiShiftSize;
91
+ // Shift down and throw away top 32 bits.
92
+ return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits);
93
+ }
94
+ V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
95
+ // To be representable as a long smi, the value must be a 32-bit integer.
96
+ return (value == static_cast<int32_t>(value));
97
+ }
98
+ };
99
+
100
+ #ifdef V8_COMPRESS_POINTERS
101
+ static_assert(
102
+ kApiSystemPointerSize == kApiInt64Size,
103
+ "Pointer compression can be enabled only for 64-bit architectures");
104
+ const int kApiTaggedSize = kApiInt32Size;
105
+ #else
106
+ const int kApiTaggedSize = kApiSystemPointerSize;
107
+ #endif
108
+
109
+ constexpr bool PointerCompressionIsEnabled() {
110
+ return kApiTaggedSize != kApiSystemPointerSize;
111
+ }
112
+
113
+ constexpr bool HeapSandboxIsEnabled() {
114
+ #ifdef V8_HEAP_SANDBOX
115
+ return true;
116
+ #else
117
+ return false;
118
+ #endif
119
+ }
120
+
121
+ using ExternalPointer_t = Address;
122
+
123
+ #ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
124
+ using PlatformSmiTagging = SmiTagging<kApiInt32Size>;
125
+ #else
126
+ using PlatformSmiTagging = SmiTagging<kApiTaggedSize>;
127
+ #endif
128
+
129
+ // TODO(ishell): Consinder adding kSmiShiftBits = kSmiShiftSize + kSmiTagSize
130
+ // since it's used much more often than the inividual constants.
131
+ const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
132
+ const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
133
+ const int kSmiMinValue = static_cast<int>(PlatformSmiTagging::kSmiMinValue);
134
+ const int kSmiMaxValue = static_cast<int>(PlatformSmiTagging::kSmiMaxValue);
135
+ constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
136
+ constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
137
+
138
+ V8_INLINE static constexpr internal::Address IntToSmi(int value) {
139
+ return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) |
140
+ kSmiTag;
141
+ }
142
+
143
+ // {obj} must be the raw tagged pointer representation of a HeapObject
144
+ // that's guaranteed to never be in ReadOnlySpace.
145
+ V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj);
146
+
147
+ // Returns if we need to throw when an error occurs. This infers the language
148
+ // mode based on the current context and the closure. This returns true if the
149
+ // language mode is strict.
150
+ V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate);
151
+
152
+ /**
153
+ * This class exports constants and functionality from within v8 that
154
+ * is necessary to implement inline functions in the v8 api. Don't
155
+ * depend on functions and constants defined here.
156
+ */
157
+ class Internals {
158
+ public:
159
+ // These values match non-compiler-dependent values defined within
160
+ // the implementation of v8.
161
+ static const int kHeapObjectMapOffset = 0;
162
+ static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size;
163
+ static const int kStringResourceOffset =
164
+ 1 * kApiTaggedSize + 2 * kApiInt32Size;
165
+
166
+ static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize;
167
+ static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
168
+ static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
169
+ static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize;
170
+ static const int kEmbedderDataSlotSize = kApiSystemPointerSize;
171
+ static const int kNativeContextEmbedderDataOffset = 6 * kApiTaggedSize;
172
+ static const int kFullStringRepresentationMask = 0x0f;
173
+ static const int kStringEncodingMask = 0x8;
174
+ static const int kExternalTwoByteRepresentationTag = 0x02;
175
+ static const int kExternalOneByteRepresentationTag = 0x0a;
176
+
177
+ static const uint32_t kNumIsolateDataSlots = 4;
178
+
179
+ // IsolateData layout guarantees.
180
+ static const int kIsolateEmbedderDataOffset = 0;
181
+ static const int kIsolateFastCCallCallerFpOffset =
182
+ kNumIsolateDataSlots * kApiSystemPointerSize;
183
+ static const int kIsolateFastCCallCallerPcOffset =
184
+ kIsolateFastCCallCallerFpOffset + kApiSystemPointerSize;
185
+ static const int kIsolateStackGuardOffset =
186
+ kIsolateFastCCallCallerPcOffset + kApiSystemPointerSize;
187
+ static const int kIsolateRootsOffset =
188
+ kIsolateStackGuardOffset + 7 * kApiSystemPointerSize;
189
+
190
+ static const int kUndefinedValueRootIndex = 4;
191
+ static const int kTheHoleValueRootIndex = 5;
192
+ static const int kNullValueRootIndex = 6;
193
+ static const int kTrueValueRootIndex = 7;
194
+ static const int kFalseValueRootIndex = 8;
195
+ static const int kEmptyStringRootIndex = 9;
196
+
197
+ static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize;
198
+ static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3;
199
+ static const int kNodeStateMask = 0x7;
200
+ static const int kNodeStateIsWeakValue = 2;
201
+ static const int kNodeStateIsPendingValue = 3;
202
+
203
+ static const int kFirstNonstringType = 0x40;
204
+ static const int kOddballType = 0x43;
205
+ static const int kForeignType = 0x46;
206
+ static const int kJSSpecialApiObjectType = 0x410;
207
+ static const int kJSApiObjectType = 0x420;
208
+ static const int kJSObjectType = 0x421;
209
+
210
+ static const int kUndefinedOddballKind = 5;
211
+ static const int kNullOddballKind = 3;
212
+
213
+ // Constants used by PropertyCallbackInfo to check if we should throw when an
214
+ // error occurs.
215
+ static const int kThrowOnError = 0;
216
+ static const int kDontThrow = 1;
217
+ static const int kInferShouldThrowMode = 2;
218
+
219
+ // Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an
220
+ // incremental GC once the external memory reaches this limit.
221
+ static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024;
222
+
223
+ V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
224
+ V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
225
+ #ifdef V8_ENABLE_CHECKS
226
+ CheckInitializedImpl(isolate);
227
+ #endif
228
+ }
229
+
230
+ V8_INLINE static bool HasHeapObjectTag(const internal::Address value) {
231
+ return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
232
+ }
233
+
234
+ V8_INLINE static int SmiValue(const internal::Address value) {
235
+ return PlatformSmiTagging::SmiToInt(value);
236
+ }
237
+
238
+ V8_INLINE static constexpr internal::Address IntToSmi(int value) {
239
+ return internal::IntToSmi(value);
240
+ }
241
+
242
+ V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
243
+ return PlatformSmiTagging::IsValidSmi(value);
244
+ }
245
+
246
+ V8_INLINE static int GetInstanceType(const internal::Address obj) {
247
+ typedef internal::Address A;
248
+ A map = ReadTaggedPointerField(obj, kHeapObjectMapOffset);
249
+ return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset);
250
+ }
251
+
252
+ V8_INLINE static int GetOddballKind(const internal::Address obj) {
253
+ return SmiValue(ReadTaggedSignedField(obj, kOddballKindOffset));
254
+ }
255
+
256
+ V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
257
+ int representation = (instance_type & kFullStringRepresentationMask);
258
+ return representation == kExternalTwoByteRepresentationTag;
259
+ }
260
+
261
+ V8_INLINE static uint8_t GetNodeFlag(internal::Address* obj, int shift) {
262
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
263
+ return *addr & static_cast<uint8_t>(1U << shift);
264
+ }
265
+
266
+ V8_INLINE static void UpdateNodeFlag(internal::Address* obj, bool value,
267
+ int shift) {
268
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
269
+ uint8_t mask = static_cast<uint8_t>(1U << shift);
270
+ *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
271
+ }
272
+
273
+ V8_INLINE static uint8_t GetNodeState(internal::Address* obj) {
274
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
275
+ return *addr & kNodeStateMask;
276
+ }
277
+
278
+ V8_INLINE static void UpdateNodeState(internal::Address* obj, uint8_t value) {
279
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
280
+ *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
281
+ }
282
+
283
+ V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot,
284
+ void* data) {
285
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
286
+ kIsolateEmbedderDataOffset +
287
+ slot * kApiSystemPointerSize;
288
+ *reinterpret_cast<void**>(addr) = data;
289
+ }
290
+
291
+ V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
292
+ uint32_t slot) {
293
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
294
+ kIsolateEmbedderDataOffset +
295
+ slot * kApiSystemPointerSize;
296
+ return *reinterpret_cast<void* const*>(addr);
297
+ }
298
+
299
+ V8_INLINE static internal::Address* GetRoot(v8::Isolate* isolate, int index) {
300
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
301
+ kIsolateRootsOffset +
302
+ index * kApiSystemPointerSize;
303
+ return reinterpret_cast<internal::Address*>(addr);
304
+ }
305
+
306
+ template <typename T>
307
+ V8_INLINE static T ReadRawField(internal::Address heap_object_ptr,
308
+ int offset) {
309
+ internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
310
+ #ifdef V8_COMPRESS_POINTERS
311
+ if (sizeof(T) > kApiTaggedSize) {
312
+ // TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
313
+ // fields (external pointers, doubles and BigInt data) are only
314
+ // kTaggedSize aligned so we have to use unaligned pointer friendly way of
315
+ // accessing them in order to avoid undefined behavior in C++ code.
316
+ T r;
317
+ memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T));
318
+ return r;
319
+ }
320
+ #endif
321
+ return *reinterpret_cast<const T*>(addr);
322
+ }
323
+
324
+ V8_INLINE static internal::Address ReadTaggedPointerField(
325
+ internal::Address heap_object_ptr, int offset) {
326
+ #ifdef V8_COMPRESS_POINTERS
327
+ uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
328
+ internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
329
+ return root + static_cast<internal::Address>(static_cast<uintptr_t>(value));
330
+ #else
331
+ return ReadRawField<internal::Address>(heap_object_ptr, offset);
332
+ #endif
333
+ }
334
+
335
+ V8_INLINE static internal::Address ReadTaggedSignedField(
336
+ internal::Address heap_object_ptr, int offset) {
337
+ #ifdef V8_COMPRESS_POINTERS
338
+ uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
339
+ return static_cast<internal::Address>(static_cast<uintptr_t>(value));
340
+ #else
341
+ return ReadRawField<internal::Address>(heap_object_ptr, offset);
342
+ #endif
343
+ }
344
+
345
+ V8_INLINE static internal::Isolate* GetIsolateForHeapSandbox(
346
+ internal::Address obj) {
347
+ #ifdef V8_HEAP_SANDBOX
348
+ return internal::IsolateFromNeverReadOnlySpaceObject(obj);
349
+ #else
350
+ // Not used in non-sandbox mode.
351
+ return nullptr;
352
+ #endif
353
+ }
354
+
355
+ V8_INLINE static internal::Address ReadExternalPointerField(
356
+ internal::Isolate* isolate, internal::Address heap_object_ptr,
357
+ int offset) {
358
+ internal::Address value = ReadRawField<Address>(heap_object_ptr, offset);
359
+ #ifdef V8_HEAP_SANDBOX
360
+ // We currently have to treat zero as nullptr in embedder slots.
361
+ if (value) value = DecodeExternalPointer(isolate, value);
362
+ #endif
363
+ return value;
364
+ }
365
+
366
+ #ifdef V8_COMPRESS_POINTERS
367
+ // See v8:7703 or src/ptr-compr.* for details about pointer compression.
368
+ static constexpr size_t kPtrComprHeapReservationSize = size_t{1} << 32;
369
+ static constexpr size_t kPtrComprIsolateRootAlignment = size_t{1} << 32;
370
+
371
+ // See v8:10391 for details about V8 heap sandbox.
372
+ static constexpr uint32_t kExternalPointerSalt =
373
+ 0x7fffffff & ~static_cast<uint32_t>(kHeapObjectTagMask);
374
+
375
+ V8_INLINE static internal::Address GetRootFromOnHeapAddress(
376
+ internal::Address addr) {
377
+ return addr & -static_cast<intptr_t>(kPtrComprIsolateRootAlignment);
378
+ }
379
+
380
+ V8_INLINE static internal::Address DecompressTaggedAnyField(
381
+ internal::Address heap_object_ptr, uint32_t value) {
382
+ internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
383
+ return root + static_cast<internal::Address>(static_cast<uintptr_t>(value));
384
+ }
385
+
386
+ V8_INLINE static Address DecodeExternalPointer(
387
+ const Isolate* isolate, ExternalPointer_t encoded_pointer) {
388
+ #ifndef V8_HEAP_SANDBOX
389
+ return encoded_pointer;
390
+ #else
391
+ return encoded_pointer ^ kExternalPointerSalt;
392
+ #endif
393
+ }
394
+ #endif // V8_COMPRESS_POINTERS
395
+ };
396
+
397
+ // Only perform cast check for types derived from v8::Data since
398
+ // other types do not implement the Cast method.
399
+ template <bool PerformCheck>
400
+ struct CastCheck {
401
+ template <class T>
402
+ static void Perform(T* data);
403
+ };
404
+
405
+ template <>
406
+ template <class T>
407
+ void CastCheck<true>::Perform(T* data) {
408
+ T::Cast(data);
409
+ }
410
+
411
+ template <>
412
+ template <class T>
413
+ void CastCheck<false>::Perform(T* data) {}
414
+
415
+ template <class T>
416
+ V8_INLINE void PerformCastCheck(T* data) {
417
+ CastCheck<std::is_base_of<Data, T>::value>::Perform(data);
418
+ }
419
+
420
+ // A base class for backing stores, which is needed due to vagaries of
421
+ // how static casts work with std::shared_ptr.
422
+ class BackingStoreBase {};
423
+
424
+ } // namespace internal
425
+ } // namespace v8
426
+
427
+ #endif // INCLUDE_V8_INTERNAL_H_