libv8-node 16.20.0.0-aarch64-linux → 17.9.1.0-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/location.rb +1 -1
  3. data/ext/libv8-node/paths.rb +1 -1
  4. data/lib/libv8/node/version.rb +3 -3
  5. data/vendor/v8/aarch64-linux/libv8/obj/libv8_monolith.a +0 -0
  6. data/vendor/v8/include/cppgc/allocation.h +11 -5
  7. data/vendor/v8/include/cppgc/cross-thread-persistent.h +78 -26
  8. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +2 -2
  9. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +2 -0
  10. data/vendor/v8/include/cppgc/internal/gc-info.h +90 -10
  11. data/vendor/v8/include/cppgc/internal/name-trait.h +11 -0
  12. data/vendor/v8/include/cppgc/internal/persistent-node.h +44 -12
  13. data/vendor/v8/include/cppgc/internal/pointer-policies.h +22 -11
  14. data/vendor/v8/include/cppgc/internal/write-barrier.h +9 -1
  15. data/vendor/v8/include/cppgc/persistent.h +1 -1
  16. data/vendor/v8/include/cppgc/prefinalizer.h +1 -1
  17. data/vendor/v8/include/v8-array-buffer.h +433 -0
  18. data/vendor/v8/include/v8-callbacks.h +377 -0
  19. data/vendor/v8/include/v8-container.h +129 -0
  20. data/vendor/v8/include/v8-context.h +418 -0
  21. data/vendor/v8/include/v8-cppgc.h +5 -2
  22. data/vendor/v8/include/v8-data.h +65 -0
  23. data/vendor/v8/include/v8-date.h +43 -0
  24. data/vendor/v8/include/v8-debug.h +151 -0
  25. data/vendor/v8/include/v8-embedder-heap.h +238 -0
  26. data/vendor/v8/include/v8-exception.h +224 -0
  27. data/vendor/v8/include/v8-extension.h +62 -0
  28. data/vendor/v8/include/v8-external.h +37 -0
  29. data/vendor/v8/include/v8-fast-api-calls.h +63 -11
  30. data/vendor/v8/include/v8-forward.h +81 -0
  31. data/vendor/v8/include/v8-function-callback.h +475 -0
  32. data/vendor/v8/include/v8-function.h +122 -0
  33. data/vendor/v8/include/v8-initialization.h +282 -0
  34. data/vendor/v8/include/v8-inspector.h +11 -21
  35. data/vendor/v8/include/v8-internal.h +85 -22
  36. data/vendor/v8/include/v8-isolate.h +1662 -0
  37. data/vendor/v8/include/v8-json.h +47 -0
  38. data/vendor/v8/include/v8-local-handle.h +459 -0
  39. data/vendor/v8/include/v8-locker.h +148 -0
  40. data/vendor/v8/include/v8-maybe.h +137 -0
  41. data/vendor/v8/include/v8-memory-span.h +43 -0
  42. data/vendor/v8/include/v8-message.h +241 -0
  43. data/vendor/v8/include/v8-metrics.h +37 -1
  44. data/vendor/v8/include/v8-microtask-queue.h +152 -0
  45. data/vendor/v8/include/v8-microtask.h +28 -0
  46. data/vendor/v8/include/v8-object.h +770 -0
  47. data/vendor/v8/include/v8-persistent-handle.h +590 -0
  48. data/vendor/v8/include/v8-platform.h +41 -17
  49. data/vendor/v8/include/v8-primitive-object.h +118 -0
  50. data/vendor/v8/include/v8-primitive.h +858 -0
  51. data/vendor/v8/include/v8-profiler.h +10 -11
  52. data/vendor/v8/include/v8-promise.h +174 -0
  53. data/vendor/v8/include/v8-proxy.h +50 -0
  54. data/vendor/v8/include/v8-regexp.h +105 -0
  55. data/vendor/v8/include/v8-script.h +771 -0
  56. data/vendor/v8/include/v8-snapshot.h +198 -0
  57. data/vendor/v8/include/v8-statistics.h +215 -0
  58. data/vendor/v8/include/v8-template.h +1052 -0
  59. data/vendor/v8/include/v8-traced-handle.h +605 -0
  60. data/vendor/v8/include/v8-typed-array.h +282 -0
  61. data/vendor/v8/include/v8-unwinder-state.h +4 -3
  62. data/vendor/v8/include/v8-unwinder.h +129 -0
  63. data/vendor/v8/include/v8-util.h +7 -1
  64. data/vendor/v8/include/v8-value-serializer.h +249 -0
  65. data/vendor/v8/include/v8-value.h +526 -0
  66. data/vendor/v8/include/v8-version.h +3 -3
  67. data/vendor/v8/include/v8-wasm.h +245 -0
  68. data/vendor/v8/include/v8-weak-callback-info.h +73 -0
  69. data/vendor/v8/include/v8.h +41 -12604
  70. metadata +47 -5
@@ -0,0 +1,238 @@
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 TracedGlobal handle should be considered as root for
38
+ * the currently running non-tracing garbage collection and false otherwise.
39
+ * The default implementation will keep all TracedGlobal references as roots.
40
+ *
41
+ * If this returns false, then V8 may decide that the object referred to by
42
+ * such a handle is reclaimed. In that case:
43
+ * - No action is required if handles are used with destructors, i.e., by just
44
+ * using |TracedGlobal|.
45
+ * - When run without destructors, i.e., by using |TracedReference|, V8 calls
46
+ * |ResetRoot|.
47
+ *
48
+ * Note that the |handle| is different from the handle that the embedder holds
49
+ * for retaining the object. The embedder may use |WrapperClassId()| to
50
+ * distinguish cases where it wants handles to be treated as roots from not
51
+ * being treated as roots.
52
+ */
53
+ virtual bool IsRoot(const v8::TracedReference<v8::Value>& handle) = 0;
54
+ virtual bool IsRoot(const v8::TracedGlobal<v8::Value>& handle) = 0;
55
+
56
+ /**
57
+ * Used in combination with |IsRoot|. Called by V8 when an
58
+ * object that is backed by a handle is reclaimed by a non-tracing garbage
59
+ * collection. It is up to the embedder to reset the original handle.
60
+ *
61
+ * Note that the |handle| is different from the handle that the embedder holds
62
+ * for retaining the object. It is up to the embedder to find the original
63
+ * handle via the object or class id.
64
+ */
65
+ virtual void ResetRoot(const v8::TracedReference<v8::Value>& handle) = 0;
66
+ };
67
+
68
+ /**
69
+ * Interface for tracing through the embedder heap. During a V8 garbage
70
+ * collection, V8 collects hidden fields of all potential wrappers, and at the
71
+ * end of its marking phase iterates the collection and asks the embedder to
72
+ * trace through its heap and use reporter to report each JavaScript object
73
+ * reachable from any of the given wrappers.
74
+ */
75
+ class V8_EXPORT EmbedderHeapTracer {
76
+ public:
77
+ using EmbedderStackState = cppgc::EmbedderStackState;
78
+
79
+ enum TraceFlags : uint64_t {
80
+ kNoFlags = 0,
81
+ kReduceMemory = 1 << 0,
82
+ kForced = 1 << 2,
83
+ };
84
+
85
+ /**
86
+ * Interface for iterating through TracedGlobal handles.
87
+ */
88
+ class V8_EXPORT TracedGlobalHandleVisitor {
89
+ public:
90
+ virtual ~TracedGlobalHandleVisitor() = default;
91
+ virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& handle) {}
92
+ virtual void VisitTracedReference(const TracedReference<Value>& handle) {}
93
+ };
94
+
95
+ /**
96
+ * Summary of a garbage collection cycle. See |TraceEpilogue| on how the
97
+ * summary is reported.
98
+ */
99
+ struct TraceSummary {
100
+ /**
101
+ * Time spent managing the retained memory in milliseconds. This can e.g.
102
+ * include the time tracing through objects in the embedder.
103
+ */
104
+ double time = 0.0;
105
+
106
+ /**
107
+ * Memory retained by the embedder through the |EmbedderHeapTracer|
108
+ * mechanism in bytes.
109
+ */
110
+ size_t allocated_size = 0;
111
+ };
112
+
113
+ virtual ~EmbedderHeapTracer() = default;
114
+
115
+ /**
116
+ * Iterates all TracedGlobal handles created for the v8::Isolate the tracer is
117
+ * attached to.
118
+ */
119
+ void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor);
120
+
121
+ /**
122
+ * Called by the embedder to set the start of the stack which is e.g. used by
123
+ * V8 to determine whether handles are used from stack or heap.
124
+ */
125
+ void SetStackStart(void* stack_start);
126
+
127
+ /**
128
+ * Called by the embedder to notify V8 of an empty execution stack.
129
+ */
130
+ V8_DEPRECATE_SOON(
131
+ "This call only optimized internal caches which V8 is able to figure out "
132
+ "on its own now.")
133
+ void NotifyEmptyEmbedderStack();
134
+
135
+ /**
136
+ * Called by v8 to register internal fields of found wrappers.
137
+ *
138
+ * The embedder is expected to store them somewhere and trace reachable
139
+ * wrappers from them when called through |AdvanceTracing|.
140
+ */
141
+ virtual void RegisterV8References(
142
+ const std::vector<std::pair<void*, void*>>& embedder_fields) = 0;
143
+
144
+ void RegisterEmbedderReference(const BasicTracedReference<v8::Data>& ref);
145
+
146
+ /**
147
+ * Called at the beginning of a GC cycle.
148
+ */
149
+ virtual void TracePrologue(TraceFlags flags) {}
150
+
151
+ /**
152
+ * Called to advance tracing in the embedder.
153
+ *
154
+ * The embedder is expected to trace its heap starting from wrappers reported
155
+ * by RegisterV8References method, and report back all reachable wrappers.
156
+ * Furthermore, the embedder is expected to stop tracing by the given
157
+ * deadline. A deadline of infinity means that tracing should be finished.
158
+ *
159
+ * Returns |true| if tracing is done, and false otherwise.
160
+ */
161
+ virtual bool AdvanceTracing(double deadline_in_ms) = 0;
162
+
163
+ /*
164
+ * Returns true if there no more tracing work to be done (see AdvanceTracing)
165
+ * and false otherwise.
166
+ */
167
+ virtual bool IsTracingDone() = 0;
168
+
169
+ /**
170
+ * Called at the end of a GC cycle.
171
+ *
172
+ * Note that allocation is *not* allowed within |TraceEpilogue|. Can be
173
+ * overriden to fill a |TraceSummary| that is used by V8 to schedule future
174
+ * garbage collections.
175
+ */
176
+ virtual void TraceEpilogue(TraceSummary* trace_summary) {}
177
+
178
+ /**
179
+ * Called upon entering the final marking pause. No more incremental marking
180
+ * steps will follow this call.
181
+ */
182
+ virtual void EnterFinalPause(EmbedderStackState stack_state) = 0;
183
+
184
+ /*
185
+ * Called by the embedder to request immediate finalization of the currently
186
+ * running tracing phase that has been started with TracePrologue and not
187
+ * yet finished with TraceEpilogue.
188
+ *
189
+ * Will be a noop when currently not in tracing.
190
+ *
191
+ * This is an experimental feature.
192
+ */
193
+ void FinalizeTracing();
194
+
195
+ /**
196
+ * See documentation on EmbedderRootsHandler.
197
+ */
198
+ virtual bool IsRootForNonTracingGC(
199
+ const v8::TracedReference<v8::Value>& handle);
200
+ virtual bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>& handle);
201
+
202
+ /**
203
+ * See documentation on EmbedderRootsHandler.
204
+ */
205
+ virtual void ResetHandleInNonTracingGC(
206
+ const v8::TracedReference<v8::Value>& handle);
207
+
208
+ /*
209
+ * Called by the embedder to immediately perform a full garbage collection.
210
+ *
211
+ * Should only be used in testing code.
212
+ */
213
+ void GarbageCollectionForTesting(EmbedderStackState stack_state);
214
+
215
+ /*
216
+ * Called by the embedder to signal newly allocated or freed memory. Not bound
217
+ * to tracing phases. Embedders should trade off when increments are reported
218
+ * as V8 may consult global heuristics on whether to trigger garbage
219
+ * collection on this change.
220
+ */
221
+ void IncreaseAllocatedSize(size_t bytes);
222
+ void DecreaseAllocatedSize(size_t bytes);
223
+
224
+ /*
225
+ * Returns the v8::Isolate this tracer is attached too and |nullptr| if it
226
+ * is not attached to any v8::Isolate.
227
+ */
228
+ v8::Isolate* isolate() const { return isolate_; }
229
+
230
+ protected:
231
+ v8::Isolate* isolate_ = nullptr;
232
+
233
+ friend class internal::LocalEmbedderHeapTracer;
234
+ };
235
+
236
+ } // namespace v8
237
+
238
+ #endif // INCLUDE_V8_EMBEDDER_HEAP_H_
@@ -0,0 +1,224 @@
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
+ V8_DEPRECATE_SOON(
173
+ "This is private information that should not be exposed by the API")
174
+ static void* JSStackComparableAddress(TryCatch* handler) {
175
+ if (handler == nullptr) return nullptr;
176
+ return reinterpret_cast<void*>(handler->JSStackComparableAddressPrivate());
177
+ }
178
+
179
+ TryCatch(const TryCatch&) = delete;
180
+ void operator=(const TryCatch&) = delete;
181
+
182
+ private:
183
+ // Declaring operator new and delete as deleted is not spec compliant.
184
+ // Therefore declare them private instead to disable dynamic alloc
185
+ void* operator new(size_t size);
186
+ void* operator new[](size_t size);
187
+ void operator delete(void*, size_t);
188
+ void operator delete[](void*, size_t);
189
+
190
+ /**
191
+ * There are cases when the raw address of C++ TryCatch object cannot be
192
+ * used for comparisons with addresses into the JS stack. The cases are:
193
+ * 1) ARM, ARM64 and MIPS simulators which have separate JS stack.
194
+ * 2) Address sanitizer allocates local C++ object in the heap when
195
+ * UseAfterReturn mode is enabled.
196
+ * This method returns address that can be used for comparisons with
197
+ * addresses into the JS stack. When neither simulator nor ASAN's
198
+ * UseAfterReturn is enabled, then the address returned will be the address
199
+ * of the C++ try catch handler itself.
200
+ */
201
+ internal::Address JSStackComparableAddressPrivate() {
202
+ return js_stack_comparable_address_;
203
+ }
204
+
205
+ void ResetInternal();
206
+
207
+ internal::Isolate* isolate_;
208
+ TryCatch* next_;
209
+ void* exception_;
210
+ void* message_obj_;
211
+ internal::Address js_stack_comparable_address_;
212
+ bool is_verbose_ : 1;
213
+ bool can_continue_ : 1;
214
+ bool capture_message_ : 1;
215
+ bool rethrow_ : 1;
216
+ bool has_terminated_ : 1;
217
+
218
+ friend class internal::Isolate;
219
+ friend class internal::ThreadLocalTop;
220
+ };
221
+
222
+ } // namespace v8
223
+
224
+ #endif // INCLUDE_V8_EXCEPTION_H_
@@ -0,0 +1,62 @@
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_EXTENSION_H_
6
+ #define INCLUDE_V8_EXTENSION_H_
7
+
8
+ #include <memory>
9
+
10
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
11
+ #include "v8-primitive.h" // NOLINT(build/include_directory)
12
+ #include "v8config.h" // NOLINT(build/include_directory)
13
+
14
+ namespace v8 {
15
+
16
+ class FunctionTemplate;
17
+
18
+ // --- Extensions ---
19
+
20
+ /**
21
+ * Ignore
22
+ */
23
+ class V8_EXPORT Extension {
24
+ public:
25
+ // Note that the strings passed into this constructor must live as long
26
+ // as the Extension itself.
27
+ Extension(const char* name, const char* source = nullptr, int dep_count = 0,
28
+ const char** deps = nullptr, int source_length = -1);
29
+ virtual ~Extension() { delete source_; }
30
+ virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
31
+ Isolate* isolate, Local<String> name) {
32
+ return Local<FunctionTemplate>();
33
+ }
34
+
35
+ const char* name() const { return name_; }
36
+ size_t source_length() const { return source_length_; }
37
+ const String::ExternalOneByteStringResource* source() const {
38
+ return source_;
39
+ }
40
+ int dependency_count() const { return dep_count_; }
41
+ const char** dependencies() const { return deps_; }
42
+ void set_auto_enable(bool value) { auto_enable_ = value; }
43
+ bool auto_enable() { return auto_enable_; }
44
+
45
+ // Disallow copying and assigning.
46
+ Extension(const Extension&) = delete;
47
+ void operator=(const Extension&) = delete;
48
+
49
+ private:
50
+ const char* name_;
51
+ size_t source_length_; // expected to initialize before source_
52
+ String::ExternalOneByteStringResource* source_;
53
+ int dep_count_;
54
+ const char** deps_;
55
+ bool auto_enable_;
56
+ };
57
+
58
+ void V8_EXPORT RegisterExtension(std::unique_ptr<Extension>);
59
+
60
+ } // namespace v8
61
+
62
+ #endif // INCLUDE_V8_EXTENSION_H_
@@ -0,0 +1,37 @@
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_EXTERNAL_H_
6
+ #define INCLUDE_V8_EXTERNAL_H_
7
+
8
+ #include "v8-value.h" // NOLINT(build/include_directory)
9
+ #include "v8config.h" // NOLINT(build/include_directory)
10
+
11
+ namespace v8 {
12
+
13
+ class Isolate;
14
+
15
+ /**
16
+ * A JavaScript value that wraps a C++ void*. This type of value is mainly used
17
+ * to associate C++ data structures with JavaScript objects.
18
+ */
19
+ class V8_EXPORT External : public Value {
20
+ public:
21
+ static Local<External> New(Isolate* isolate, void* value);
22
+ V8_INLINE static External* Cast(Value* value) {
23
+ #ifdef V8_ENABLE_CHECKS
24
+ CheckCast(value);
25
+ #endif
26
+ return static_cast<External*>(value);
27
+ }
28
+
29
+ void* Value() const;
30
+
31
+ private:
32
+ static void CheckCast(v8::Value* obj);
33
+ };
34
+
35
+ } // namespace v8
36
+
37
+ #endif // INCLUDE_V8_EXTERNAL_H_
@@ -225,9 +225,11 @@
225
225
  #include <tuple>
226
226
  #include <type_traits>
227
227
 
228
- #include "v8-internal.h" // NOLINT(build/include_directory)
229
- #include "v8.h" // NOLINT(build/include_directory)
230
- #include "v8config.h" // NOLINT(build/include_directory)
228
+ #include "v8-internal.h" // NOLINT(build/include_directory)
229
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
230
+ #include "v8-typed-array.h" // NOLINT(build/include_directory)
231
+ #include "v8-value.h" // NOLINT(build/include_directory)
232
+ #include "v8config.h" // NOLINT(build/include_directory)
231
233
 
232
234
  namespace v8 {
233
235
 
@@ -275,6 +277,17 @@ class CTypeInfo {
275
277
  Flags flags = Flags::kNone)
276
278
  : type_(type), sequence_type_(sequence_type), flags_(flags) {}
277
279
 
280
+ typedef uint32_t Identifier;
281
+ explicit constexpr CTypeInfo(Identifier identifier)
282
+ : CTypeInfo(static_cast<Type>(identifier >> 16),
283
+ static_cast<SequenceType>((identifier >> 8) & 255),
284
+ static_cast<Flags>(identifier & 255)) {}
285
+ constexpr Identifier GetId() const {
286
+ return static_cast<uint8_t>(type_) << 16 |
287
+ static_cast<uint8_t>(sequence_type_) << 8 |
288
+ static_cast<uint8_t>(flags_);
289
+ }
290
+
278
291
  constexpr Type GetType() const { return type_; }
279
292
  constexpr SequenceType GetSequenceType() const { return sequence_type_; }
280
293
  constexpr Flags GetFlags() const { return flags_; }
@@ -322,6 +335,14 @@ struct FastApiTypedArray : public FastApiTypedArrayBase {
322
335
  return tmp;
323
336
  }
324
337
 
338
+ bool getStorageIfAligned(T** elements) const {
339
+ if (reinterpret_cast<uintptr_t>(data_) % alignof(T) != 0) {
340
+ return false;
341
+ }
342
+ *elements = reinterpret_cast<T*>(data_);
343
+ return true;
344
+ }
345
+
325
346
  private:
326
347
  // This pointer should include the typed array offset applied.
327
348
  // It's not guaranteed that it's aligned to sizeof(T), it's only
@@ -814,23 +835,54 @@ static constexpr CTypeInfo kTypeInfoFloat64 =
814
835
  * returns true on success. `type_info` will be used for conversions.
815
836
  */
816
837
  template <const CTypeInfo* type_info, typename T>
817
- bool V8_EXPORT V8_WARN_UNUSED_RESULT TryCopyAndConvertArrayToCppBuffer(
818
- Local<Array> src, T* dst, uint32_t max_length);
838
+ V8_DEPRECATE_SOON(
839
+ "Use TryToCopyAndConvertArrayToCppBuffer<CTypeInfo::Identifier, T>()")
840
+ bool V8_EXPORT V8_WARN_UNUSED_RESULT
841
+ TryCopyAndConvertArrayToCppBuffer(Local<Array> src, T* dst,
842
+ uint32_t max_length);
819
843
 
820
844
  template <>
845
+ V8_DEPRECATE_SOON(
846
+ "Use TryToCopyAndConvertArrayToCppBuffer<CTypeInfo::Identifier, T>()")
821
847
  inline bool V8_WARN_UNUSED_RESULT
822
- TryCopyAndConvertArrayToCppBuffer<&kTypeInfoInt32, int32_t>(
823
- Local<Array> src, int32_t* dst, uint32_t max_length) {
824
- return CopyAndConvertArrayToCppBufferInt32(src, dst, max_length);
848
+ TryCopyAndConvertArrayToCppBuffer<&kTypeInfoInt32, int32_t>(
849
+ Local<Array> src, int32_t* dst, uint32_t max_length) {
850
+ return false;
825
851
  }
826
852
 
827
853
  template <>
854
+ V8_DEPRECATE_SOON(
855
+ "Use TryToCopyAndConvertArrayToCppBuffer<CTypeInfo::Identifier, T>()")
828
856
  inline bool V8_WARN_UNUSED_RESULT
829
- TryCopyAndConvertArrayToCppBuffer<&kTypeInfoFloat64, double>(
830
- Local<Array> src, double* dst, uint32_t max_length) {
831
- return CopyAndConvertArrayToCppBufferFloat64(src, dst, max_length);
857
+ TryCopyAndConvertArrayToCppBuffer<&kTypeInfoFloat64, double>(
858
+ Local<Array> src, double* dst, uint32_t max_length) {
859
+ return false;
832
860
  }
833
861
 
862
+ template <CTypeInfo::Identifier type_info_id, typename T>
863
+ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer(
864
+ Local<Array> src, T* dst, uint32_t max_length);
865
+
866
+ template <>
867
+ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
868
+ internal::CTypeInfoBuilder<int32_t>::Build().GetId(), int32_t>(
869
+ Local<Array> src, int32_t* dst, uint32_t max_length);
870
+
871
+ template <>
872
+ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
873
+ internal::CTypeInfoBuilder<uint32_t>::Build().GetId(), uint32_t>(
874
+ Local<Array> src, uint32_t* dst, uint32_t max_length);
875
+
876
+ template <>
877
+ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
878
+ internal::CTypeInfoBuilder<float>::Build().GetId(), float>(
879
+ Local<Array> src, float* dst, uint32_t max_length);
880
+
881
+ template <>
882
+ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
883
+ internal::CTypeInfoBuilder<double>::Build().GetId(), double>(
884
+ Local<Array> src, double* dst, uint32_t max_length);
885
+
834
886
  } // namespace v8
835
887
 
836
888
  #endif // INCLUDE_V8_FAST_API_CALLS_H_