82 | union helper {
83 | static_assert(std::is_trivial::value && std::is_standard_layout
::value, "type P must a pod type");
84 | static_assert(sizeof(V) == sizeof(P), "type P must be same size as type V");
85 | static_assert(alignof(V) == alignof(P), "alignment of type P must be compatible with that of type V");
86 |
87 | inline helper(V&& value) : value_(std::move(value)) {}
88 | inline helper(const V& value) : value_(value) {}
89 | inline ~helper() {}
90 |
91 | inline operator P() {
92 | // Do a memcpy here avoid undefined behavior.
93 | P result;
94 | memcpy(&result, this, sizeof result);
95 | return result;
96 | }
97 |
98 | private:
99 | V value_;
100 | };
101 | };
102 |
103 | extern "C" {
104 |
105 | // Platform
106 |
107 | v8::Platform* v8__Platform__NewDefaultPlatform(
108 | int thread_pool_size,
109 | bool idle_task_support) {
110 | return v8::platform::NewDefaultPlatform(
111 | thread_pool_size,
112 | idle_task_support ? v8::platform::IdleTaskSupport::kEnabled : v8::platform::IdleTaskSupport::kDisabled,
113 | v8::platform::InProcessStackDumping::kDisabled,
114 | nullptr
115 | ).release();
116 | }
117 |
118 | void v8__Platform__DELETE(v8::Platform* self) { delete self; }
119 |
120 | bool v8__Platform__PumpMessageLoop(
121 | v8::Platform* platform,
122 | v8::Isolate* isolate,
123 | bool wait_for_work) {
124 | return v8::platform::PumpMessageLoop(
125 | platform, isolate,
126 | wait_for_work ? v8::platform::MessageLoopBehavior::kWaitForWork : v8::platform::MessageLoopBehavior::kDoNotWait);
127 | }
128 |
129 | void v8__Platform__RunIdleTasks(
130 | v8::Platform* platform,
131 | v8::Isolate* isolate,
132 | double idle_time_in_seconds) {
133 | v8::platform::RunIdleTasks(platform, isolate, idle_time_in_seconds);
134 | }
135 |
136 | // Root
137 |
138 | const v8::Primitive* v8__Undefined(v8::Isolate* isolate) {
139 | return local_to_ptr(v8::Undefined(isolate));
140 | }
141 |
142 | const v8::Primitive* v8__Null(v8::Isolate* isolate) {
143 | return local_to_ptr(v8::Null(isolate));
144 | }
145 |
146 | const v8::Boolean* v8__True(v8::Isolate* isolate) {
147 | return local_to_ptr(v8::True(isolate));
148 | }
149 |
150 | const v8::Boolean* v8__False(v8::Isolate* isolate) {
151 | return local_to_ptr(v8::False(isolate));
152 | }
153 |
154 | const v8::Uint8ClampedArray* v8__Uint8ClampedArray__New(
155 | const v8::ArrayBuffer& buf,
156 | size_t byte_offset,
157 | size_t length) {
158 | return local_to_ptr(
159 | v8::Uint8ClampedArray::New(ptr_to_local(&buf), byte_offset, length)
160 | );
161 | }
162 |
163 | const v8::Uint8Array* v8__Uint8Array__New(
164 | const v8::ArrayBuffer& buf,
165 | size_t byte_offset,
166 | size_t length) {
167 | return local_to_ptr(
168 | v8::Uint8Array::New(ptr_to_local(&buf), byte_offset, length)
169 | );
170 | }
171 |
172 | const v8::Int8Array* v8__Int8Array__New(
173 | const v8::ArrayBuffer& buf,
174 | size_t byte_offset,
175 | size_t length) {
176 | return local_to_ptr(
177 | v8::Int8Array::New(ptr_to_local(&buf), byte_offset, length)
178 | );
179 | }
180 |
181 | const v8::Uint16Array* v8__Uint16Array__New(
182 | const v8::ArrayBuffer& buf,
183 | size_t byte_offset,
184 | size_t length) {
185 | return local_to_ptr(
186 | v8::Uint16Array::New(ptr_to_local(&buf), byte_offset, length)
187 | );
188 | }
189 |
190 | const v8::Int16Array* v8__Int16Array__New(
191 | const v8::ArrayBuffer& buf,
192 | size_t byte_offset,
193 | size_t length) {
194 | return local_to_ptr(
195 | v8::Int16Array::New(ptr_to_local(&buf), byte_offset, length)
196 | );
197 | }
198 |
199 | const v8::Uint32Array* v8__Uint32Array__New(
200 | const v8::ArrayBuffer& buf,
201 | size_t byte_offset,
202 | size_t length) {
203 | return local_to_ptr(
204 | v8::Uint32Array::New(ptr_to_local(&buf), byte_offset, length)
205 | );
206 | }
207 |
208 | const v8::Int32Array* v8__Int32Array__New(
209 | const v8::ArrayBuffer& buf,
210 | size_t byte_offset,
211 | size_t length) {
212 | return local_to_ptr(
213 | v8::Int32Array::New(ptr_to_local(&buf), byte_offset, length)
214 | );
215 | }
216 |
217 | const v8::Float16Array* v8__Float16Array__New(
218 | const v8::ArrayBuffer& buf,
219 | size_t byte_offset,
220 | size_t length) {
221 | return local_to_ptr(
222 | v8::Float16Array::New(ptr_to_local(&buf), byte_offset, length)
223 | );
224 | }
225 |
226 | const v8::Float32Array* v8__Float32Array__New(
227 | const v8::ArrayBuffer& buf,
228 | size_t byte_offset,
229 | size_t length) {
230 | return local_to_ptr(
231 | v8::Float32Array::New(ptr_to_local(&buf), byte_offset, length)
232 | );
233 | }
234 |
235 | const v8::Float64Array* v8__Float64Array__New(
236 | const v8::ArrayBuffer& buf,
237 | size_t byte_offset,
238 | size_t length) {
239 | return local_to_ptr(
240 | v8::Float64Array::New(ptr_to_local(&buf), byte_offset, length)
241 | );
242 | }
243 |
244 | const v8::BigUint64Array* v8__BigUint64Array__New(
245 | const v8::ArrayBuffer& buf,
246 | size_t byte_offset,
247 | size_t length) {
248 | return local_to_ptr(
249 | v8::BigUint64Array::New(ptr_to_local(&buf), byte_offset, length)
250 | );
251 | }
252 |
253 | const v8::BigInt64Array* v8__BigInt64Array__New(
254 | const v8::ArrayBuffer& buf,
255 | size_t byte_offset,
256 | size_t length) {
257 | return local_to_ptr(
258 | v8::BigInt64Array::New(ptr_to_local(&buf), byte_offset, length)
259 | );
260 | }
261 | // V8
262 |
263 | const char* v8__V8__GetVersion() { return v8::V8::GetVersion(); }
264 |
265 | void v8__V8__InitializePlatform(v8::Platform* platform) {
266 | v8::V8::InitializePlatform(platform);
267 | }
268 |
269 | void v8__V8__Initialize() { v8::V8::Initialize(); }
270 |
271 | bool v8__V8__InitializeICU() { return v8::V8::InitializeICU(); }
272 |
273 | int v8__V8__Dispose() { return v8::V8::Dispose(); }
274 |
275 | void v8__V8__DisposePlatform() { v8::V8::DisposePlatform(); }
276 |
277 | // Isolate
278 |
279 | v8::Isolate* v8__Isolate__New(const v8::Isolate::CreateParams& params) {
280 | return v8::Isolate::New(params);
281 | }
282 |
283 | void v8__Isolate__Dispose(v8::Isolate* isolate) { isolate->Dispose(); }
284 |
285 | void v8__Isolate__Enter(v8::Isolate* isolate) { isolate->Enter(); }
286 |
287 | void v8__Isolate__Exit(v8::Isolate* isolate) { isolate->Exit(); }
288 |
289 | const v8::Context* v8__Isolate__GetCurrentContext(v8::Isolate* isolate) {
290 | return local_to_ptr(isolate->GetCurrentContext());
291 | }
292 |
293 | size_t v8__Isolate__CreateParams__SIZEOF() {
294 | return sizeof(v8::Isolate::CreateParams);
295 | }
296 |
297 | void v8__Isolate__CreateParams__CONSTRUCT(v8::Isolate::CreateParams* buf) {
298 | // Use in place new constructor otherwise special fields like shared_ptr will attempt to do copy and fail if the buffer had undefined values.
299 | new (buf) v8::Isolate::CreateParams();
300 | }
301 |
302 | const v8::Value* v8__Isolate__ThrowException(
303 | v8::Isolate* isolate,
304 | const v8::Value& exception) {
305 | return local_to_ptr(isolate->ThrowException(ptr_to_local(&exception)));
306 | }
307 |
308 | void v8__Isolate__SetHostImportModuleDynamicallyCallback(
309 | v8::Isolate* isolate,
310 | v8::HostImportModuleDynamicallyCallback callback) {
311 | isolate->SetHostImportModuleDynamicallyCallback(callback);
312 | }
313 |
314 | void v8__Isolate__SetHostInitializeImportMetaObjectCallback(
315 | v8::Isolate* isolate,
316 | v8::HostInitializeImportMetaObjectCallback callback) {
317 | isolate->SetHostInitializeImportMetaObjectCallback(callback);
318 | }
319 |
320 | void v8__Isolate__SetPromiseRejectCallback(
321 | v8::Isolate* isolate,
322 | v8::PromiseRejectCallback callback) {
323 | isolate->SetPromiseRejectCallback(callback);
324 | }
325 |
326 | v8::MicrotasksPolicy v8__Isolate__GetMicrotasksPolicy(const v8::Isolate* self) {
327 | return self->GetMicrotasksPolicy();
328 | }
329 |
330 | void v8__Isolate__SetMicrotasksPolicy(
331 | v8::Isolate* self,
332 | v8::MicrotasksPolicy policy) {
333 | self->SetMicrotasksPolicy(policy);
334 | }
335 |
336 | void v8__Isolate__PerformMicrotaskCheckpoint(v8::Isolate* self) {
337 | self->PerformMicrotaskCheckpoint();
338 | }
339 |
340 | bool v8__Isolate__AddMessageListener(
341 | v8::Isolate* self,
342 | v8::MessageCallback callback) {
343 | return self->AddMessageListener(callback);
344 | }
345 |
346 | bool v8__Isolate__AddMessageListenerWithErrorLevel(
347 | v8::Isolate* self,
348 | v8::MessageCallback callback,
349 | int message_levels,
350 | const v8::Value& data) {
351 | return self->AddMessageListenerWithErrorLevel(callback, message_levels, ptr_to_local(&data));
352 | }
353 |
354 | void v8__Isolate__SetCaptureStackTraceForUncaughtExceptions(
355 | v8::Isolate* isolate,
356 | bool capture,
357 | int frame_limit) {
358 | isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit);
359 | }
360 |
361 | void v8__Isolate__TerminateExecution(v8::Isolate* self) {
362 | self->TerminateExecution();
363 | }
364 |
365 | bool v8__Isolate__IsExecutionTerminating(v8::Isolate* self) {
366 | return self->IsExecutionTerminating();
367 | }
368 |
369 | void v8__Isolate__CancelTerminateExecution(v8::Isolate* self) {
370 | self->CancelTerminateExecution();
371 | }
372 |
373 | void v8__Isolate__LowMemoryNotification(v8::Isolate* self) {
374 | self->LowMemoryNotification();
375 | }
376 |
377 | void v8__Isolate__GetHeapStatistics(
378 | v8::Isolate* self,
379 | v8::HeapStatistics* stats) {
380 | self->GetHeapStatistics(stats);
381 | }
382 |
383 | void* v8__Isolate__GetData(v8::Isolate* self, int idx) {
384 | return self->GetData(idx);
385 | }
386 |
387 | void v8__Isolate__SetData(v8::Isolate* self, int idx, void* val) {
388 | self->SetData(idx, val);
389 | }
390 |
391 | void v8__Isolate__EnqueueMicrotask(v8::Isolate* self, v8::MicrotaskCallback callback, void* data) {
392 | self->EnqueueMicrotask(callback, data);
393 | }
394 |
395 | void v8__Isolate__EnqueueMicrotaskFunc(v8::Isolate* self, const v8::Function* function) {
396 | self->EnqueueMicrotask(ptr_to_local(function));
397 | }
398 |
399 | size_t v8__HeapStatistics__SIZEOF() {
400 | return sizeof(v8::HeapStatistics);
401 | }
402 |
403 | // ArrayBuffer
404 |
405 | v8::ArrayBuffer::Allocator* v8__ArrayBuffer__Allocator__NewDefaultAllocator() {
406 | return v8::ArrayBuffer::Allocator::NewDefaultAllocator();
407 | }
408 |
409 | void v8__ArrayBuffer__Allocator__DELETE(v8::ArrayBuffer::Allocator* self) { delete self; }
410 |
411 | v8::BackingStore* v8__ArrayBuffer__NewBackingStore(
412 | v8::Isolate* isolate,
413 | size_t byte_len) {
414 | std::unique_ptr store = v8::ArrayBuffer::NewBackingStore(isolate, byte_len);
415 | return store.release();
416 | }
417 |
418 | v8::BackingStore* v8__ArrayBuffer__NewBackingStore2(
419 | void* data,
420 | size_t byte_len,
421 | v8::BackingStoreDeleterCallback deleter,
422 | void* deleter_data) {
423 | std::unique_ptr store = v8::ArrayBuffer::NewBackingStore(data, byte_len, deleter, deleter_data);
424 | return store.release();
425 | }
426 |
427 | void* v8__BackingStore__Data(const v8::BackingStore& self) { return self.Data(); }
428 |
429 | size_t v8__BackingStore__ByteLength(const v8::BackingStore& self) { return self.ByteLength(); }
430 |
431 | bool v8__BackingStore__IsShared(const v8::BackingStore& self) { return self.IsShared(); }
432 |
433 | SharedPtr v8__BackingStore__TO_SHARED_PTR(v8::BackingStore* unique_ptr) {
434 | return make_pod(std::shared_ptr(unique_ptr));
435 | }
436 |
437 | void std__shared_ptr__v8__BackingStore__reset(std::shared_ptr* self) { self->reset(); }
438 |
439 | v8::BackingStore* std__shared_ptr__v8__BackingStore__get(const std::shared_ptr& self) { return self.get(); }
440 |
441 | long std__shared_ptr__v8__BackingStore__use_count(const std::shared_ptr& self) { return self.use_count(); }
442 |
443 | const v8::ArrayBuffer* v8__ArrayBuffer__New(
444 | v8::Isolate* isolate, size_t byte_len) {
445 | return local_to_ptr(v8::ArrayBuffer::New(isolate, byte_len));
446 | }
447 |
448 | const v8::ArrayBuffer* v8__ArrayBuffer__New2(
449 | v8::Isolate* isolate,
450 | const std::shared_ptr& backing_store) {
451 | return local_to_ptr(v8::ArrayBuffer::New(isolate, backing_store));
452 | }
453 |
454 | size_t v8__ArrayBuffer__ByteLength(const v8::ArrayBuffer& self) { return self.ByteLength(); }
455 |
456 | SharedPtr v8__ArrayBuffer__GetBackingStore(const v8::ArrayBuffer& self) {
457 | return make_pod(ptr_to_local(&self)->GetBackingStore());
458 | }
459 |
460 | // ArrayBufferView
461 |
462 | const v8::ArrayBuffer* v8__ArrayBufferView__Buffer(const v8::ArrayBufferView& self) {
463 | return local_to_ptr(ptr_to_local(&self)->Buffer());
464 | }
465 |
466 | size_t v8__ArrayBufferView__ByteLength(const v8::ArrayBufferView& self) {
467 | return ptr_to_local(&self)->ByteLength();
468 | }
469 | size_t v8__ArrayBufferView__ByteOffset(const v8::ArrayBufferView& self) {
470 | return ptr_to_local(&self)->ByteOffset();
471 | }
472 |
473 | // HandleScope
474 |
475 | void v8__HandleScope__CONSTRUCT(v8::HandleScope* buf, v8::Isolate* isolate) {
476 | // We can't do in place new, since new is overloaded for HandleScope.
477 | // Use in place construct instead.
478 | construct_in_place(buf, isolate);
479 | }
480 |
481 | void v8__HandleScope__DESTRUCT(v8::HandleScope* scope) { scope->~HandleScope(); }
482 |
483 | // Context
484 |
485 | v8::Context* v8__Context__New(
486 | v8::Isolate* isolate,
487 | const v8::ObjectTemplate* global_tmpl,
488 | const v8::Value* global_obj) {
489 | return local_to_ptr(
490 | v8::Context::New(isolate, nullptr, ptr_to_maybe_local(global_tmpl), ptr_to_maybe_local(global_obj))
491 | );
492 | }
493 |
494 | void v8__Context__Enter(const v8::Context& context) { ptr_to_local(&context)->Enter(); }
495 |
496 | void v8__Context__Exit(const v8::Context& context) { ptr_to_local(&context)->Exit(); }
497 |
498 | v8::Isolate* v8__Context__GetIsolate(const v8::Context& self) {
499 | return ptr_to_local(&self)->GetIsolate();
500 | }
501 |
502 | const v8::Object* v8__Context__Global(
503 | const v8::Context& self) {
504 | return local_to_ptr(ptr_to_local(&self)->Global());
505 | }
506 |
507 | const v8::Value* v8__Context__GetEmbedderData(
508 | const v8::Context& self,
509 | int idx) {
510 | return local_to_ptr(ptr_to_local(&self)->GetEmbedderData(idx));
511 | }
512 |
513 | void v8__Context__SetEmbedderData(
514 | const v8::Context& self,
515 | int idx,
516 | const v8::Value& val) {
517 | ptr_to_local(&self)->SetEmbedderData(idx, ptr_to_local(&val));
518 | }
519 |
520 | int v8__Context__DebugContextId(const v8::Context& self) {
521 | return v8::debug::GetContextId(ptr_to_local(&self));
522 | }
523 |
524 | // ScriptOrigin
525 |
526 | void v8__ScriptOrigin__CONSTRUCT(
527 | v8::ScriptOrigin* buf,
528 | const v8::Value& resource_name) {
529 | new (buf) v8::ScriptOrigin(ptr_to_local(&resource_name));
530 | }
531 |
532 | void v8__ScriptOrigin__CONSTRUCT2(
533 | v8::ScriptOrigin* buf,
534 | const v8::Value& resource_name,
535 | int resource_line_offset,
536 | int resource_column_offset,
537 | bool resource_is_shared_cross_origin,
538 | int script_id,
539 | const v8::Value& source_map_url,
540 | bool resource_is_opaque,
541 | bool is_wasm,
542 | bool is_module,
543 | const v8::Data& host_defined_options) {
544 | new (buf) v8::ScriptOrigin(
545 | ptr_to_local(&resource_name),
546 | resource_line_offset, resource_column_offset, resource_is_shared_cross_origin, script_id,
547 | ptr_to_local(&source_map_url), resource_is_opaque, is_wasm, is_module, ptr_to_local(&host_defined_options)
548 | );
549 | }
550 |
551 | // Script
552 |
553 | v8::Script* v8__Script__Compile(
554 | const v8::Context& context,
555 | const v8::String& src,
556 | const v8::ScriptOrigin& origin) {
557 | return maybe_local_to_ptr(
558 | v8::Script::Compile(ptr_to_local(&context), ptr_to_local(&src), const_cast(&origin))
559 | );
560 | }
561 |
562 | v8::Value* v8__Script__Run(
563 | const v8::Script& script,
564 | const v8::Context& context) {
565 | return maybe_local_to_ptr(ptr_to_local(&script)->Run(ptr_to_local(&context)));
566 | }
567 |
568 | // ScriptCompiler
569 |
570 | size_t v8__ScriptCompiler__Source__SIZEOF() {
571 | return sizeof(v8::ScriptCompiler::Source);
572 | }
573 |
574 | void v8__ScriptCompiler__Source__CONSTRUCT(
575 | const v8::String& src,
576 | v8::ScriptCompiler::CachedData* cached_data,
577 | v8::ScriptCompiler::Source* out) {
578 | new (out) v8::ScriptCompiler::Source(ptr_to_local(&src), cached_data);
579 | }
580 |
581 | void v8__ScriptCompiler__Source__CONSTRUCT2(
582 | const v8::String& src,
583 | const v8::ScriptOrigin* origin,
584 | v8::ScriptCompiler::CachedData* cached_data,
585 | v8::ScriptCompiler::Source* out) {
586 | new (out) v8::ScriptCompiler::Source(ptr_to_local(&src), *origin, cached_data);
587 | }
588 |
589 | void v8__ScriptCompiler__Source__DESTRUCT(v8::ScriptCompiler::Source* self) {
590 | self->~Source();
591 | }
592 |
593 | size_t v8__ScriptCompiler__CachedData__SIZEOF() {
594 | return sizeof(v8::ScriptCompiler::CachedData);
595 | }
596 |
597 | v8::ScriptCompiler::CachedData* v8__ScriptCompiler__CachedData__NEW(
598 | const uint8_t* data,
599 | int length) {
600 | return new v8::ScriptCompiler::CachedData(
601 | data, length, v8::ScriptCompiler::CachedData::BufferNotOwned
602 | );
603 | }
604 |
605 | void v8__ScriptCompiler__CachedData__DELETE(v8::ScriptCompiler::CachedData* self) {
606 | delete self;
607 | }
608 |
609 | const v8::Module* v8__ScriptCompiler__CompileModule(
610 | v8::Isolate* isolate,
611 | v8::ScriptCompiler::Source* source,
612 | v8::ScriptCompiler::CompileOptions options,
613 | v8::ScriptCompiler::NoCacheReason reason) {
614 | v8::MaybeLocal maybe_local = v8::ScriptCompiler::CompileModule(isolate, source, options, reason);
615 | return maybe_local_to_ptr(maybe_local);
616 | }
617 |
618 | const v8::Script* v8__ScriptCompiler__Compile(
619 | const v8::Context& context,
620 | v8::ScriptCompiler::Source* source,
621 | v8::ScriptCompiler::CompileOptions options,
622 | v8::ScriptCompiler::NoCacheReason reason) {
623 | v8::MaybeLocal maybe_local = v8::ScriptCompiler::Compile(ptr_to_local(&context), source, options, reason);
624 | return maybe_local_to_ptr(maybe_local);
625 | }
626 |
627 | size_t v8__ScriptCompiler__CompilationDetails__SIZEOF() {
628 | return sizeof(v8::ScriptCompiler::CompilationDetails);
629 | }
630 | // Module
631 |
632 | v8::Module::Status v8__Module__GetStatus(const v8::Module& self) {
633 | return self.GetStatus();
634 | }
635 |
636 | const v8::Value* v8__Module__GetException(const v8::Module& self) {
637 | return local_to_ptr(self.GetException());
638 | }
639 |
640 | const v8::FixedArray* v8__Module__GetModuleRequests(const v8::Module& self) {
641 | return local_to_ptr(self.GetModuleRequests());
642 | }
643 |
644 | void v8__Module__InstantiateModule(
645 | const v8::Module& self,
646 | const v8::Context& ctx,
647 | v8::Module::ResolveModuleCallback cb,
648 | v8::Maybe* out) {
649 | *out = ptr_to_local(&self)->InstantiateModule(ptr_to_local(&ctx), cb);
650 | }
651 |
652 | const v8::Value* v8__Module__Evaluate(
653 | const v8::Module& self,
654 | const v8::Context& ctx) {
655 | return maybe_local_to_ptr(ptr_to_local(&self)->Evaluate(ptr_to_local(&ctx)));
656 | }
657 |
658 | int v8__Module__GetIdentityHash(const v8::Module& self) {
659 | return self.GetIdentityHash();
660 | }
661 |
662 | v8::Value* v8__Module__GetModuleNamespace(v8::Module& self) {
663 | return local_to_ptr(self.GetModuleNamespace());
664 | }
665 |
666 | int v8__Module__ScriptId(const v8::Module& self) {
667 | return self.ScriptId();
668 | }
669 |
670 | // ModuleRequest
671 |
672 | const v8::String* v8__ModuleRequest__GetSpecifier(const v8::ModuleRequest& self) {
673 | return local_to_ptr(self.GetSpecifier());
674 | }
675 |
676 | int v8__ModuleRequest__GetSourceOffset(const v8::ModuleRequest& self) {
677 | return self.GetSourceOffset();
678 | }
679 |
680 | // FixedArray
681 |
682 | int v8__FixedArray__Length(const v8::FixedArray& self) {
683 | return self.Length();
684 | }
685 |
686 | const v8::Data* v8__FixedArray__Get(
687 | const v8::FixedArray& self,
688 | const v8::Context& ctx,
689 | int idx) {
690 | return local_to_ptr(ptr_to_local(&self)->Get(ptr_to_local(&ctx), idx));
691 | }
692 |
693 | // String
694 |
695 | v8::String* v8__String__NewFromUtf8(
696 | v8::Isolate* isolate,
697 | const char* data,
698 | v8::NewStringType type,
699 | int length) {
700 | return maybe_local_to_ptr(
701 | v8::String::NewFromUtf8(isolate, data, type, length)
702 | );
703 | }
704 |
705 | size_t v8__String__WriteUtf8(
706 | const v8::String& str,
707 | v8::Isolate* isolate,
708 | char* buffer,
709 | size_t length,
710 | int options) {
711 | return str.WriteUtf8V2(isolate, buffer, length, options);
712 | }
713 |
714 | int v8__String__Utf8Length(const v8::String& self, v8::Isolate* isolate) {
715 | return self.Utf8LengthV2(isolate);
716 | }
717 |
718 | // Boolean
719 |
720 | const v8::Boolean* v8__Boolean__New(
721 | v8::Isolate* isolate,
722 | bool value) {
723 | return local_to_ptr(v8::Boolean::New(isolate, value));
724 | }
725 |
726 | // Number
727 |
728 | const v8::Number* v8__Number__New(
729 | v8::Isolate* isolate,
730 | double value) {
731 | return *v8::Number::New(isolate, value);
732 | }
733 |
734 | // Integer
735 |
736 | const v8::Integer* v8__Integer__New(
737 | v8::Isolate* isolate,
738 | int32_t value) {
739 | return *v8::Integer::New(isolate, value);
740 | }
741 |
742 | const v8::Integer* v8__Integer__NewFromUnsigned(
743 | v8::Isolate* isolate,
744 | uint32_t value) {
745 | return *v8::Integer::NewFromUnsigned(isolate, value);
746 | }
747 |
748 | int64_t v8__Integer__Value(const v8::Integer& self) { return self.Value(); }
749 |
750 | // BigInt
751 |
752 | const v8::BigInt* v8__BigInt__New(
753 | v8::Isolate* iso,
754 | int64_t val) {
755 | return local_to_ptr(v8::BigInt::New(iso, val));
756 | }
757 |
758 | const v8::BigInt* v8__BigInt__NewFromUnsigned(
759 | v8::Isolate* iso,
760 | uint64_t val) {
761 | return local_to_ptr(v8::BigInt::NewFromUnsigned(iso, val));
762 | }
763 |
764 | uint64_t v8__BigInt__Uint64Value(
765 | const v8::BigInt& self,
766 | bool* lossless) {
767 | return ptr_to_local(&self)->Uint64Value(lossless);
768 | }
769 |
770 | int64_t v8__BigInt__Int64Value(
771 | const v8::BigInt& self,
772 | bool* lossless) {
773 | return ptr_to_local(&self)->Int64Value(lossless);
774 | }
775 |
776 | // Promise
777 |
778 | const v8::Promise::Resolver* v8__Promise__Resolver__New(
779 | const v8::Context& ctx) {
780 | return maybe_local_to_ptr(
781 | v8::Promise::Resolver::New(ptr_to_local(&ctx))
782 | );
783 | }
784 |
785 | const v8::Promise* v8__Promise__Resolver__GetPromise(
786 | const v8::Promise::Resolver& self) {
787 | return local_to_ptr(ptr_to_local(&self)->GetPromise());
788 | }
789 |
790 | void v8__Promise__Resolver__Resolve(
791 | const v8::Promise::Resolver& self,
792 | const v8::Context& ctx,
793 | const v8::Value& value,
794 | v8::Maybe* out) {
795 | *out = ptr_to_local(&self)->Resolve(
796 | ptr_to_local(&ctx), ptr_to_local(&value)
797 | );
798 | }
799 |
800 | void v8__Promise__Resolver__Reject(
801 | const v8::Promise::Resolver& self,
802 | const v8::Context& ctx,
803 | const v8::Value& value,
804 | v8::Maybe* out) {
805 | *out = ptr_to_local(&self)->Reject(
806 | ptr_to_local(&ctx),
807 | ptr_to_local(&value)
808 | );
809 | }
810 |
811 | const v8::Promise* v8__Promise__Catch(
812 | const v8::Promise& self,
813 | const v8::Context& ctx,
814 | const v8::Function& handler) {
815 | return maybe_local_to_ptr(
816 | ptr_to_local(&self)->Catch(ptr_to_local(&ctx), ptr_to_local(&handler))
817 | );
818 | }
819 |
820 | const v8::Promise* v8__Promise__Then(
821 | const v8::Promise& self,
822 | const v8::Context& ctx,
823 | const v8::Function& handler) {
824 | return maybe_local_to_ptr(
825 | ptr_to_local(&self)->Then(ptr_to_local(&ctx), ptr_to_local(&handler))
826 | );
827 | }
828 |
829 | const v8::Promise* v8__Promise__Then2(
830 | const v8::Promise& self,
831 | const v8::Context& ctx,
832 | const v8::Function& on_fulfilled,
833 | const v8::Function& on_rejected) {
834 | return maybe_local_to_ptr(
835 | ptr_to_local(&self)->Then(
836 | ptr_to_local(&ctx),
837 | ptr_to_local(&on_fulfilled),
838 | ptr_to_local(&on_rejected)
839 | )
840 | );
841 | }
842 |
843 | v8::Promise::PromiseState v8__Promise__State(const v8::Promise& self) {
844 | return ptr_to_local(&self)->State();
845 | }
846 |
847 | void v8__Promise__MarkAsHandled(const v8::Promise& self) {
848 | ptr_to_local(&self)->MarkAsHandled();
849 | }
850 |
851 | const v8::Value* v8__Promise__Result(const v8::Promise& self) {
852 | return local_to_ptr(ptr_to_local(&self)->Result());
853 | }
854 |
855 | // Value
856 |
857 | const v8::String* v8__Value__TypeOf(
858 | v8::Value& self,
859 | v8::Isolate* isolate) {
860 | return local_to_ptr(self.TypeOf(isolate));
861 | }
862 |
863 | const v8::String* v8__Value__ToString(
864 | const v8::Value& self,
865 | const v8::Context& ctx) {
866 | return maybe_local_to_ptr(self.ToString(ptr_to_local(&ctx)));
867 | }
868 |
869 | const v8::String* v8__Value__ToDetailString(
870 | const v8::Value& self,
871 | const v8::Context& ctx) {
872 | return maybe_local_to_ptr(self.ToDetailString(ptr_to_local(&ctx)));
873 | }
874 |
875 | bool v8__Value__BooleanValue(
876 | const v8::Value& self,
877 | v8::Isolate* isolate) {
878 | return self.BooleanValue(isolate);
879 | }
880 |
881 | void v8__Value__Uint32Value(
882 | const v8::Value& self,
883 | const v8::Context& ctx,
884 | v8::Maybe* out) {
885 | *out = self.Uint32Value(ptr_to_local(&ctx));
886 | }
887 |
888 | void v8__Value__Int32Value(
889 | const v8::Value& self,
890 | const v8::Context& ctx,
891 | v8::Maybe* out) {
892 | *out = self.Int32Value(ptr_to_local(&ctx));
893 | }
894 |
895 | void v8__Value__NumberValue(
896 | const v8::Value& self,
897 | const v8::Context& ctx,
898 | v8::Maybe* out) {
899 | *out = self.NumberValue(ptr_to_local(&ctx));
900 | }
901 |
902 | bool v8__Value__IsFunction(const v8::Value& self) { return self.IsFunction(); }
903 |
904 | bool v8__Value__IsAsyncFunction(const v8::Value& self) { return self.IsAsyncFunction(); }
905 |
906 | bool v8__Value__IsPromise(const v8::Value& self) { return self.IsPromise(); }
907 |
908 | bool v8__Value__IsBoolean(const v8::Value& self) { return self.IsBoolean(); }
909 |
910 | bool v8__Value__IsBooleanObject(const v8::Value& self) { return self.IsBooleanObject(); }
911 |
912 | bool v8__Value__IsInt32(const v8::Value& self) { return self.IsInt32(); }
913 |
914 | bool v8__Value__IsUint32(const v8::Value& self) { return self.IsUint32(); }
915 |
916 | bool v8__Value__IsNumber(const v8::Value& self) { return self.IsNumber(); }
917 |
918 | bool v8__Value__IsNumberObject(const v8::Value& self) { return self.IsNumberObject(); }
919 |
920 | bool v8__Value__IsObject(const v8::Value& self) { return self.IsObject(); }
921 |
922 | bool v8__Value__IsString(const v8::Value& self) { return self.IsString(); }
923 |
924 | bool v8__Value__IsSymbol(const v8::Value& self) { return self.IsSymbol(); }
925 |
926 | bool v8__Value__IsArray(const v8::Value& self) { return self.IsArray(); }
927 |
928 | bool v8__Value__IsTypedArray(const v8::Value& self) { return self.IsTypedArray(); }
929 |
930 | bool v8__Value__IsUint8Array(const v8::Value& self) { return self.IsUint8Array(); }
931 |
932 | bool v8__Value__IsUint8ClampedArray(const v8::Value& self) { return self.IsUint8ClampedArray(); }
933 |
934 | bool v8__Value__IsInt8Array(const v8::Value& self) { return self.IsInt8Array(); }
935 |
936 | bool v8__Value__IsUint16Array(const v8::Value& self) { return self.IsUint16Array(); }
937 |
938 | bool v8__Value__IsInt16Array(const v8::Value& self) { return self.IsInt16Array(); }
939 |
940 | bool v8__Value__IsUint32Array(const v8::Value& self) { return self.IsUint32Array(); }
941 |
942 | bool v8__Value__IsInt32Array(const v8::Value& self) { return self.IsInt32Array(); }
943 |
944 | bool v8__Value__IsBigInt64Array(const v8::Value& self) { return self.IsBigInt64Array(); }
945 |
946 | bool v8__Value__IsBigUint64Array(const v8::Value& self) { return self.IsBigUint64Array(); }
947 |
948 | bool v8__Value__IsFloat32Array(const v8::Value& self) { return self.IsFloat32Array(); }
949 |
950 | bool v8__Value__IsFloat64Array(const v8::Value& self) { return self.IsFloat64Array(); }
951 |
952 | bool v8__Value__IsArrayBuffer(const v8::Value& self) { return self.IsArrayBuffer(); }
953 |
954 | bool v8__Value__IsArrayBufferView(const v8::Value& self) { return self.IsArrayBufferView(); }
955 |
956 | bool v8__Value__IsExternal(const v8::Value& self) { return self.IsExternal(); }
957 |
958 | bool v8__Value__IsTrue(const v8::Value& self) { return self.IsTrue(); }
959 |
960 | bool v8__Value__IsFalse(const v8::Value& self) { return self.IsFalse(); }
961 |
962 | bool v8__Value__IsUndefined(const v8::Value& self) { return self.IsUndefined(); }
963 |
964 | bool v8__Value__IsNull(const v8::Value& self) { return self.IsNull(); }
965 |
966 | bool v8__Value__IsNullOrUndefined(const v8::Value& self) { return self.IsNullOrUndefined(); }
967 |
968 | bool v8__Value__IsNativeError(const v8::Value& self) { return self.IsNativeError(); }
969 |
970 | bool v8__Value__IsBigInt(const v8::Value& self) {
971 | return self.IsBigInt();
972 | }
973 |
974 | bool v8__Value__IsBigIntObject(const v8::Value& self) {
975 | return self.IsBigIntObject();
976 | }
977 |
978 | void v8__Value__InstanceOf(
979 | const v8::Value& self,
980 | const v8::Context& ctx,
981 | const v8::Object& object,
982 | v8::Maybe* out) {
983 | *out = ptr_to_local(&self)->InstanceOf(ptr_to_local(&ctx), ptr_to_local(&object));
984 | }
985 |
986 | // Template
987 |
988 | void v8__Template__Set(
989 | const v8::Template& self,
990 | const v8::Name& key,
991 | const v8::Data& value,
992 | v8::PropertyAttribute attr) {
993 | ptr_to_local(&self)->Set(ptr_to_local(&key), ptr_to_local(&value), attr);
994 | }
995 |
996 | void v8__Template__SetAccessorProperty__DEFAULT(
997 | const v8::Template& self,
998 | const v8::Name& key,
999 | const v8::FunctionTemplate& getter) {
1000 | ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), ptr_to_local(&getter));
1001 | }
1002 |
1003 | // ObjectTemplate
1004 |
1005 | const v8::ObjectTemplate* v8__ObjectTemplate__New__DEFAULT(
1006 | v8::Isolate* isolate) {
1007 | return local_to_ptr(v8::ObjectTemplate::New(isolate));
1008 | }
1009 |
1010 | const v8::ObjectTemplate* v8__ObjectTemplate__New(
1011 | v8::Isolate* isolate, const v8::FunctionTemplate& constructor) {
1012 | return local_to_ptr(v8::ObjectTemplate::New(isolate, ptr_to_local(&constructor)));
1013 | }
1014 |
1015 | const v8::Object* v8__ObjectTemplate__NewInstance(
1016 | const v8::ObjectTemplate& self, const v8::Context& ctx) {
1017 | return maybe_local_to_ptr(
1018 | ptr_to_local(&self)->NewInstance(ptr_to_local(&ctx))
1019 | );
1020 | }
1021 |
1022 | void v8__ObjectTemplate__SetInternalFieldCount(
1023 | const v8::ObjectTemplate& self,
1024 | int value) {
1025 | ptr_to_local(&self)->SetInternalFieldCount(value);
1026 | }
1027 |
1028 | void v8__ObjectTemplate__SetIndexedHandler(
1029 | const v8::ObjectTemplate& self,
1030 | const v8::IndexedPropertyHandlerConfiguration& configuration) {
1031 | ptr_to_local(&self)->SetHandler(configuration);
1032 | }
1033 |
1034 | void v8__ObjectTemplate__SetNamedHandler(
1035 | const v8::ObjectTemplate& self,
1036 | const v8::NamedPropertyHandlerConfiguration& configuration) {
1037 | ptr_to_local(&self)->SetHandler(configuration);
1038 | }
1039 |
1040 | void v8__ObjectTemplate__SetAccessorProperty__DEFAULT(
1041 | const v8::ObjectTemplate& self,
1042 | const v8::Name& key,
1043 | const v8::FunctionTemplate& getter) {
1044 | ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), ptr_to_local(&getter));
1045 | }
1046 |
1047 | void v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(
1048 | const v8::ObjectTemplate& self,
1049 | const v8::Name& key,
1050 | const v8::FunctionTemplate& getter,
1051 | const v8::FunctionTemplate& setter) {
1052 | ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), ptr_to_local(&getter), ptr_to_local(&setter));
1053 | }
1054 |
1055 | void v8__ObjectTemplate__SetNativeDataProperty__DEFAULT(
1056 | const v8::ObjectTemplate& self,
1057 | const v8::Name& key,
1058 | const v8::AccessorNameGetterCallback getter) {
1059 | ptr_to_local(&self)->SetNativeDataProperty(ptr_to_local(&key), getter);
1060 | }
1061 |
1062 | void v8__ObjectTemplate__SetNativeDataProperty__DEFAULT2(
1063 | const v8::ObjectTemplate& self,
1064 | const v8::Name& key,
1065 | const v8::AccessorNameGetterCallback getter,
1066 | const v8::AccessorNameSetterCallback setter) {
1067 | ptr_to_local(&self)->SetNativeDataProperty(ptr_to_local(&key), getter, setter);
1068 | }
1069 |
1070 | void v8__ObjectTemplate__MarkAsUndetectable(
1071 | const v8::ObjectTemplate& self) {
1072 | ptr_to_local(&self)->MarkAsUndetectable();
1073 | }
1074 |
1075 | void v8__ObjectTemplate__SetCallAsFunctionHandler(
1076 | const v8::ObjectTemplate& self,
1077 | v8::FunctionCallback callback_or_null) {
1078 | ptr_to_local(&self)->SetCallAsFunctionHandler(callback_or_null);
1079 | }
1080 |
1081 | // Array
1082 |
1083 | const v8::Array* v8__Array__New(
1084 | v8::Isolate* isolate,
1085 | int length) {
1086 | return local_to_ptr(v8::Array::New(isolate, length));
1087 | }
1088 |
1089 | const v8::Array* v8__Array__New2(
1090 | v8::Isolate* isolate,
1091 | const v8::Value* const elements[],
1092 | size_t length) {
1093 | return local_to_ptr(
1094 | v8::Array::New(isolate, const_ptr_array_to_local_array(elements), length)
1095 | );
1096 | }
1097 |
1098 | uint32_t v8__Array__Length(const v8::Array& self) { return self.Length(); }
1099 |
1100 | // Object
1101 |
1102 | const v8::Object* v8__Object__New(
1103 | v8::Isolate* isolate) {
1104 | return local_to_ptr(v8::Object::New(isolate));
1105 | }
1106 |
1107 | const v8::String* v8__Object__GetConstructorName(
1108 | const v8::Object& self) {
1109 | return local_to_ptr(ptr_to_local(&self)->GetConstructorName());
1110 | }
1111 |
1112 | void v8__Object__SetInternalField(
1113 | const v8::Object& self,
1114 | int index,
1115 | const v8::Value& value) {
1116 | ptr_to_local(&self)->SetInternalField(index, ptr_to_local(&value));
1117 | }
1118 |
1119 | const v8::Data* v8__Object__GetInternalField(
1120 | const v8::Object& self,
1121 | int index) {
1122 | return local_to_ptr(ptr_to_local(&self)->GetInternalField(index));
1123 | }
1124 |
1125 | int v8__Object__InternalFieldCount(
1126 | const v8::Object& self) {
1127 | return ptr_to_local(&self)->InternalFieldCount();
1128 | }
1129 |
1130 | const v8::Value* v8__Object__Get(
1131 | const v8::Object& self,
1132 | const v8::Context& ctx,
1133 | const v8::Value& key) {
1134 | return maybe_local_to_ptr(
1135 | ptr_to_local(&self)->Get(ptr_to_local(&ctx), ptr_to_local(&key))
1136 | );
1137 | }
1138 |
1139 | const v8::Value* v8__Object__GetIndex(
1140 | const v8::Object& self,
1141 | const v8::Context& ctx,
1142 | uint32_t idx) {
1143 | return maybe_local_to_ptr(
1144 | ptr_to_local(&self)->Get(ptr_to_local(&ctx), idx)
1145 | );
1146 | }
1147 |
1148 | void v8__Object__Set(
1149 | const v8::Object& self,
1150 | const v8::Context& ctx,
1151 | const v8::Value& key,
1152 | const v8::Value& value,
1153 | v8::Maybe* out) {
1154 | *out = ptr_to_local(&self)->Set(
1155 | ptr_to_local(&ctx),
1156 | ptr_to_local(&key),
1157 | ptr_to_local(&value)
1158 | );
1159 | }
1160 |
1161 | void v8__Object__Delete(
1162 | const v8::Object& self,
1163 | const v8::Context& ctx,
1164 | const v8::Value& key,
1165 | v8::Maybe* out) {
1166 | *out = ptr_to_local(&self)->Delete(
1167 | ptr_to_local(&ctx),
1168 | ptr_to_local(&key)
1169 | );
1170 | }
1171 |
1172 | void v8__Object__SetAtIndex(
1173 | const v8::Object& self,
1174 | const v8::Context& ctx,
1175 | uint32_t idx,
1176 | const v8::Value& value,
1177 | v8::Maybe* out) {
1178 | *out = ptr_to_local(&self)->Set(
1179 | ptr_to_local(&ctx),
1180 | idx,
1181 | ptr_to_local(&value)
1182 | );
1183 | }
1184 |
1185 | void v8__Object__DefineOwnProperty(
1186 | const v8::Object& self,
1187 | const v8::Context& ctx,
1188 | const v8::Name& key,
1189 | const v8::Value& value,
1190 | v8::PropertyAttribute attr,
1191 | v8::Maybe* out) {
1192 | *out = ptr_to_local(&self)->DefineOwnProperty(
1193 | ptr_to_local(&ctx),
1194 | ptr_to_local(&key),
1195 | ptr_to_local(&value),
1196 | attr
1197 | );
1198 | }
1199 |
1200 | v8::Isolate* v8__Object__GetIsolate(const v8::Object& self) {
1201 | return ptr_to_local(&self)->GetIsolate();
1202 | }
1203 |
1204 | const v8::Context* v8__Object__GetCreationContext(const v8::Object& self) {
1205 | return maybe_local_to_ptr(ptr_to_local(&self)->GetCreationContext());
1206 | }
1207 |
1208 | int v8__Object__GetIdentityHash(const v8::Object& self) {
1209 | return ptr_to_local(&self)->GetIdentityHash();
1210 | }
1211 |
1212 | void v8__Object__Has(
1213 | const v8::Object& self,
1214 | const v8::Context& ctx,
1215 | const v8::Value& key,
1216 | v8::Maybe* out) {
1217 | *out = ptr_to_local(&self)->Has(
1218 | ptr_to_local(&ctx), ptr_to_local(&key)
1219 | );
1220 | }
1221 |
1222 | void v8__Object__HasIndex(
1223 | const v8::Object& self,
1224 | const v8::Context& ctx,
1225 | uint32_t idx,
1226 | v8::Maybe* out) {
1227 | *out = ptr_to_local(&self)->Has(ptr_to_local(&ctx), idx);
1228 | }
1229 |
1230 | const v8::Array* v8__Object__GetOwnPropertyNames(
1231 | const v8::Object* self,
1232 | const v8::Context* ctx) {
1233 | return maybe_local_to_ptr(
1234 | ptr_to_local(self)->GetOwnPropertyNames(ptr_to_local(ctx))
1235 | );
1236 | }
1237 |
1238 | const v8::Array* v8__Object__GetPropertyNames(
1239 | const v8::Object* self,
1240 | const v8::Context* ctx) {
1241 | return maybe_local_to_ptr(
1242 | ptr_to_local(self)->GetPropertyNames(ptr_to_local(ctx))
1243 | );
1244 | }
1245 |
1246 | const v8::Value* v8__Object__GetPrototype(
1247 | const v8::Object& self) {
1248 | return local_to_ptr(ptr_to_local(&self)->GetPrototypeV2());
1249 | }
1250 |
1251 | void v8__Object__SetPrototype(
1252 | const v8::Object& self,
1253 | const v8::Context& ctx,
1254 | const v8::Object& prototype,
1255 | v8::Maybe* out) {
1256 | *out = ptr_to_local(&self)->SetPrototypeV2(ptr_to_local(&ctx), ptr_to_local(&prototype));
1257 | }
1258 |
1259 | void v8__Object__SetAlignedPointerInInternalField(
1260 | const v8::Object* self,
1261 | int idx,
1262 | void* ptr) {
1263 | ptr_to_local(self)->SetAlignedPointerInInternalField(idx, ptr);
1264 | }
1265 |
1266 | // FunctionCallbackInfo
1267 |
1268 | v8::Isolate* v8__FunctionCallbackInfo__GetIsolate(
1269 | const v8::FunctionCallbackInfo& self) {
1270 | return self.GetIsolate();
1271 | }
1272 |
1273 | int v8__FunctionCallbackInfo__Length(
1274 | const v8::FunctionCallbackInfo& self) {
1275 | return self.Length();
1276 | }
1277 |
1278 | const v8::Value* v8__FunctionCallbackInfo__INDEX(
1279 | const v8::FunctionCallbackInfo& self, int i) {
1280 | return local_to_ptr(self[i]);
1281 | }
1282 |
1283 | void v8__FunctionCallbackInfo__GetReturnValue(
1284 | const v8::FunctionCallbackInfo& self,
1285 | v8::ReturnValue* out) {
1286 | // Can't return incomplete type to C so copy to res pointer.
1287 | *out = self.GetReturnValue();
1288 | }
1289 |
1290 | const v8::Object* v8__FunctionCallbackInfo__This(
1291 | const v8::FunctionCallbackInfo& self) {
1292 | return local_to_ptr(self.This());
1293 | }
1294 |
1295 | const v8::Value* v8__FunctionCallbackInfo__Data(
1296 | const v8::FunctionCallbackInfo& self) {
1297 | return local_to_ptr(self.Data());
1298 | }
1299 |
1300 | // PropertyCallbackInfo
1301 |
1302 | v8::Isolate* v8__PropertyCallbackInfo__GetIsolate(
1303 | const v8::PropertyCallbackInfo& self) {
1304 | return self.GetIsolate();
1305 | }
1306 |
1307 | void v8__PropertyCallbackInfo__GetReturnValue(
1308 | const v8::PropertyCallbackInfo& self,
1309 | v8::ReturnValue* out) {
1310 | *out = self.GetReturnValue();
1311 | }
1312 |
1313 | const v8::Object* v8__PropertyCallbackInfo__This(
1314 | const v8::PropertyCallbackInfo& self) {
1315 | return local_to_ptr(self.This());
1316 | }
1317 |
1318 | const v8::Value* v8__PropertyCallbackInfo__Data(
1319 | const v8::PropertyCallbackInfo& self) {
1320 | return local_to_ptr(self.Data());
1321 | }
1322 |
1323 | // PromiseRejectMessage
1324 |
1325 | v8::PromiseRejectEvent v8__PromiseRejectMessage__GetEvent(const v8::PromiseRejectMessage& self) {
1326 | return self.GetEvent();
1327 | }
1328 |
1329 | const v8::Promise* v8__PromiseRejectMessage__GetPromise(const v8::PromiseRejectMessage& self) {
1330 | return local_to_ptr(self.GetPromise());
1331 | }
1332 |
1333 | const v8::Value* v8__PromiseRejectMessage__GetValue(const v8::PromiseRejectMessage& self) {
1334 | return local_to_ptr(self.GetValue());
1335 | }
1336 |
1337 | size_t v8__PromiseRejectMessage__SIZEOF() {
1338 | return sizeof(v8::PromiseRejectMessage);
1339 | }
1340 |
1341 | // ReturnValue
1342 |
1343 | void v8__ReturnValue__Set(
1344 | v8::ReturnValue self,
1345 | const v8::Value& value) {
1346 | self.Set(ptr_to_local(&value));
1347 | }
1348 |
1349 | const v8::Value* v8__ReturnValue__Get(
1350 | v8::ReturnValue self) {
1351 | return local_to_ptr(self.Get());
1352 | }
1353 |
1354 | // FunctionTemplate
1355 |
1356 | const v8::FunctionTemplate* v8__FunctionTemplate__New__DEFAULT(
1357 | v8::Isolate* isolate) {
1358 | return local_to_ptr(v8::FunctionTemplate::New(isolate));
1359 | }
1360 |
1361 | const v8::FunctionTemplate* v8__FunctionTemplate__New__DEFAULT2(
1362 | v8::Isolate* isolate,
1363 | v8::FunctionCallback callback_or_null) {
1364 | return local_to_ptr(v8::FunctionTemplate::New(isolate, callback_or_null));
1365 | }
1366 |
1367 | const v8::FunctionTemplate* v8__FunctionTemplate__New__DEFAULT3(
1368 | v8::Isolate* isolate,
1369 | v8::FunctionCallback callback_or_null,
1370 | const v8::Value& data) {
1371 | return local_to_ptr(v8::FunctionTemplate::New(isolate, callback_or_null, ptr_to_local(&data)));
1372 | }
1373 |
1374 | const v8::ObjectTemplate* v8__FunctionTemplate__InstanceTemplate(
1375 | const v8::FunctionTemplate& self) {
1376 | return local_to_ptr(ptr_to_local(&self)->InstanceTemplate());
1377 | }
1378 |
1379 | const v8::ObjectTemplate* v8__FunctionTemplate__PrototypeTemplate(
1380 | const v8::FunctionTemplate& self) {
1381 | return local_to_ptr(ptr_to_local(&self)->PrototypeTemplate());
1382 | }
1383 |
1384 | void v8__FunctionTemplate__Inherit(
1385 | const v8::FunctionTemplate& self,
1386 | const v8::FunctionTemplate& parent) {
1387 | ptr_to_local(&self)->Inherit(ptr_to_local(&parent));
1388 | }
1389 |
1390 | void v8__FunctionTemplate__SetPrototypeProviderTemplate(
1391 | const v8::FunctionTemplate& self,
1392 | const v8::FunctionTemplate& prototype_provider) {
1393 | ptr_to_local(&self)->SetPrototypeProviderTemplate(ptr_to_local(&prototype_provider));
1394 | }
1395 |
1396 | const v8::Function* v8__FunctionTemplate__GetFunction(
1397 | const v8::FunctionTemplate& self, const v8::Context& context) {
1398 | return maybe_local_to_ptr(
1399 | ptr_to_local(&self)->GetFunction(ptr_to_local(&context))
1400 | );
1401 | }
1402 |
1403 | void v8__FunctionTemplate__SetClassName(
1404 | const v8::FunctionTemplate& self,
1405 | const v8::String& name) {
1406 | ptr_to_local(&self)->SetClassName(ptr_to_local(&name));
1407 | }
1408 |
1409 | void v8__FunctionTemplate__ReadOnlyPrototype(
1410 | const v8::FunctionTemplate& self) {
1411 | ptr_to_local(&self)->ReadOnlyPrototype();
1412 | }
1413 |
1414 | // Function
1415 |
1416 | const v8::Function* v8__Function__New__DEFAULT(
1417 | const v8::Context& ctx,
1418 | v8::FunctionCallback callback) {
1419 | return maybe_local_to_ptr(
1420 | v8::Function::New(ptr_to_local(&ctx), callback)
1421 | );
1422 | }
1423 |
1424 | const v8::Function* v8__Function__New__DEFAULT2(
1425 | const v8::Context& ctx,
1426 | v8::FunctionCallback callback,
1427 | const v8::Value& data) {
1428 | return maybe_local_to_ptr(
1429 | v8::Function::New(ptr_to_local(&ctx), callback, ptr_to_local(&data))
1430 | );
1431 | }
1432 |
1433 | const v8::Value* v8__Function__Call(
1434 | const v8::Function& self,
1435 | const v8::Context& context,
1436 | const v8::Value& recv,
1437 | int argc,
1438 | const v8::Value* const argv[]) {
1439 | return maybe_local_to_ptr(
1440 | ptr_to_local(&self)->Call(
1441 | ptr_to_local(&context),
1442 | ptr_to_local(&recv),
1443 | argc, const_ptr_array_to_local_array(argv)
1444 | )
1445 | );
1446 | }
1447 |
1448 | const v8::Object* v8__Function__NewInstance(
1449 | const v8::Function& self,
1450 | const v8::Context& context,
1451 | int argc,
1452 | const v8::Value* const argv[]) {
1453 | return maybe_local_to_ptr(
1454 | ptr_to_local(&self)->NewInstance(
1455 | ptr_to_local(&context),
1456 | argc,
1457 | const_ptr_array_to_local_array(argv)
1458 | )
1459 | );
1460 | }
1461 |
1462 | const v8::Value* v8__Function__GetName(const v8::Function& self) {
1463 | return local_to_ptr(self.GetName());
1464 | }
1465 |
1466 | void v8__Function__SetName(
1467 | const v8::Function& self,
1468 | const v8::String& name) {
1469 | return ptr_to_local(&self)->SetName(ptr_to_local(&name));
1470 | }
1471 |
1472 | // External
1473 |
1474 | const v8::External* v8__External__New(
1475 | v8::Isolate* isolate,
1476 | void* value) {
1477 | return local_to_ptr(v8::External::New(isolate, value));
1478 | }
1479 |
1480 | void* v8__External__Value(const v8::External& self) { return self.Value(); }
1481 |
1482 | // Symbol well-known
1483 |
1484 | const v8::Symbol* v8__Symbol__GetAsyncIterator(v8::Isolate* isolate) {
1485 | return local_to_ptr(v8::Symbol::GetAsyncIterator(isolate));
1486 | }
1487 | const v8::Symbol* v8__Symbol__GetHasInstance(v8::Isolate* isolate) {
1488 | return local_to_ptr(v8::Symbol::GetHasInstance(isolate));
1489 | }
1490 | const v8::Symbol* v8__Symbol__GetIsConcatSpreadable(v8::Isolate* isolate) {
1491 | return local_to_ptr(v8::Symbol::GetIsConcatSpreadable(isolate));
1492 | }
1493 | const v8::Symbol* v8__Symbol__GetIterator(v8::Isolate* isolate) {
1494 | return local_to_ptr(v8::Symbol::GetIterator(isolate));
1495 | }
1496 | const v8::Symbol* v8__Symbol__GetMatch(v8::Isolate* isolate) {
1497 | return local_to_ptr(v8::Symbol::GetMatch(isolate));
1498 | }
1499 | const v8::Symbol* v8__Symbol__GetReplace(v8::Isolate* isolate) {
1500 | return local_to_ptr(v8::Symbol::GetReplace(isolate));
1501 | }
1502 | const v8::Symbol* v8__Symbol__GetSearch(v8::Isolate* isolate) {
1503 | return local_to_ptr(v8::Symbol::GetSearch(isolate));
1504 | }
1505 | const v8::Symbol* v8__Symbol__GetSplit(v8::Isolate* isolate) {
1506 | return local_to_ptr(v8::Symbol::GetSplit(isolate));
1507 | }
1508 | const v8::Symbol* v8__Symbol__GetToPrimitive(v8::Isolate* isolate) {
1509 | return local_to_ptr(v8::Symbol::GetToPrimitive(isolate));
1510 | }
1511 | const v8::Symbol* v8__Symbol__GetToStringTag(v8::Isolate* isolate) {
1512 | return local_to_ptr(v8::Symbol::GetToStringTag(isolate));
1513 | }
1514 | const v8::Symbol* v8__Symbol__GetUnscopables(v8::Isolate* isolate) {
1515 | return local_to_ptr(v8::Symbol::GetUnscopables(isolate));
1516 | }
1517 | const v8::Value* v8__Symbol__Description(const v8::Symbol& self, v8::Isolate* isolate) {
1518 | return local_to_ptr(self.Description(isolate));
1519 | }
1520 |
1521 | // Persistent
1522 |
1523 | void v8__Persistent__New(
1524 | v8::Isolate* isolate,
1525 | // Allow passing in a data pointer which includes values, templates, context, and more.
1526 | const v8::Data& data,
1527 | v8::Persistent* out) {
1528 | new (out) v8::Persistent(isolate, ptr_to_local(&data));
1529 | }
1530 |
1531 | void v8__Persistent__Reset(v8::Persistent* self) {
1532 | // v8::Persistent by default uses NonCopyablePersistentTraits which will create a bad copy if we accept v8::Persistent as the arg.
1533 | // Instead we operate on its pointer.
1534 | self->Reset();
1535 | }
1536 |
1537 | void v8__Persistent__SetWeak(v8::Persistent* self) {
1538 | self->SetWeak();
1539 | }
1540 |
1541 | void v8__Persistent__SetWeakFinalizer(
1542 | v8::Persistent* self,
1543 | void* finalizer_ctx,
1544 | v8::WeakCallbackInfo::Callback finalizer_cb,
1545 | v8::WeakCallbackType type) {
1546 | self->SetWeak(finalizer_ctx, finalizer_cb, type);
1547 | }
1548 |
1549 | // WeakCallbackInfo
1550 |
1551 | v8::Isolate* v8__WeakCallbackInfo__GetIsolate(
1552 | const v8::WeakCallbackInfo& self) {
1553 | return self.GetIsolate();
1554 | }
1555 |
1556 | void* v8__WeakCallbackInfo__GetParameter(
1557 | const v8::WeakCallbackInfo& self) {
1558 | return self.GetParameter();
1559 | }
1560 |
1561 | void* v8__WeakCallbackInfo__GetInternalField(
1562 | const v8::WeakCallbackInfo& self,
1563 | int idx) {
1564 | return self.GetInternalField(idx);
1565 | }
1566 |
1567 | // Exception
1568 |
1569 | const v8::Value* v8__Exception__Error(const v8::String& message) {
1570 | return local_to_ptr(v8::Exception::Error(ptr_to_local(&message)));
1571 | }
1572 |
1573 | const v8::Value* v8__Exception__TypeError(const v8::String& message) {
1574 | return local_to_ptr(v8::Exception::TypeError(ptr_to_local(&message)));
1575 | }
1576 |
1577 | const v8::Value* v8__Exception__SyntaxError(const v8::String& message) {
1578 | return local_to_ptr(v8::Exception::SyntaxError(ptr_to_local(&message)));
1579 | }
1580 |
1581 | const v8::Value* v8__Exception__ReferenceError(const v8::String& message) {
1582 | return local_to_ptr(v8::Exception::ReferenceError(ptr_to_local(&message)));
1583 | }
1584 |
1585 | const v8::Value* v8__Exception__RangeError(const v8::String& message) {
1586 | return local_to_ptr(v8::Exception::RangeError(ptr_to_local(&message)));
1587 | }
1588 |
1589 | const v8::StackTrace* v8__Exception__GetStackTrace(const v8::Value& exception) {
1590 | return local_to_ptr(v8::Exception::GetStackTrace(ptr_to_local(&exception)));
1591 | }
1592 |
1593 | const v8::Message* v8__Exception__CreateMessage(
1594 | v8::Isolate* isolate,
1595 | const v8::Value& exception) {
1596 | return local_to_ptr(v8::Exception::CreateMessage(isolate, ptr_to_local(&exception)));
1597 | }
1598 |
1599 | // TryCatch
1600 |
1601 | size_t v8__TryCatch__SIZEOF() {
1602 | return sizeof(v8::TryCatch);
1603 | }
1604 |
1605 | void v8__TryCatch__CONSTRUCT(
1606 | v8::TryCatch* buf, v8::Isolate* isolate) {
1607 | construct_in_place(buf, isolate);
1608 | }
1609 |
1610 | void v8__TryCatch__DESTRUCT(v8::TryCatch* self) { self->~TryCatch(); }
1611 |
1612 | const v8::Value* v8__TryCatch__Exception(const v8::TryCatch& self) {
1613 | return local_to_ptr(self.Exception());
1614 | }
1615 |
1616 | const v8::Message* v8__TryCatch__Message(const v8::TryCatch& self) {
1617 | return local_to_ptr(self.Message());
1618 | }
1619 |
1620 | bool v8__TryCatch__HasCaught(const v8::TryCatch& self) {
1621 | return self.HasCaught();
1622 | }
1623 |
1624 | const v8::Value* v8__TryCatch__StackTrace(
1625 | const v8::TryCatch& self,
1626 | const v8::Context& context) {
1627 | return maybe_local_to_ptr(self.StackTrace(ptr_to_local(&context)));
1628 | }
1629 |
1630 | bool v8__TryCatch__IsVerbose(const v8::TryCatch& self) { return self.IsVerbose(); }
1631 |
1632 | void v8__TryCatch__SetVerbose(
1633 | v8::TryCatch* self,
1634 | bool value) {
1635 | self->SetVerbose(value);
1636 | }
1637 |
1638 | const v8::Value* v8__TryCatch__ReThrow(v8::TryCatch* self) {
1639 | return local_to_ptr(self->ReThrow());
1640 | }
1641 |
1642 | // Message
1643 |
1644 | const v8::String* v8__Message__Get(const v8::Message& self) {
1645 | return local_to_ptr(self.Get());
1646 | }
1647 |
1648 | const v8::String* v8__Message__GetSourceLine(
1649 | const v8::Message& self,
1650 | const v8::Context& context) {
1651 | return maybe_local_to_ptr(self.GetSourceLine(ptr_to_local(&context)));
1652 | }
1653 |
1654 | const v8::Value* v8__Message__GetScriptResourceName(const v8::Message& self) {
1655 | return local_to_ptr(self.GetScriptResourceName());
1656 | }
1657 |
1658 | int v8__Message__GetLineNumber(
1659 | const v8::Message& self,
1660 | const v8::Context& context) {
1661 | v8::Maybe maybe = self.GetLineNumber(ptr_to_local(&context));
1662 | return maybe.FromMaybe(-1);
1663 | }
1664 |
1665 | int v8__Message__GetStartColumn(const v8::Message& self) { return self.GetStartColumn(); }
1666 |
1667 | int v8__Message__GetEndColumn(const v8::Message& self) { return self.GetEndColumn(); }
1668 |
1669 | const v8::StackTrace* v8__Message__GetStackTrace(const v8::Message& self) { return local_to_ptr(self.GetStackTrace()); }
1670 |
1671 | // StackTrace
1672 |
1673 | int v8__StackTrace__GetFrameCount(const v8::StackTrace& self) { return self.GetFrameCount(); }
1674 |
1675 | const v8::StackFrame* v8__StackTrace__GetFrame(
1676 | const v8::StackTrace& self,
1677 | v8::Isolate* isolate,
1678 | uint32_t idx) {
1679 | return local_to_ptr(self.GetFrame(isolate, idx));
1680 | }
1681 |
1682 | const v8::StackTrace* v8__StackTrace__CurrentStackTrace__STATIC(
1683 | v8::Isolate* isolate,
1684 | int frame_limit) {
1685 | return local_to_ptr(v8::StackTrace::CurrentStackTrace(isolate, frame_limit));
1686 | }
1687 |
1688 | const v8::String* v8__StackTrace__CurrentScriptNameOrSourceURL__STATIC(v8::Isolate* isolate) {
1689 | return local_to_ptr(v8::StackTrace::CurrentScriptNameOrSourceURL(isolate));
1690 | }
1691 |
1692 | // StackFrame
1693 |
1694 | int v8__StackFrame__GetLineNumber(const v8::StackFrame& self) { return self.GetLineNumber(); }
1695 |
1696 | int v8__StackFrame__GetColumn(const v8::StackFrame& self) { return self.GetColumn(); }
1697 |
1698 | int v8__StackFrame__GetScriptId(const v8::StackFrame& self) { return self.GetScriptId(); }
1699 |
1700 | const v8::String* v8__StackFrame__GetScriptName(const v8::StackFrame& self) {
1701 | return local_to_ptr(self.GetScriptName());
1702 | }
1703 |
1704 | const v8::String* v8__StackFrame__GetScriptNameOrSourceURL(const v8::StackFrame& self) {
1705 | return local_to_ptr(self.GetScriptNameOrSourceURL());
1706 | }
1707 |
1708 | const v8::String* v8__StackFrame__GetFunctionName(const v8::StackFrame& self) {
1709 | return local_to_ptr(self.GetFunctionName());
1710 | }
1711 |
1712 | bool v8__StackFrame__IsEval(const v8::StackFrame& self) { return self.IsEval(); }
1713 |
1714 | bool v8__StackFrame__IsConstructor(const v8::StackFrame& self) { return self.IsConstructor(); }
1715 |
1716 | bool v8__StackFrame__IsWasm(const v8::StackFrame& self) { return self.IsWasm(); }
1717 |
1718 | bool v8__StackFrame__IsUserJavaScript(const v8::StackFrame& self) { return self.IsUserJavaScript(); }
1719 |
1720 | // JSON
1721 |
1722 | const v8::Value* v8__JSON__Parse(
1723 | const v8::Context& ctx,
1724 | const v8::String& json) {
1725 | return maybe_local_to_ptr(
1726 | v8::JSON::Parse(ptr_to_local(&ctx), ptr_to_local(&json)));
1727 | }
1728 |
1729 | const v8::String* v8__JSON__Stringify(
1730 | const v8::Context& ctx,
1731 | const v8::Value& val,
1732 | const v8::String& gap) {
1733 | return maybe_local_to_ptr(
1734 | v8::JSON::Stringify(ptr_to_local(&ctx), ptr_to_local(&val), ptr_to_local(&gap)));
1735 | }
1736 |
1737 | // Misc.
1738 |
1739 | void v8__base__SetDcheckFunction(void (*func)(const char*, int, const char*)) {
1740 | v8::base::SetDcheckFunction(func);
1741 | }
1742 |
1743 | // CpuProfiler
1744 | // -----------
1745 |
1746 | v8::CpuProfiler* v8__CpuProfiler__Get(v8::Isolate* isolate) {
1747 | return v8::CpuProfiler::New(isolate);
1748 | }
1749 |
1750 | void v8__CpuProfiler__StartProfiling(v8::CpuProfiler* self, const v8::String& title) {
1751 | self->StartProfiling(ptr_to_local(&title), true);
1752 | }
1753 |
1754 | const v8::CpuProfile* v8__CpuProfiler__StopProfiling(v8::CpuProfiler* self, const v8::String& title) {
1755 | return self->StopProfiling(ptr_to_local(&title));
1756 | }
1757 |
1758 | void v8__CpuProfiler__UseDetailedSourcePositionsForProfiling(v8::Isolate* isolate) {
1759 | v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
1760 | }
1761 |
1762 | void v8__CpuProfile__Delete(const v8::CpuProfile* self) {
1763 | const_cast(self)->Delete();
1764 | }
1765 |
1766 | const v8::CpuProfileNode* v8__CpuProfile__GetTopDownRoot(const v8::CpuProfile* self) {
1767 | return self->GetTopDownRoot();
1768 | }
1769 |
1770 | // Custom OutputStream that collects output into a string
1771 | class StringOutputStream : public v8::OutputStream {
1772 | public:
1773 | void EndOfStream() override {}
1774 |
1775 | int GetChunkSize() override {
1776 | return 1024 * 1024; // 1MB chunks
1777 | }
1778 |
1779 | v8::OutputStream::WriteResult WriteAsciiChunk(char* data, int size) override {
1780 | buffer_.append(data, size);
1781 | return v8::OutputStream::kContinue;
1782 | }
1783 |
1784 | const std::string& str() const { return buffer_; }
1785 |
1786 | private:
1787 | std::string buffer_;
1788 | };
1789 |
1790 | const v8::String* v8__CpuProfile__Serialize(const v8::CpuProfile* self, v8::Isolate* isolate) {
1791 | StringOutputStream stream;
1792 | self->Serialize(&stream);
1793 | return maybe_local_to_ptr(
1794 | v8::String::NewFromUtf8(isolate, stream.str().c_str(), v8::NewStringType::kNormal, stream.str().length())
1795 | );
1796 | }
1797 |
1798 | // Inspector
1799 | // ---------
1800 |
1801 | // v8 inspector is not really documented and not easy.
1802 | // Sources:
1803 | // - https://v8.dev/docs/inspector
1804 | // - C++ doc https://v8.github.io/api/head/namespacev8__inspector.html
1805 | // - Rusty (Deno) bindings https://github.com/denoland/rusty_v8/blob/main/src/binding.cc
1806 | // - https://github.com/ahmadov/v8_inspector_example
1807 | // - https://web.archive.org/web/20210918052901/http://hyperandroid.com/2020/02/12/v8-inspector-from-an-embedder-standpoint
1808 |
1809 | // Utils
1810 |
1811 | extern "C" typedef struct {
1812 | const char *ptr;
1813 | uint64_t len;
1814 | } CZigString;
1815 |
1816 | /// Header for Zig
1817 | /// Allocates `bytes` bytes of memory using the allocator.
1818 | /// @param allocator: A Zig std.mem.Allocator
1819 | /// @param bytes: The number of bytes to allocate
1820 | /// @returns A pointer to the allocated memory, null if allocation failed
1821 | char* zigAlloc(const void* allocator, uint64_t bytes);
1822 |
1823 | static inline v8_inspector::StringView toStringView(const char *str, size_t length) {
1824 | auto* stringView = reinterpret_cast(str);
1825 | return { stringView, length };
1826 | }
1827 | /// Overload for safety in case the function is called with a string literal
1828 | static inline v8_inspector::StringView toStringView(const char *str) {
1829 | size_t length = strlen(str);
1830 | auto* stringView = reinterpret_cast(str);
1831 | return { stringView, length };
1832 | }
1833 | static inline v8_inspector::StringView toStringView(const std::string &str) {
1834 | return toStringView(str.c_str(), str.length());
1835 | }
1836 |
1837 | static inline std::string fromStringView(v8::Isolate* isolate, const v8_inspector::StringView stringView) {
1838 | int length = static_cast(stringView.length());
1839 | v8::Local message = (
1840 | stringView.is8Bit()
1841 | ? v8::String::NewFromOneByte(isolate, stringView.characters8(), v8::NewStringType::kNormal, length)
1842 | : v8::String::NewFromTwoByte(isolate, stringView.characters16(), v8::NewStringType::kNormal, length)
1843 | ).ToLocalChecked();
1844 | v8::String::Utf8Value result(isolate, message);
1845 | return *result;
1846 | }
1847 |
1848 | /// Allocates a string as utf8 on the allocator without \0 terminator, for use in Zig.
1849 | /// The strings pointer and length should therefore be returned together
1850 | /// @param input: The string contents to allocate
1851 | /// @param allocator: A Zig std.mem.Allocator
1852 | /// @param output: Points to the now allocated string on the heap (without sentinel \0), NULL if view was null, invalid if allocation failed
1853 | /// @returns false if allocation errored
1854 | bool allocString(const v8_inspector::StringView& input, const void* allocator, CZigString& output) {
1855 | output.ptr = nullptr;
1856 | output.len = 0;
1857 | if (input.characters8() == nullptr) {
1858 | return true;
1859 | }
1860 |
1861 | std::string utf8_str;
1862 | if (input.is8Bit()) {
1863 | output.len = input.length();
1864 | } else {
1865 | utf8_str = v8_inspector::UTF16ToUTF8(reinterpret_cast(input.characters16()), input.length());
1866 | output.len = utf8_str.length();
1867 | }
1868 |
1869 | char* heap_str = zigAlloc(allocator, output.len);
1870 | if (heap_str == nullptr) {
1871 | return false;
1872 | }
1873 |
1874 | if (input.is8Bit()) {
1875 | memcpy(heap_str, input.characters8(), output.len);
1876 | } else {
1877 | memcpy(heap_str, utf8_str.c_str(), output.len);
1878 | }
1879 | output.ptr = heap_str;
1880 | return true;
1881 | }
1882 |
1883 |
1884 | // Inspector
1885 |
1886 | v8_inspector::V8Inspector *v8_inspector__Inspector__Create(
1887 | v8::Isolate* isolate, v8_inspector__Client__IMPL *client) {
1888 | std::unique_ptr u =
1889 | v8_inspector::V8Inspector::create(isolate, client);
1890 | return u.release();
1891 | }
1892 | void v8_inspector__Inspector__DELETE(v8_inspector::V8Inspector* self) {
1893 | delete self;
1894 | }
1895 | v8_inspector::V8InspectorSession *v8_inspector__Inspector__Connect(
1896 | v8_inspector::V8Inspector *self, int contextGroupId,
1897 | v8_inspector__Channel__IMPL *channel,
1898 | v8_inspector::V8Inspector::ClientTrustLevel client_trust_level) {
1899 | auto state = v8_inspector::StringView();
1900 | std::unique_ptr u =
1901 | self->connect(contextGroupId, channel, state, client_trust_level);
1902 | return u.release();
1903 | }
1904 | void v8_inspector__Inspector__ContextCreated(v8_inspector::V8Inspector *self,
1905 | const char *name, int name_len,
1906 | const char *origin, int origin_len,
1907 | const char *auxData, int auxData_len,
1908 | int contextGroupId,
1909 | const v8::Context &ctx) {
1910 | // create context info
1911 | std::string name_str;
1912 | name_str.assign(name, name_len);
1913 | v8_inspector::StringView name_view(toStringView(name_str));
1914 | auto context = ptr_to_local(&ctx);
1915 | v8_inspector::V8ContextInfo info(context, contextGroupId, name_view);
1916 |
1917 | // add origin to context info
1918 | std::string origin_str;
1919 | origin_str.assign(origin, origin_len);
1920 | info.origin = toStringView(origin_str);
1921 |
1922 | // add auxData to context info
1923 | std::string auxData_str;
1924 | auxData_str.assign(auxData, auxData_len);
1925 | info.auxData = toStringView(auxData_str);
1926 |
1927 | // call contextCreated
1928 | self->contextCreated(info);
1929 | }
1930 |
1931 | // InspectorSession
1932 |
1933 | void v8_inspector__Session__DELETE(v8_inspector::V8InspectorSession* self) {
1934 | delete self;
1935 | }
1936 |
1937 | void v8_inspector__Session__dispatchProtocolMessage(
1938 | v8_inspector::V8InspectorSession *session, v8::Isolate *isolate,
1939 | const char *msg, int msg_len) {
1940 | auto str_view = toStringView(msg, msg_len);
1941 | session->dispatchProtocolMessage(str_view);
1942 | }
1943 |
1944 | v8_inspector::protocol::Runtime::RemoteObject* v8_inspector__Session__wrapObject(
1945 | v8_inspector::V8InspectorSession *session, v8::Isolate *isolate,
1946 | const v8::Context* ctx, const v8::Value* val,
1947 | const char *grpname, int grpname_len, bool generatepreview) {
1948 | auto sv_grpname = toStringView(grpname, grpname_len);
1949 | auto remote_object = session->wrapObject(ptr_to_local(ctx), ptr_to_local(val), sv_grpname, generatepreview);
1950 | return static_cast(remote_object.release());
1951 | }
1952 |
1953 | bool v8_inspector__Session__unwrapObject(
1954 | v8_inspector::V8InspectorSession *session,
1955 | const void *allocator,
1956 | CZigString &out_error,
1957 | CZigString in_objectId,
1958 | v8::Local &out_value,
1959 | v8::Local &out_context,
1960 | CZigString &out_objectGroup
1961 | ) {
1962 | auto objectId = toStringView(in_objectId.ptr, in_objectId.len);
1963 | auto error = v8_inspector::StringBuffer::create({});
1964 | auto objectGroup = v8_inspector::StringBuffer::create({});
1965 |
1966 | // [out optional ] std::unique_ptr* error,
1967 | // [in required ] StringView objectId,
1968 | // [out required ] v8::Local * value
1969 | // [out required ] v8::Local * context
1970 | // [out optional ] std::unique_ptr* objectGroup
1971 | bool result = session->unwrapObject(&error, objectId, &out_value, &out_context, &objectGroup);
1972 | if (!result) {
1973 | allocString(error->string(), allocator, out_error);
1974 | return false;
1975 | }
1976 | return allocString(objectGroup->string(), allocator, out_objectGroup);
1977 | }
1978 |
1979 | // RemoteObject
1980 |
1981 | // To prevent extra allocations on every call a single default value is reused everytime.
1982 | // It is expected that the precense of a value is checked before calling get* methods.
1983 | const v8_inspector::String16 DEFAULT_STRING = {"default"};
1984 |
1985 | void v8_inspector__RemoteObject__DELETE(v8_inspector::protocol::Runtime::RemoteObject* self) {
1986 | delete self;
1987 | }
1988 |
1989 | // RemoteObject - Type
1990 | bool v8_inspector__RemoteObject__getType(v8_inspector::protocol::Runtime::RemoteObject* self, const void* allocator, CZigString &out_type) {
1991 | auto str = self->getType();
1992 | return allocString(toStringView(str), allocator, out_type);
1993 | }
1994 | void v8_inspector__RemoteObject__setType(v8_inspector::protocol::Runtime::RemoteObject* self, CZigString type) {
1995 | self->setType(v8_inspector::String16::fromUTF8(type.ptr, type.len));
1996 | }
1997 |
1998 | // RemoteObject - Subtype
1999 | bool v8_inspector__RemoteObject__hasSubtype(v8_inspector::protocol::Runtime::RemoteObject* self) {
2000 | return self->hasSubtype();
2001 | }
2002 | bool v8_inspector__RemoteObject__getSubtype(v8_inspector::protocol::Runtime::RemoteObject* self, const void* allocator, CZigString &subtype) {
2003 | auto str = self->getSubtype(DEFAULT_STRING);
2004 | return allocString(toStringView(str), allocator, subtype);
2005 | }
2006 | void v8_inspector__RemoteObject__setSubtype(v8_inspector::protocol::Runtime::RemoteObject* self, CZigString subtype) {
2007 | self->setSubtype(v8_inspector::String16::fromUTF8(subtype.ptr, subtype.len));
2008 | }
2009 |
2010 | // RemoteObject - ClassName
2011 | bool v8_inspector__RemoteObject__hasClassName(v8_inspector::protocol::Runtime::RemoteObject* self) {
2012 | return self->hasClassName();
2013 | }
2014 | bool v8_inspector__RemoteObject__getClassName(v8_inspector::protocol::Runtime::RemoteObject* self, const void* allocator, CZigString &className) {
2015 | auto str = self->getClassName(DEFAULT_STRING);
2016 | return allocString(toStringView(str), allocator, className);
2017 | }
2018 | void v8_inspector__RemoteObject__setClassName(v8_inspector::protocol::Runtime::RemoteObject* self, CZigString className) {
2019 | self->setClassName(v8_inspector::String16::fromUTF8(className.ptr, className.len));
2020 | }
2021 |
2022 | // RemoteObject - Value
2023 | bool v8_inspector__RemoteObject__hasValue(v8_inspector::protocol::Runtime::RemoteObject* self) {
2024 | return self->hasValue();
2025 | }
2026 | v8_inspector::protocol::Value* v8_inspector__RemoteObject__getValue(v8_inspector::protocol::Runtime::RemoteObject* self) {
2027 | return self->getValue(nullptr);
2028 | }
2029 | void v8_inspector__RemoteObject__setValue(v8_inspector::protocol::Runtime::RemoteObject* self, v8_inspector::protocol::Value* value) {
2030 | self->setValue(std::unique_ptr(value));
2031 | }
2032 |
2033 | // RemoteObject - UnserializableValue
2034 | bool v8_inspector__RemoteObject__hasUnserializableValue(v8_inspector::protocol::Runtime::RemoteObject* self) {
2035 | return self->hasUnserializableValue();
2036 | }
2037 | bool v8_inspector__RemoteObject__getUnserializableValue(v8_inspector::protocol::Runtime::RemoteObject* self, const void* allocator, CZigString &unserializableValue) {
2038 | auto str = self->getUnserializableValue(DEFAULT_STRING);
2039 | return allocString(toStringView(str), allocator, unserializableValue);
2040 | }
2041 | void v8_inspector__RemoteObject__setUnserializableValue(v8_inspector::protocol::Runtime::RemoteObject* self, CZigString unserializableValue) {
2042 | self->setUnserializableValue(v8_inspector::String16::fromUTF8(unserializableValue.ptr, unserializableValue.len));
2043 | }
2044 |
2045 | // RemoteObject - Description
2046 | bool v8_inspector__RemoteObject__hasDescription(v8_inspector::protocol::Runtime::RemoteObject* self) {
2047 | return self->hasDescription();
2048 | }
2049 | bool v8_inspector__RemoteObject__getDescription(v8_inspector::protocol::Runtime::RemoteObject* self, const void* allocator, CZigString &description) {
2050 | auto str = self->getDescription(DEFAULT_STRING);
2051 | return allocString(toStringView(str), allocator, description);
2052 | }
2053 | void v8_inspector__RemoteObject__setDescription(v8_inspector::protocol::Runtime::RemoteObject* self, CZigString description) {
2054 | self->setDescription(v8_inspector::String16::fromUTF8(description.ptr, description.len));
2055 | }
2056 |
2057 | // RemoteObject - ObjectId
2058 | bool v8_inspector__RemoteObject__hasObjectId(v8_inspector::protocol::Runtime::RemoteObject* self) {
2059 | return self->hasObjectId();
2060 | }
2061 |
2062 | bool v8_inspector__RemoteObject__getObjectId(v8_inspector::protocol::Runtime::RemoteObject* self, const void* allocator, CZigString &objectId) {
2063 | auto str = self->getObjectId(DEFAULT_STRING);
2064 | return allocString(toStringView(str), allocator, objectId);
2065 | }
2066 | void v8_inspector__RemoteObject__setObjectId(v8_inspector::protocol::Runtime::RemoteObject* self, CZigString objectId) {
2067 | self->setObjectId(v8_inspector::String16::fromUTF8(objectId.ptr, objectId.len));
2068 | }
2069 |
2070 | // RemoteObject - Preview
2071 | bool v8_inspector__RemoteObject__hasPreview(v8_inspector::protocol::Runtime::RemoteObject* self) {
2072 | return self->hasPreview();
2073 | }
2074 | const v8_inspector::protocol::Runtime::ObjectPreview* v8_inspector__RemoteObject__getPreview(v8_inspector::protocol::Runtime::RemoteObject* self) {
2075 | return self->getPreview(nullptr);
2076 | }
2077 | void v8_inspector__RemoteObject__setPreview(v8_inspector::protocol::Runtime::RemoteObject* self, v8_inspector::protocol::Runtime::ObjectPreview* preview) {
2078 | self->setPreview(std::unique_ptr(preview));
2079 | }
2080 |
2081 | // RemoteObject - CustomPreview
2082 | bool v8_inspector__RemoteObject__hasCustomPreview(v8_inspector::protocol::Runtime::RemoteObject* self) {
2083 | return self->hasCustomPreview();
2084 | }
2085 | const v8_inspector::protocol::Runtime::CustomPreview* v8_inspector__RemoteObject__getCustomPreview(v8_inspector::protocol::Runtime::RemoteObject* self) {
2086 | return self->getCustomPreview(nullptr);
2087 | }
2088 | void v8_inspector__RemoteObject__setCustomPreview(v8_inspector::protocol::Runtime::RemoteObject* self, v8_inspector::protocol::Runtime::CustomPreview* customPreview) {
2089 | self->setCustomPreview(std::unique_ptr(customPreview));
2090 | }
2091 |
2092 | // InspectorChannel
2093 |
2094 | v8_inspector__Channel__IMPL * v8_inspector__Channel__IMPL__CREATE(v8::Isolate *isolate) {
2095 | auto channel = new v8_inspector__Channel__IMPL();
2096 | channel->isolate = isolate;
2097 | return channel;
2098 | }
2099 | void v8_inspector__Channel__IMPL__DELETE(v8_inspector__Channel__IMPL *self) {
2100 | delete self;
2101 | }
2102 | void v8_inspector__Channel__IMPL__SET_DATA(v8_inspector__Channel__IMPL *self, void *data) {
2103 | self->data = data;
2104 | }
2105 |
2106 | // declaration of functions implementations
2107 | // NOTE: zig project should provide those implementations with C-ABI functions
2108 | void v8_inspector__Channel__IMPL__sendResponse(
2109 | v8_inspector__Channel__IMPL* self, void* data,
2110 | int callId, const char* message, size_t length);
2111 | void v8_inspector__Channel__IMPL__sendNotification(
2112 | v8_inspector__Channel__IMPL* self, void *data,
2113 | const char* msg, size_t length);
2114 | void v8_inspector__Channel__IMPL__flushProtocolNotifications(
2115 | v8_inspector__Channel__IMPL* self, void *data);
2116 |
2117 | // c++ implementation (just wrappers around the C/zig functions)
2118 | } // extern "C"
2119 | void v8_inspector__Channel__IMPL::sendResponse(
2120 | int callId, std::unique_ptr message) {
2121 | const std::string resp = fromStringView(this->isolate, message->string());
2122 | return v8_inspector__Channel__IMPL__sendResponse(this, this->data, callId, resp.c_str(), resp.length());
2123 | }
2124 | void v8_inspector__Channel__IMPL::sendNotification(
2125 | std::unique_ptr message) {
2126 | const std::string notif = fromStringView(this->isolate, message->string());
2127 | return v8_inspector__Channel__IMPL__sendNotification(this, this->data, notif.c_str(), notif.length());
2128 | }
2129 | void v8_inspector__Channel__IMPL::flushProtocolNotifications() {
2130 | return v8_inspector__Channel__IMPL__flushProtocolNotifications(this, this->data);
2131 | }
2132 |
2133 | extern "C" {
2134 |
2135 | // wrappers for the public API Interface
2136 | // NOTE: not sure it's useful to expose those
2137 | void v8_inspector__Channel__sendResponse(
2138 | v8_inspector::V8Inspector::Channel* self, int callId,
2139 | v8_inspector::StringBuffer* message) {
2140 | self->sendResponse(
2141 | callId,
2142 | static_cast>(message));
2143 | }
2144 | void v8_inspector__Channel__sendNotification(
2145 | v8_inspector::V8Inspector::Channel* self,
2146 | v8_inspector::StringBuffer* message) {
2147 | self->sendNotification(
2148 | static_cast>(message));
2149 | }
2150 | void v8_inspector__Channel__flushProtocolNotifications(
2151 | v8_inspector::V8Inspector::Channel* self) {
2152 | self->flushProtocolNotifications();
2153 | }
2154 |
2155 | // InspectorClient
2156 |
2157 | v8_inspector__Client__IMPL *v8_inspector__Client__IMPL__CREATE() {
2158 | return new v8_inspector__Client__IMPL();
2159 | }
2160 | void v8_inspector__Client__IMPL__DELETE(v8_inspector__Client__IMPL *self) {
2161 | delete self;
2162 | }
2163 | void v8_inspector__Client__IMPL__SET_DATA(v8_inspector__Client__IMPL *self, void *data) {
2164 | self->data = data;
2165 | }
2166 |
2167 | // declaration of functions implementations
2168 | // NOTE: zig project should provide those implementations with C-like functions
2169 | int64_t v8_inspector__Client__IMPL__generateUniqueId(v8_inspector__Client__IMPL* self, void* data);
2170 | void v8_inspector__Client__IMPL__runMessageLoopOnPause(
2171 | v8_inspector__Client__IMPL *self,
2172 | void* data, int contextGroupId);
2173 | void v8_inspector__Client__IMPL__quitMessageLoopOnPause(v8_inspector__Client__IMPL* self, void* data);
2174 | void v8_inspector__Client__IMPL__runIfWaitingForDebugger(
2175 | v8_inspector__Client__IMPL* self, void* data, int contextGroupId);
2176 | void v8_inspector__Client__IMPL__consoleAPIMessage(
2177 | v8_inspector__Client__IMPL* self, void* data, int contextGroupId,
2178 | v8::Isolate::MessageErrorLevel level,
2179 | const v8_inspector::StringView &message,
2180 | const v8_inspector::StringView &url, unsigned lineNumber,
2181 | unsigned columnNumber, v8_inspector::V8StackTrace *stackTrace);
2182 | const v8::Context* v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
2183 | v8_inspector__Client__IMPL* self, void* data, int contextGroupId);
2184 | char* v8_inspector__Client__IMPL__valueSubtype(
2185 | v8_inspector__Client__IMPL* self, v8::Local value);
2186 | char* v8_inspector__Client__IMPL__descriptionForValueSubtype(
2187 | v8_inspector__Client__IMPL* self, v8::Local context, v8::Local value);
2188 |
2189 | // c++ implementation (just wrappers around the c/zig functions)
2190 | } // extern "C"
2191 | int64_t v8_inspector__Client__IMPL::generateUniqueId() {
2192 | return v8_inspector__Client__IMPL__generateUniqueId(this, this->data);
2193 | }
2194 | void v8_inspector__Client__IMPL::runMessageLoopOnPause(int contextGroupId) {
2195 | return v8_inspector__Client__IMPL__runMessageLoopOnPause(this, this->data, contextGroupId);
2196 | }
2197 | void v8_inspector__Client__IMPL::quitMessageLoopOnPause() {
2198 | return v8_inspector__Client__IMPL__quitMessageLoopOnPause(this, this->data);
2199 | }
2200 | void v8_inspector__Client__IMPL::runIfWaitingForDebugger(int contextGroupId) {
2201 | return v8_inspector__Client__IMPL__runIfWaitingForDebugger(this, this->data, contextGroupId);
2202 | }
2203 | void v8_inspector__Client__IMPL::consoleAPIMessage(
2204 | int contextGroupId, v8::Isolate::MessageErrorLevel level,
2205 | const v8_inspector::StringView &message,
2206 | const v8_inspector::StringView &url, unsigned lineNumber,
2207 | unsigned columnNumber, v8_inspector::V8StackTrace *stackTrace) {
2208 | return v8_inspector__Client__IMPL__consoleAPIMessage(
2209 | this, this->data, contextGroupId, level, message, url, lineNumber,
2210 | columnNumber, stackTrace);
2211 | }
2212 | v8::Local v8_inspector__Client__IMPL::ensureDefaultContextInGroup(int contextGroupId) {
2213 | return ptr_to_local(v8_inspector__Client__IMPL__ensureDefaultContextInGroup(this, this->data, contextGroupId));
2214 | }
2215 | std::unique_ptr v8_inspector__Client__IMPL::valueSubtype(v8::Local value) {
2216 | auto subType = v8_inspector__Client__IMPL__valueSubtype(this, value);
2217 | if (subType == nullptr) {
2218 | return nullptr;
2219 | }
2220 | return v8_inspector::StringBuffer::create(toStringView(subType));
2221 | }
2222 | std::unique_ptr v8_inspector__Client__IMPL::descriptionForValueSubtype(v8::Local context, v8::Local value) {
2223 | auto description = v8_inspector__Client__IMPL__descriptionForValueSubtype(this, context, value);
2224 | if (description == nullptr) {
2225 | return nullptr;
2226 | }
2227 | return v8_inspector::StringBuffer::create(toStringView(description));
2228 | }
2229 |
2230 | extern "C" {
2231 |
2232 | // wrappers for the public API Interface
2233 | // NOTE: not sure it's useful to expose those
2234 | int64_t v8_inspector__Client__generateUniqueId(
2235 | v8_inspector::V8InspectorClient *self) {
2236 | return self->generateUniqueId();
2237 | }
2238 | void v8_inspector__Client__runMessageLoopOnPause(
2239 | v8_inspector::V8InspectorClient* self, int contextGroupId) {
2240 | self->runMessageLoopOnPause(contextGroupId);
2241 | }
2242 | void v8_inspector__Client__quitMessageLoopOnPause(
2243 | v8_inspector::V8InspectorClient* self) {
2244 | self->quitMessageLoopOnPause();
2245 | }
2246 | void v8_inspector__Client__runIfWaitingForDebugger(
2247 | v8_inspector::V8InspectorClient* self, int contextGroupId) {
2248 | self->runIfWaitingForDebugger(contextGroupId);
2249 | }
2250 | void v8_inspector__Client__consoleAPIMessage(
2251 | v8_inspector::V8InspectorClient* self, int contextGroupId,
2252 | v8::Isolate::MessageErrorLevel level,
2253 | const v8_inspector::StringView& message,
2254 | const v8_inspector::StringView& url, unsigned lineNumber,
2255 | unsigned columnNumber, v8_inspector::V8StackTrace* stackTrace) {
2256 | self->consoleAPIMessage(contextGroupId, level, message, url, lineNumber,
2257 | columnNumber, stackTrace);
2258 | }
2259 |
2260 | } // extern "C"
2261 |
--------------------------------------------------------------------------------
/src/binding.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | typedef uintptr_t usize;
6 | typedef struct Data Data;
7 | typedef struct ArrayBufferAllocator ArrayBufferAllocator;
8 | typedef struct CreateParams CreateParams;
9 | typedef struct Isolate Isolate;
10 | typedef struct StackTrace StackTrace;
11 | typedef struct StackFrame StackFrame;
12 | typedef struct FixedArray FixedArray;
13 | typedef struct Module Module;
14 | typedef struct FunctionTemplate FunctionTemplate;
15 | typedef struct Message Message;
16 | typedef struct Context Context;
17 | // Internally, all Value types have a base InternalAddress struct.
18 | typedef uintptr_t InternalAddress;
19 | // Super type.
20 | typedef Data Value;
21 | typedef Value Object;
22 | typedef Value String;
23 | typedef Value Function;
24 | typedef Value Number;
25 | typedef Value Primitive;
26 | typedef Value Integer;
27 | typedef Value BigInt;
28 | typedef Value Array;
29 | typedef Value Uint8ClampedArray;
30 | typedef Value Uint8Array;
31 | typedef Value Int8Array;
32 | typedef Value Uint16Array;
33 | typedef Value Int16Array;
34 | typedef Value Uint32Array;
35 | typedef Value Int32Array;
36 | typedef Value BigUint64Array;
37 | typedef Value BigInt64Array;
38 | typedef Value Float16Array;
39 | typedef Value Float32Array;
40 | typedef Value Float64Array;
41 | typedef Value ArrayBuffer;
42 | typedef Value ArrayBufferView;
43 | typedef Value External;
44 | typedef Value Symbol;
45 | typedef Value Boolean;
46 | typedef Value Promise;
47 | typedef Value Name;
48 | typedef Value PromiseResolver;
49 | typedef enum CompileOptions {
50 | kNoCompileOptions = 0,
51 | kConsumeCodeCache = 1,
52 | kEagerCompile = 2,
53 | } CompileOptions;
54 | typedef enum NoCacheReason {
55 | kNoCacheNoReason = 0,
56 | kNoCacheBecauseCachingDisabled,
57 | kNoCacheBecauseNoResource,
58 | kNoCacheBecauseInlineScript,
59 | kNoCacheBecauseModule,
60 | kNoCacheBecauseStreamingSource,
61 | kNoCacheBecauseInspector,
62 | kNoCacheBecauseScriptTooSmall,
63 | kNoCacheBecauseCacheTooCold,
64 | kNoCacheBecauseV8Extension,
65 | kNoCacheBecauseExtensionModule,
66 | kNoCacheBecausePacScript,
67 | kNoCacheBecauseInDocumentWrite,
68 | kNoCacheBecauseResourceWithNoCacheHandler,
69 | kNoCacheBecauseDeferredProduceCodeCache
70 | } NoCacheReason;
71 | typedef enum PromiseRejectEvent {
72 | kPromiseRejectWithNoHandler = 0,
73 | kPromiseHandlerAddedAfterReject = 1,
74 | kPromiseRejectAfterResolved = 2,
75 | kPromiseResolveAfterResolved = 3,
76 | } PromiseRejectEvent;
77 | typedef struct PromiseRejectMessage PromiseRejectMessage;
78 | typedef void (*PromiseRejectCallback)(PromiseRejectMessage);
79 | typedef Promise* (*HostImportModuleDynamicallyCallback)(Context*, Data*, Value*, String*, FixedArray*);
80 | typedef void (*HostInitializeImportMetaObjectCallback)(Context*, Module*, Data*);
81 | typedef enum MessageErrorLevel {
82 | kMessageLog = (1 << 0),
83 | kMessageDebug = (1 << 1),
84 | kMessageInfo = (1 << 2),
85 | kMessageError = (1 << 3),
86 | kMessageWarning = (1 << 4),
87 | kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
88 | kMessageWarning,
89 | } MessageErrorLevel;
90 | typedef void (*MessageCallback)(const Message* message, const Value* data);
91 | typedef usize UniquePtr;
92 | typedef struct SharedPtr {
93 | usize a;
94 | usize b;
95 | } SharedPtr;
96 | typedef uintptr_t IntAddress; // v8::internal::Address
97 |
98 | typedef struct MaybeU32 {
99 | bool has_value;
100 | uint32_t value;
101 | } MaybeU32;
102 | typedef struct MaybeI32 {
103 | bool has_value;
104 | int32_t value;
105 | } MaybeI32;
106 | typedef struct MaybeF64 {
107 | bool has_value;
108 | double value;
109 | } MaybeF64;
110 | typedef struct MaybeBool {
111 | bool has_value;
112 | bool value;
113 | } MaybeBool;
114 | typedef enum PropertyAttribute {
115 | /** None. **/
116 | None = 0,
117 | /** ReadOnly, i.e., not writable. **/
118 | ReadOnly = 1 << 0,
119 | /** DontEnum, i.e., not enumerable. **/
120 | DontEnum = 1 << 1,
121 | /** DontDelete, i.e., not configurable. **/
122 | DontDelete = 1 << 2
123 | } PropertyAttribute;
124 |
125 | // Platform
126 | typedef struct Platform Platform;
127 | Platform* v8__Platform__NewDefaultPlatform(int thread_pool_size, int idle_task_support);
128 | void v8__Platform__DELETE(Platform* platform);
129 | bool v8__Platform__PumpMessageLoop(Platform* platform, Isolate* isolate, bool wait_for_work);
130 | void v8__Platform__RunIdleTasks(Platform* platform, Isolate* isolate, double idle_time_in_seconds);
131 |
132 | // Root
133 | const Primitive* v8__Undefined(Isolate* isolate);
134 | const Primitive* v8__Null(Isolate* isolate);
135 | const Boolean* v8__True(Isolate* isolate);
136 | const Boolean* v8__False(Isolate* isolate);
137 | const Uint8ClampedArray* v8__Uint8ClampedArray__New(
138 | const ArrayBuffer* buf,
139 | size_t byte_offset,
140 | size_t length);
141 |
142 | const Uint8Array* v8__Uint8Array__New(
143 | const ArrayBuffer* buf,
144 | size_t byte_offset,
145 | size_t length);
146 |
147 | const Int8Array* v8__Int8Array__New(
148 | const ArrayBuffer* buf,
149 | size_t byte_offset,
150 | size_t length);
151 |
152 | const Uint16Array* v8__Uint16Array__New(
153 | const ArrayBuffer* buf,
154 | size_t byte_offset,
155 | size_t length);
156 |
157 | const Int16Array* v8__Int16Array__New(
158 | const ArrayBuffer* buf,
159 | size_t byte_offset,
160 | size_t length);
161 |
162 | const Uint32Array* v8__Uint32Array__New(
163 | const ArrayBuffer* buf,
164 | size_t byte_offset,
165 | size_t length);
166 |
167 | const Int32Array* v8__Int32Array__New(
168 | const ArrayBuffer* buf,
169 | size_t byte_offset,
170 | size_t length);
171 |
172 | const Float16Array* v8__Float16Array__New(
173 | const ArrayBuffer* buf,
174 | size_t byte_offset,
175 | size_t length);
176 |
177 | const Float32Array* v8__Float32Array__New(
178 | const ArrayBuffer* buf,
179 | size_t byte_offset,
180 | size_t length);
181 |
182 | const Float64Array* v8__Float64Array__New(
183 | const ArrayBuffer* buf,
184 | size_t byte_offset,
185 | size_t length);
186 |
187 | const BigUint64Array* v8__BigUint64Array__New(
188 | const ArrayBuffer* buf,
189 | size_t byte_offset,
190 | size_t length);
191 |
192 | const BigInt64Array* v8__BigInt64Array__New(
193 | const ArrayBuffer* buf,
194 | size_t byte_offset,
195 | size_t length);
196 |
197 | // V8
198 | void v8__V8__InitializePlatform(Platform* platform);
199 | void v8__V8__Initialize();
200 | bool v8__V8__InitializeICU();
201 | int v8__V8__Dispose();
202 | void v8__V8__DisposePlatform();
203 | const char* v8__V8__GetVersion();
204 |
205 | // Microtask
206 | typedef enum MicrotasksPolicy { kExplicit, kScoped, kAuto } MicrotasksPolicy;
207 |
208 | // Isolate
209 | Isolate* v8__Isolate__New(CreateParams* params);
210 | void v8__Isolate__Enter(Isolate* isolate);
211 | void v8__Isolate__Exit(Isolate* isolate);
212 | void v8__Isolate__Dispose(Isolate* isolate);
213 | Context* v8__Isolate__GetCurrentContext(Isolate* isolate);
214 | const Value* v8__Isolate__ThrowException(
215 | Isolate* isolate,
216 | const Value* exception);
217 | void v8__Isolate__SetHostImportModuleDynamicallyCallback(
218 | Isolate* isolate,
219 | HostImportModuleDynamicallyCallback callback);
220 | void v8__Isolate__SetHostInitializeImportMetaObjectCallback(
221 | Isolate* isolate,
222 | HostInitializeImportMetaObjectCallback callback);
223 | void v8__Isolate__SetPromiseRejectCallback(
224 | Isolate* isolate,
225 | PromiseRejectCallback callback);
226 | MicrotasksPolicy v8__Isolate__GetMicrotasksPolicy(const Isolate* self);
227 | void v8__Isolate__SetMicrotasksPolicy(
228 | Isolate* self,
229 | MicrotasksPolicy policy);
230 | void v8__Isolate__PerformMicrotaskCheckpoint(Isolate* self);
231 | bool v8__Isolate__AddMessageListener(
232 | Isolate* self,
233 | MessageCallback callback);
234 | bool v8__Isolate__AddMessageListenerWithErrorLevel(
235 | Isolate* self,
236 | MessageCallback callback,
237 | int message_levels,
238 | const Value* data);
239 | void v8__Isolate__SetCaptureStackTraceForUncaughtExceptions(
240 | Isolate* isolate,
241 | bool capture,
242 | int frame_limit);
243 | void v8__Isolate__TerminateExecution(Isolate* self);
244 | bool v8__Isolate__IsExecutionTerminating(Isolate* self);
245 | void v8__Isolate__CancelTerminateExecution(Isolate* self);
246 | void v8__Isolate__LowMemoryNotification(Isolate* self);
247 | typedef struct HeapStatistics {
248 | size_t total_heap_size;
249 | size_t total_heap_size_executable;
250 | size_t total_physical_size;
251 | size_t total_available_size;
252 | size_t used_heap_size;
253 | size_t heap_size_limit;
254 | size_t malloced_memory;
255 | size_t external_memory;
256 | size_t peak_malloced_memory;
257 | bool does_zap_garbage;
258 | size_t number_of_native_contexts;
259 | size_t number_of_detached_contexts;
260 | size_t total_global_handles_size;
261 | size_t used_global_handles_size;
262 | } HeapStatistics;
263 | void v8__Isolate__GetHeapStatistics(
264 | Isolate* self,
265 | HeapStatistics* stats);
266 | usize v8__HeapStatistics__SIZEOF();
267 | void* v8__Isolate__GetData(Isolate* self, int idx);
268 | void v8__Isolate__SetData(Isolate* self, int idx, void* val);
269 | typedef void (*MicrotaskCallback)(void* data);
270 | void v8__Isolate__EnqueueMicrotask(Isolate* self, MicrotaskCallback callback, void* data);
271 | void v8__Isolate__EnqueueMicrotaskFunc(Isolate* self, const Function* function);
272 |
273 | typedef struct StartupData {
274 | const char* data;
275 | int raw_size;
276 | } StartupData;
277 |
278 | typedef struct ResourceConstraints {
279 | usize code_range_size_;
280 | usize max_old_generation_size_;
281 | usize max_young_generation_size_;
282 | usize initial_old_generation_size_;
283 | usize initial_young_generation_size_;
284 | uint64_t physical_memory_size_;
285 | uint32_t* stack_limit_;
286 | } ResourceConstraints;
287 |
288 | typedef struct CreateParams {
289 | void* code_event_handler; // JitCodeEventHandler
290 | ResourceConstraints constraints;
291 | StartupData* snapshot_blob;
292 | void* counter_lookup_callback;
293 | void* create_histogram_callback; // CreateHistogramCallback
294 | void* add_histogram_sample_callback; // AddHistogramSampleCallback
295 | ArrayBufferAllocator* array_buffer_allocator;
296 | SharedPtr array_buffer_allocator_shared;
297 | const intptr_t* external_references;
298 | bool allow_atomics_wait;
299 | bool only_terminate_in_safe_scope;
300 | int embedder_wrapper_type_index;
301 | int embedder_wrapper_object_index;
302 | void* fatal_error_callback;
303 | void* oom_error_callback;
304 | void* cpp_heap;
305 | } CreateParams;
306 | usize v8__Isolate__CreateParams__SIZEOF();
307 | void v8__Isolate__CreateParams__CONSTRUCT(CreateParams* buf);
308 |
309 | // FixedArray
310 | int v8__FixedArray__Length(const FixedArray* self);
311 | const Data* v8__FixedArray__Get(
312 | const FixedArray* self,
313 | const Context* ctx,
314 | int idx);
315 |
316 | // ArrayBuffer
317 | typedef void (*PromiseRejectCallback)(PromiseRejectMessage);
318 | typedef void (*BackingStoreDeleterCallback)(void* data, size_t len, void* deleter_data);
319 | typedef struct BackingStore BackingStore;
320 | ArrayBufferAllocator* v8__ArrayBuffer__Allocator__NewDefaultAllocator();
321 | void v8__ArrayBuffer__Allocator__DELETE(ArrayBufferAllocator* self);
322 | BackingStore* v8__ArrayBuffer__NewBackingStore(
323 | Isolate* isolate,
324 | size_t byte_len);
325 | BackingStore* v8__ArrayBuffer__NewBackingStore2(
326 | void* data,
327 | size_t byte_len,
328 | BackingStoreDeleterCallback deleter,
329 | void* deleter_data);
330 | void* v8__BackingStore__Data(const BackingStore* self);
331 | size_t v8__BackingStore__ByteLength(const BackingStore* self);
332 | bool v8__BackingStore__IsShared(const BackingStore* self);
333 | SharedPtr v8__BackingStore__TO_SHARED_PTR(BackingStore* unique_ptr);
334 | void std__shared_ptr__v8__BackingStore__reset(SharedPtr* self);
335 | BackingStore* std__shared_ptr__v8__BackingStore__get(const SharedPtr* self);
336 | long std__shared_ptr__v8__BackingStore__use_count(const SharedPtr* self);
337 | const ArrayBuffer* v8__ArrayBuffer__New(Isolate* isolate, size_t byte_len);
338 | const ArrayBuffer* v8__ArrayBuffer__New2(Isolate* isolate, const SharedPtr* backing_store);
339 | size_t v8__ArrayBuffer__ByteLength(const ArrayBuffer* self);
340 | SharedPtr v8__ArrayBuffer__GetBackingStore(const ArrayBuffer* self);
341 |
342 | // ArrayBufferView
343 | const ArrayBuffer* v8__ArrayBufferView__Buffer(const ArrayBufferView* self);
344 | size_t v8__ArrayBufferView__ByteLength(const ArrayBufferView* self);
345 | size_t v8__ArrayBufferView__ByteOffset(const ArrayBufferView* self);
346 |
347 | // HandleScope
348 | typedef struct HandleScope {
349 | // internal vars.
350 | Isolate* isolate_;
351 | InternalAddress* prev_next_;
352 | InternalAddress* prev_limit_;
353 | } HandleScope;
354 | void v8__HandleScope__CONSTRUCT(HandleScope* buf, Isolate* isolate);
355 | void v8__HandleScope__DESTRUCT(HandleScope* scope);
356 |
357 | // Message
358 | const String* v8__Message__Get(const Message* self);
359 | const String* v8__Message__GetSourceLine(const Message* self, const Context* context);
360 | const Value* v8__Message__GetScriptResourceName(const Message* self);
361 | int v8__Message__GetLineNumber(const Message* self, const Context* context);
362 | int v8__Message__GetStartColumn(const Message* self);
363 | int v8__Message__GetEndColumn(const Message* self);
364 | const StackTrace* v8__Message__GetStackTrace(const Message* self);
365 |
366 | // TryCatch
367 | typedef struct TryCatch {
368 | void* isolate_;
369 | struct TryCatch* next_;
370 | void* exception_;
371 | void* message_obj_;
372 | IntAddress js_stack_comparable_address_;
373 | usize flags;
374 | } TryCatch;
375 | usize v8__TryCatch__SIZEOF();
376 | void v8__TryCatch__CONSTRUCT(TryCatch* buf, Isolate* isolate);
377 | void v8__TryCatch__DESTRUCT(TryCatch* self);
378 | const Value* v8__TryCatch__Exception(const TryCatch* self);
379 | const Message* v8__TryCatch__Message(const TryCatch* self);
380 | bool v8__TryCatch__HasCaught(const TryCatch* self);
381 | const Value* v8__TryCatch__StackTrace(const TryCatch* self, const Context* context);
382 | bool v8__TryCatch__IsVerbose(const TryCatch* self);
383 | void v8__TryCatch__SetVerbose(
384 | TryCatch* self,
385 | bool value);
386 | const Value* v8__TryCatch__ReThrow(TryCatch* self);
387 |
388 | // StackTrace
389 | int v8__StackTrace__GetFrameCount(const StackTrace* self);
390 | const StackFrame* v8__StackTrace__GetFrame(
391 | const StackTrace* self,
392 | Isolate* isolate,
393 | uint32_t idx);
394 | const StackTrace* v8__StackTrace__CurrentStackTrace__STATIC(Isolate* isolate, int frame_limit);
395 | const String* v8__StackTrace__CurrentScriptNameOrSourceURL__STATIC(Isolate* isolate);
396 |
397 | // StackFrame
398 | int v8__StackFrame__GetLineNumber(const StackFrame* self);
399 | int v8__StackFrame__GetColumn(const StackFrame* self);
400 | int v8__StackFrame__GetScriptId(const StackFrame* self);
401 | const String* v8__StackFrame__GetScriptName(const StackFrame* self);
402 | const String* v8__StackFrame__GetScriptNameOrSourceURL(const StackFrame* self);
403 | const String* v8__StackFrame__GetFunctionName(const StackFrame* self);
404 | bool v8__StackFrame__IsEval(const StackFrame* self);
405 | bool v8__StackFrame__IsConstructor(const StackFrame* self);
406 | bool v8__StackFrame__IsWasm(const StackFrame* self);
407 | bool v8__StackFrame__IsUserJavaScript(const StackFrame* self);
408 |
409 | // Context
410 | typedef struct Context Context;
411 | typedef struct ObjectTemplate ObjectTemplate;
412 | Context* v8__Context__New(Isolate* isolate, const ObjectTemplate* global_tmpl, const Value* global_obj);
413 | void v8__Context__Enter(const Context* context);
414 | void v8__Context__Exit(const Context* context);
415 | Isolate* v8__Context__GetIsolate(const Context* context);
416 | const Object* v8__Context__Global(const Context* self);
417 | const Value* v8__Context__GetEmbedderData(
418 | const Context* self,
419 | int idx);
420 | void v8__Context__SetEmbedderData(
421 | const Context* self,
422 | int idx,
423 | const Value* val);
424 | int v8__Context__DebugContextId(const Context* self);
425 |
426 | // Boolean
427 | const Boolean* v8__Boolean__New(
428 | Isolate* isolate,
429 | bool value);
430 |
431 | // String
432 | typedef enum NewStringType {
433 | /**
434 | * Create a new string, always allocating new storage memory.
435 | */
436 | kNormal,
437 |
438 | /**
439 | * Acts as a hint that the string should be created in the
440 | * old generation heap space and be deduplicated if an identical string
441 | * already exists.
442 | */
443 | kInternalized
444 | } NewStringType;
445 | typedef enum WriteOptions {
446 | NO_OPTIONS = 0,
447 | HINT_MANY_WRITES_EXPECTED = 1,
448 | NO_NULL_TERMINATION = 2,
449 | PRESERVE_ONE_BYTE_NULL = 4,
450 | // Used by WriteUtf8 to replace orphan surrogate code units with the
451 | // unicode replacement character. Needs to be set to guarantee valid UTF-8
452 | // output.
453 | REPLACE_INVALID_UTF8 = 8
454 | } WriteOptions;
455 | String* v8__String__NewFromUtf8(Isolate* isolate, const char* data, NewStringType type, int length);
456 | size_t v8__String__WriteUtf8(const String* str, Isolate* isolate, const char* buf, size_t len, WriteOptions options);
457 | int v8__String__Utf8Length(const String* str, Isolate* isolate);
458 |
459 | // Value
460 | String* v8__Value__TypeOf(
461 | const Value* self,
462 | Isolate* isolate);
463 | String* v8__Value__ToString(
464 | const Value* self,
465 | const Context* ctx);
466 | const String* v8__Value__ToDetailString(
467 | const Value* self,
468 | const Context* ctx);
469 | bool v8__Value__BooleanValue(
470 | const Value* self,
471 | Isolate* isolate);
472 | void v8__Value__Uint32Value(
473 | const Value* self,
474 | const Context* ctx,
475 | MaybeU32* out);
476 | void v8__Value__Int32Value(
477 | const Value* self,
478 | const Context* ctx,
479 | MaybeI32* out);
480 | void v8__Value__NumberValue(
481 | const Value* self,
482 | const Context* context,
483 | MaybeF64* out);
484 | bool v8__Value__IsFunction(const Value* self);
485 | bool v8__Value__IsAsyncFunction(const Value* self);
486 | bool v8__Value__IsPromise(const Value* self);
487 | bool v8__Value__IsBoolean(const Value* self);
488 | bool v8__Value__IsBooleanObject(const Value* self);
489 | bool v8__Value__IsInt32(const Value* self);
490 | bool v8__Value__IsUint32(const Value* self);
491 | bool v8__Value__IsNumber(const Value* self);
492 | bool v8__Value__IsNumberObject(const Value* self);
493 | bool v8__Value__IsObject(const Value* self);
494 | bool v8__Value__IsString(const Value* self);
495 | bool v8__Value__IsSymbol(const Value* self);
496 | bool v8__Value__IsArray(const Value* self);
497 | bool v8__Value__IsTypedArray(const Value* self);
498 | bool v8__Value__IsUint8ClampedArray(const Value* self);
499 | bool v8__Value__IsInt8Array(const Value* self);
500 | bool v8__Value__IsUint16Array(const Value* self);
501 | bool v8__Value__IsInt16Array(const Value* self);
502 | bool v8__Value__IsUint32Array(const Value* self);
503 | bool v8__Value__IsInt32Array(const Value* self);
504 | bool v8__Value__IsBigInt64Array(const Value* self);
505 | bool v8__Value__IsBigUint64Array(const Value* self);
506 | bool v8__Value__IsFloat32Array(const Value* self);
507 | bool v8__Value__IsFloat64Array(const Value* self);
508 | bool v8__Value__IsArrayBuffer(const Value* self);
509 | bool v8__Value__IsArrayBufferView(const Value* self);
510 | bool v8__Value__IsUint8Array(const Value* self);
511 | bool v8__Value__IsExternal(const Value* self);
512 | bool v8__Value__IsTrue(const Value* self);
513 | bool v8__Value__IsFalse(const Value* self);
514 | bool v8__Value__IsUndefined(const Value* self);
515 | bool v8__Value__IsNull(const Value* self);
516 | bool v8__Value__IsNullOrUndefined(const Value* self);
517 | bool v8__Value__IsNativeError(const Value* self);
518 | bool v8__Value__IsBigInt(const Value* self);
519 | bool v8__Value__IsBigIntObject(const Value* self);
520 | void v8__Value__InstanceOf(
521 | const Value* self,
522 | const Context* ctx,
523 | const Object* object,
524 | MaybeBool* out);
525 |
526 | // Promise
527 | typedef enum PromiseState { kPending, kFulfilled, kRejected } PromiseState;
528 | const PromiseResolver* v8__Promise__Resolver__New(
529 | const Context* ctx);
530 | const Promise* v8__Promise__Resolver__GetPromise(
531 | const PromiseResolver* self);
532 | void v8__Promise__Resolver__Resolve(
533 | const PromiseResolver* self,
534 | const Context* ctx,
535 | const Value* value,
536 | MaybeBool* out);
537 | void v8__Promise__Resolver__Reject(
538 | const PromiseResolver* self,
539 | const Context* ctx,
540 | const Value* value,
541 | MaybeBool* out);
542 | const Promise* v8__Promise__Catch(
543 | const Promise* self,
544 | const Context* ctx,
545 | const Function* handler);
546 | const Promise* v8__Promise__Then(
547 | const Promise* self,
548 | const Context* ctx,
549 | const Function* handler);
550 | const Promise* v8__Promise__Then2(
551 | const Promise* self,
552 | const Context* ctx,
553 | const Function* on_fulfilled,
554 | const Function* on_rejected);
555 | PromiseState v8__Promise__State(const Promise* self);
556 | void v8__Promise__MarkAsHandled(const Promise* self);
557 | const Value* v8__Promise__Result(const Promise* self);
558 |
559 | // Array
560 | const Array* v8__Array__New(
561 | Isolate* isolate,
562 | int length);
563 | const Array* v8__Array__New2(
564 | Isolate* isolate,
565 | const Value* const elements[],
566 | size_t length);
567 | uint32_t v8__Array__Length(const Array* self);
568 |
569 | // Object
570 | const Object* v8__Object__New(Isolate* isolate);
571 | const String* v8__Object__GetConstructorName(const Object* self);
572 | int v8__Object__InternalFieldCount(
573 | const Object* self);
574 | const Data* v8__Object__GetInternalField(
575 | const Object* self,
576 | int index);
577 | void v8__Object__SetInternalField(
578 | const Object* self,
579 | int index,
580 | const Value* value);
581 | const Value* v8__Object__Get(
582 | const Object* self,
583 | const Context* ctx,
584 | const Value* key);
585 | const Value* v8__Object__GetIndex(
586 | const Object* self,
587 | const Context* ctx,
588 | uint32_t idx);
589 | void v8__Object__Set(
590 | const Object* self,
591 | const Context* ctx,
592 | const Value* key,
593 | const Value* value,
594 | MaybeBool* out);
595 | void v8__Object__Delete(
596 | const Object* self,
597 | const Context* ctx,
598 | const Value* key,
599 | MaybeBool* out);
600 | void v8__Object__SetAtIndex(
601 | const Object* self,
602 | const Context* ctx,
603 | uint32_t idx,
604 | const Value* value,
605 | MaybeBool* out);
606 | void v8__Object__DefineOwnProperty(
607 | const Object* self,
608 | const Context* ctx,
609 | const Name* key,
610 | const Value* value,
611 | PropertyAttribute attr,
612 | MaybeBool* out);
613 | Isolate* v8__Object__GetIsolate(const Object* self);
614 | const Context* v8__Object__GetCreationContext(const Object* self);
615 | int v8__Object__GetIdentityHash(const Object* self);
616 | void v8__Object__Has(
617 | const Object* self,
618 | const Context* ctx,
619 | const Value* key,
620 | MaybeBool* out);
621 | void v8__Object__HasIndex(
622 | const Object* self,
623 | const Context* ctx,
624 | uint32_t idx,
625 | MaybeBool* out);
626 | const Array* v8__Object__GetOwnPropertyNames(
627 | const Object* self,
628 | const Context* ctx);
629 | const Array* v8__Object__GetPropertyNames(
630 | const Object* self,
631 | const Context* ctx);
632 | const Value* v8__Object__GetPrototype(const Object* self);
633 | void v8__Object__SetPrototype(
634 | const Object* self,
635 | const Context* ctx,
636 | const Object* prototype,
637 | MaybeBool* out);
638 | void v8__Object__SetAlignedPointerInInternalField(
639 | const Object* self,
640 | int idx,
641 | void* ptr);
642 |
643 | // Exception
644 | const Value* v8__Exception__Error(const String* message);
645 | const Value* v8__Exception__TypeError(const String* message);
646 | const Value* v8__Exception__SyntaxError(const String* message);
647 | const Value* v8__Exception__ReferenceError(const String* message);
648 | const Value* v8__Exception__RangeError(const String* message);
649 | const StackTrace* v8__Exception__GetStackTrace(const Value* exception);
650 | const Message* v8__Exception__CreateMessage(
651 | Isolate* isolate,
652 | const Value* exception);
653 |
654 | // Number
655 | const Number* v8__Number__New(
656 | Isolate* isolate,
657 | double value);
658 |
659 | // Integer
660 | const Integer* v8__Integer__New(
661 | Isolate* isolate,
662 | int32_t value);
663 | const Integer* v8__Integer__NewFromUnsigned(
664 | Isolate* isolate,
665 | uint32_t value);
666 | int64_t v8__Integer__Value(const Integer* self);
667 |
668 | // BigInt
669 | const BigInt* v8__BigInt__New(
670 | Isolate* iso,
671 | int64_t val);
672 | const BigInt* v8__BigInt__NewFromUnsigned(
673 | Isolate* iso,
674 | uint64_t val);
675 | uint64_t v8__BigInt__Uint64Value(
676 | const BigInt* self,
677 | bool* lossless);
678 | int64_t v8__BigInt__Int64Value(
679 | const BigInt* self,
680 | bool* lossless);
681 |
682 | // Template
683 | typedef struct Template Template;
684 | void v8__Template__Set(
685 | const Template* self,
686 | const Name* key,
687 | const Data* value,
688 | PropertyAttribute attr);
689 | void v8__Template__SetAccessorProperty__DEFAULT(
690 | const Template* self,
691 | const Name* key,
692 | const FunctionTemplate* getter);
693 |
694 | typedef struct PropertyCallbackInfo PropertyCallbackInfo;
695 | typedef void (*AccessorNameGetterCallback)(const Name*, const PropertyCallbackInfo*);
696 | typedef void (*AccessorNameSetterCallback)(const Name*, const Value*, const PropertyCallbackInfo*);
697 | void v8__Template__SetNativeDataProperty__DEFAULT(
698 | const Template* self,
699 | const Name* key,
700 | const AccessorNameGetterCallback* getter);
701 | void v8__Template__SetNativeDataProperty__DEFAULT2(
702 | const Template* self,
703 | const Name* key,
704 | const AccessorNameGetterCallback* getter,
705 | const AccessorNameSetterCallback* setter);
706 |
707 | typedef void (*AccessorNameGetterCallback)(const Name*, const PropertyCallbackInfo*);
708 | typedef void (*AccessorNameSetterCallback)(const Name*, const Value*, const PropertyCallbackInfo*);
709 |
710 | // FunctionCallbackInfo
711 | typedef struct FunctionCallbackInfo FunctionCallbackInfo;
712 | typedef struct ReturnValue {
713 | uintptr_t addr;
714 | } ReturnValue;
715 | Isolate* v8__FunctionCallbackInfo__GetIsolate(
716 | const FunctionCallbackInfo* self);
717 | int v8__FunctionCallbackInfo__Length(
718 | const FunctionCallbackInfo* self);
719 | const Value* v8__FunctionCallbackInfo__INDEX(
720 | const FunctionCallbackInfo* self, int i);
721 | void v8__FunctionCallbackInfo__GetReturnValue(
722 | const FunctionCallbackInfo* self,
723 | ReturnValue* res);
724 | const Object* v8__FunctionCallbackInfo__This(
725 | const FunctionCallbackInfo* self);
726 | const Value* v8__FunctionCallbackInfo__Data(
727 | const FunctionCallbackInfo* self);
728 |
729 | // PropertyCallbackInfo
730 | Isolate* v8__PropertyCallbackInfo__GetIsolate(
731 | const PropertyCallbackInfo* self);
732 | void v8__PropertyCallbackInfo__GetReturnValue(
733 | const PropertyCallbackInfo* self,
734 | ReturnValue* res);
735 | const Object* v8__PropertyCallbackInfo__This(
736 | const PropertyCallbackInfo* self);
737 | const Value* v8__PropertyCallbackInfo__Data(
738 | const PropertyCallbackInfo* self);
739 |
740 | // PromiseRejectMessage
741 | struct PromiseRejectMessage {
742 | uintptr_t promise;
743 | PromiseRejectEvent event;
744 | uintptr_t value;
745 | };
746 | PromiseRejectEvent v8__PromiseRejectMessage__GetEvent(
747 | const PromiseRejectMessage* self);
748 | const Promise* v8__PromiseRejectMessage__GetPromise(
749 | const PromiseRejectMessage* self);
750 | const Value* v8__PromiseRejectMessage__GetValue(
751 | const PromiseRejectMessage* self);
752 | usize v8__PromiseRejectMessage__SIZEOF();
753 |
754 | // ReturnValue
755 | void v8__ReturnValue__Set(
756 | const ReturnValue self,
757 | const Value* value);
758 | const Value* v8__ReturnValue__Get(
759 | const ReturnValue self);
760 |
761 | // FunctionTemplate
762 | typedef void (*FunctionCallback)(const FunctionCallbackInfo*);
763 | const FunctionTemplate* v8__FunctionTemplate__New__DEFAULT(
764 | Isolate* isolate);
765 | const FunctionTemplate* v8__FunctionTemplate__New__DEFAULT2(
766 | Isolate* isolate,
767 | FunctionCallback callback_or_null);
768 | const FunctionTemplate* v8__FunctionTemplate__New__DEFAULT3(
769 | Isolate* isolate,
770 | FunctionCallback callback_or_null,
771 | const Value* data);
772 | const ObjectTemplate* v8__FunctionTemplate__InstanceTemplate(
773 | const FunctionTemplate* self);
774 | const ObjectTemplate* v8__FunctionTemplate__PrototypeTemplate(
775 | const FunctionTemplate* self);
776 | void v8__FunctionTemplate__Inherit(
777 | const FunctionTemplate* self,
778 | const FunctionTemplate* parent);
779 | void v8__FunctionTemplate__SetPrototypeProviderTemplate(
780 | const FunctionTemplate* self,
781 | const FunctionTemplate* prototype_provider);
782 | const Function* v8__FunctionTemplate__GetFunction(
783 | const FunctionTemplate* self, const Context* context);
784 | void v8__FunctionTemplate__SetClassName(
785 | const FunctionTemplate* self,
786 | const String* name);
787 | void v8__FunctionTemplate__ReadOnlyPrototype(
788 | const FunctionTemplate* self);
789 |
790 | // Function
791 | const Function* v8__Function__New__DEFAULT(
792 | const Context* ctx,
793 | FunctionCallback callback);
794 | const Function* v8__Function__New__DEFAULT2(
795 | const Context* ctx,
796 | FunctionCallback callback,
797 | const Value* data);
798 | const Value* v8__Function__Call(
799 | const Function* self,
800 | const Context* context,
801 | const Value* recv,
802 | int argc,
803 | const Value* const argv[]);
804 | const Object* v8__Function__NewInstance(
805 | const Function* self,
806 | const Context* context,
807 | int argc,
808 | const Value* const argv[]);
809 | const Value* v8__Function__GetName(const Function* self);
810 | void v8__Function__SetName(const Function* self, const String* name);
811 |
812 | // External
813 | const External* v8__External__New(
814 | Isolate* isolate,
815 | void* value);
816 | void* v8__External__Value(
817 | const External* self);
818 |
819 | // Symbol
820 | const Symbol* v8__Symbol__GetAsyncIterator(Isolate* isolate);
821 | const Symbol* v8__Symbol__GetHasInstance(Isolate* isolate);
822 | const Symbol* v8__Symbol__GetIsConcatSpreadable(Isolate* isolate);
823 | const Symbol* v8__Symbol__GetIterator(Isolate* isolate);
824 | const Symbol* v8__Symbol__GetMatch(Isolate* isolate);
825 | const Symbol* v8__Symbol__GetReplace(Isolate* isolate);
826 | const Symbol* v8__Symbol__GetSearch(Isolate* isolate);
827 | const Symbol* v8__Symbol__GetSplit(Isolate* isolate);
828 | const Symbol* v8__Symbol__GetToPrimitive(Isolate* isolate);
829 | const Symbol* v8__Symbol__GetToStringTag(Isolate* isolate);
830 | const Symbol* v8__Symbol__GetUnscopables(Isolate* isolate);
831 | const Value* v8__Symbol__Description(const Symbol* self, Isolate* isolate);
832 |
833 | // Persistent
834 | typedef struct Persistent {
835 | uintptr_t data_ptr;
836 | } Persistent;
837 | void v8__Persistent__New(
838 | Isolate* isolate,
839 | const Data* data,
840 | Persistent* out);
841 | void v8__Persistent__Reset(
842 | Persistent* self);
843 | void v8__Persistent__SetWeak(
844 | Persistent* self);
845 | typedef struct WeakCallbackInfo WeakCallbackInfo;
846 | typedef void (*WeakCallback)(const WeakCallbackInfo*);
847 | typedef enum WeakCallbackType {
848 | kParameter,
849 | kInternalFields,
850 | kFinalizer
851 | } WeakCallbackType;
852 | void v8__Persistent__SetWeakFinalizer(
853 | Persistent* self,
854 | void* finalizer_ctx,
855 | WeakCallback finalizer_cb,
856 | WeakCallbackType type);
857 |
858 | // WeakCallbackInfo
859 | Isolate* v8__WeakCallbackInfo__GetIsolate(const WeakCallbackInfo* self);
860 | void* v8__WeakCallbackInfo__GetParameter(const WeakCallbackInfo* self);
861 | void* v8__WeakCallbackInfo__GetInternalField(
862 | const WeakCallbackInfo* self,
863 | int idx);
864 |
865 | // ObjectTemplate
866 | typedef struct ObjectTemplate ObjectTemplate;
867 | ObjectTemplate* v8__ObjectTemplate__New__DEFAULT(
868 | Isolate* isolate);
869 | ObjectTemplate* v8__ObjectTemplate__New(
870 | Isolate* isolate, const FunctionTemplate* templ);
871 | Object* v8__ObjectTemplate__NewInstance(
872 | const ObjectTemplate* self, const Context* ctx);
873 | void v8__ObjectTemplate__SetInternalFieldCount(
874 | const ObjectTemplate* self,
875 | int value);
876 | void v8__ObjectTemplate__SetAccessorProperty__DEFAULT(
877 | const ObjectTemplate* self,
878 | const Name* key,
879 | const FunctionTemplate* getter);
880 | void v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(
881 | const ObjectTemplate* self,
882 | const Name* key,
883 | const FunctionTemplate* getter,
884 | const FunctionTemplate* setter);
885 | void v8__ObjectTemplate__SetNativeDataProperty__DEFAULT(
886 | const ObjectTemplate* self,
887 | const Name* key,
888 | AccessorNameGetterCallback getter);
889 | void v8__ObjectTemplate__SetNativeDataProperty__DEFAULT2(
890 | const ObjectTemplate* self,
891 | const Name* key,
892 | AccessorNameGetterCallback getter,
893 | AccessorNameSetterCallback setter);
894 | void v8__ObjectTemplate__MarkAsUndetectable(
895 | const ObjectTemplate* self);
896 | void v8__ObjectTemplate__SetCallAsFunctionHandler(
897 | const ObjectTemplate* self,
898 | FunctionCallback callback_or_null);
899 |
900 | typedef enum PropertyHandlerFlags {
901 | kNonMasking = 1,
902 | kOnlyInterceptStrings = 1 << 1,
903 | kHasNoSideEffect = 1 << 2,
904 | } PropertyHandlerFlags;
905 |
906 | typedef struct PropertyDescriptor {} PropertyDescriptor;
907 | typedef uint8_t (*IndexedPropertyGetterCallback)(uint32_t, const PropertyCallbackInfo*);
908 | typedef uint8_t (*IndexedPropertySetterCallback)(uint32_t, const Value*, const PropertyCallbackInfo*);
909 | typedef uint8_t (*IndexedPropertyQueryCallback)(uint32_t, const PropertyCallbackInfo*);
910 | typedef uint8_t (*IndexedPropertyDeleterCallback)(uint32_t, const PropertyCallbackInfo*);
911 | typedef uint8_t (*IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo*);
912 | typedef void (*IndexedPropertyDefinerCallback)(uint32_t, PropertyDescriptor* desc, const PropertyCallbackInfo*);
913 | typedef void (*IndexedPropertyDescriptorCallback)(uint32_t, const PropertyCallbackInfo*);
914 | typedef struct IndexedPropertyHandlerConfiguration {
915 | IndexedPropertyGetterCallback getter;
916 | IndexedPropertySetterCallback setter;
917 | IndexedPropertyQueryCallback query;
918 | IndexedPropertyDeleterCallback deleter;
919 | IndexedPropertyEnumeratorCallback enumerator;
920 | IndexedPropertyDefinerCallback definer;
921 | IndexedPropertyDescriptorCallback descriptor;
922 | const Value* data;
923 | PropertyHandlerFlags flags;
924 | } IndexedPropertyHandlerConfiguration;
925 | void v8__ObjectTemplate__SetIndexedHandler(
926 | const ObjectTemplate* self,
927 | const IndexedPropertyHandlerConfiguration* configuration);
928 |
929 | typedef uint8_t (*NamedPropertyGetterCallback)(const Name*, const PropertyCallbackInfo*);
930 | typedef uint8_t (*NamedPropertySetterCallback)(const Name*, const Value*, const PropertyCallbackInfo*);
931 | typedef uint8_t (*NamedPropertyQueryCallback)(const Name*, const PropertyCallbackInfo*);
932 | typedef uint8_t (*NamedPropertyDeleterCallback)(const Name*, const PropertyCallbackInfo*);
933 | typedef uint8_t (*NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo*);
934 | typedef void (*NamedPropertyDefinerCallback)(const Name*, PropertyDescriptor* desc, const PropertyCallbackInfo*);
935 | typedef void (*NamedPropertyDescriptorCallback)(const Name*, const PropertyCallbackInfo*);
936 | typedef struct NamedPropertyHandlerConfiguration {
937 | NamedPropertyGetterCallback getter;
938 | NamedPropertySetterCallback setter;
939 | NamedPropertyQueryCallback query;
940 | NamedPropertyDeleterCallback deleter;
941 | NamedPropertyEnumeratorCallback enumerator;
942 | NamedPropertyDefinerCallback definer;
943 | NamedPropertyDescriptorCallback descriptor;
944 | const Value* data;
945 | PropertyHandlerFlags flags;
946 | } NamedPropertyHandlerConfiguration;
947 | void v8__ObjectTemplate__SetNamedHandler(
948 | const ObjectTemplate* self,
949 | const NamedPropertyHandlerConfiguration* configuration);
950 |
951 | // ScriptOrigin
952 | typedef struct ScriptOriginOptions {
953 | const int flags_;
954 | } ScriptOriginOptions;
955 | typedef struct ScriptOrigin {
956 | Value* resource_name_;
957 | int resource_line_offset_;
958 | int resource_column_offset_;
959 | ScriptOriginOptions options_;
960 | int script_id_;
961 | Value* source_map_url_;
962 | void* host_defined_options_;
963 | } ScriptOrigin;
964 | void v8__ScriptOrigin__CONSTRUCT(ScriptOrigin* buf, const Value* resource_name);
965 | void v8__ScriptOrigin__CONSTRUCT2(
966 | ScriptOrigin* buf,
967 | const Value* resource_name,
968 | int resource_line_offset,
969 | int resource_column_offset,
970 | bool resource_is_shared_cross_origin,
971 | int script_id,
972 | const Value* source_map_url,
973 | bool resource_is_opaque,
974 | bool is_wasm,
975 | bool is_module,
976 | const Data* host_defined_options
977 | );
978 |
979 | usize v8__ScriptCompiler__CompilationDetails__SIZEOF();
980 | typedef struct CompilationDetails {
981 | // this is an enum, but should get padded to an int64_t
982 | int64_t in_memory_cache_result;
983 | int64_t foreground_time_in_microseconds;
984 | int64_t background_time_in_microseconds;
985 | } CompilationDetails;
986 |
987 | typedef bool (*CompileHintCallback)(int, void*);
988 |
989 | // ScriptCompiler
990 | typedef struct ScriptCompilerSource {
991 | String* source_string;
992 |
993 | // Origin information
994 | Value* resource_name;
995 | int resource_line_offset;
996 | int resource_column_offset;
997 | ScriptOriginOptions resource_options;
998 | Value* source_map_url;
999 | Data* host_defined_options;
1000 |
1001 | // Cached data from previous compilation (if a kConsume*Cache flag is
1002 | // set), or hold newly generated cache data (kProduce*Cache flags) are
1003 | // set when calling a compile method.
1004 | UniquePtr cached_data;
1005 | UniquePtr consume_cache_task;
1006 |
1007 | CompileHintCallback compile_hint_callback;
1008 | void* compile_hint_callback_data;
1009 | CompilationDetails compilation_details
1010 |
1011 | } ScriptCompilerSource;
1012 | typedef enum BufferPolicy {
1013 | BufferNotOwned,
1014 | BufferOwned
1015 | } BufferPolicy;
1016 | typedef struct ScriptCompilerCachedData {
1017 | const uint8_t* data;
1018 | int length;
1019 | bool rejected;
1020 | BufferPolicy buffer_policy;
1021 | } ScriptCompilerCachedData;
1022 | size_t v8__ScriptCompiler__Source__SIZEOF();
1023 | void v8__ScriptCompiler__Source__CONSTRUCT(
1024 | const String* src,
1025 | ScriptCompilerCachedData* cached_data,
1026 | ScriptCompilerSource* out);
1027 | void v8__ScriptCompiler__Source__CONSTRUCT2(
1028 | const String* src,
1029 | const ScriptOrigin* origin,
1030 | ScriptCompilerCachedData* cached_data,
1031 | ScriptCompilerSource* out);
1032 | void v8__ScriptCompiler__Source__DESTRUCT(ScriptCompilerSource* self);
1033 | size_t v8__ScriptCompiler__CachedData__SIZEOF();
1034 | ScriptCompilerCachedData* v8__ScriptCompiler__CachedData__NEW(
1035 | const uint8_t* data,
1036 | int length);
1037 | void v8__ScriptCompiler__CachedData__DELETE(ScriptCompilerCachedData* self);
1038 | const Module* v8__ScriptCompiler__CompileModule(
1039 | Isolate* isolate,
1040 | ScriptCompilerSource* source,
1041 | CompileOptions options,
1042 | NoCacheReason reason);
1043 |
1044 | // Script
1045 | typedef struct Script Script;
1046 | Script* v8__Script__Compile(const Context* context, const String* src, const ScriptOrigin* origin);
1047 | Value* v8__Script__Run(const Script* script, const Context* context);
1048 |
1049 | // Module
1050 | typedef enum ModuleStatus {
1051 | kUninstantiated,
1052 | kInstantiating,
1053 | kInstantiated,
1054 | kEvaluating,
1055 | kEvaluated,
1056 | kErrored
1057 | } ModuleStatus;
1058 | ModuleStatus v8__Module__GetStatus(const Module* self);
1059 | const Value* v8__Module__GetException(const Module* self);
1060 | const FixedArray* v8__Module__GetModuleRequests(const Module* self);
1061 | typedef const Module* (*ResolveModuleCallback)(
1062 | const Context* ctx, const String* spec,
1063 | const FixedArray* import_assertions, const Module* referrer);
1064 | void v8__Module__InstantiateModule(
1065 | const Module* self,
1066 | const Context* ctx,
1067 | ResolveModuleCallback cb,
1068 | MaybeBool* out);
1069 | const Value* v8__Module__Evaluate(const Module* self, const Context* ctx);
1070 | int v8__Module__GetIdentityHash(const Module* self);
1071 | Value* v8__Module__GetModuleNamespace(const Module* self);
1072 | int v8__Module__ScriptId(const Module* self);
1073 |
1074 | Script* v8__ScriptCompiler__Compile(
1075 | const Context* context,
1076 | ScriptCompilerSource* source,
1077 | CompileOptions options,
1078 | NoCacheReason reason);
1079 |
1080 | // ModuleRequest
1081 | typedef Data ModuleRequest;
1082 | const String* v8__ModuleRequest__GetSpecifier(const ModuleRequest* self);
1083 | int v8__ModuleRequest__GetSourceOffset(const ModuleRequest* self);
1084 |
1085 | // JSON
1086 | const Value* v8__JSON__Parse(
1087 | const Context* ctx,
1088 | const String* json);
1089 | const String* v8__JSON__Stringify(
1090 | const Context* ctx,
1091 | const Value* val,
1092 | const String* gap);
1093 |
1094 | // Misc.
1095 | void v8__base__SetDcheckFunction(void (*func)(const char*, int, const char*));
1096 |
1097 | // Utils
1098 |
1099 | typedef struct {
1100 | const char *ptr;
1101 | uint64_t len;
1102 | } CZigString;
1103 |
1104 | // CpuProfiler
1105 | // -----------
1106 |
1107 | typedef struct CpuProfiler CpuProfiler;
1108 | typedef struct CpuProfile CpuProfile;
1109 | typedef struct CpuProfileNode CpuProfileNode;
1110 |
1111 | CpuProfiler* v8__CpuProfiler__Get(Isolate* isolate);
1112 | void v8__CpuProfiler__StartProfiling(CpuProfiler* self, const String* title);
1113 | const CpuProfile* v8__CpuProfiler__StopProfiling(CpuProfiler* self, const String* title);
1114 | void v8__CpuProfiler__UseDetailedSourcePositionsForProfiling(Isolate* isolate);
1115 | void v8__CpuProfile__Delete(const CpuProfile* self);
1116 | const CpuProfileNode* v8__CpuProfile__GetTopDownRoot(const CpuProfile* self);
1117 | const String* v8__CpuProfile__Serialize(const CpuProfile* self, Isolate* isolate);
1118 |
1119 | // Inspector
1120 | // ---------
1121 |
1122 | typedef enum ClientTrustLevel {
1123 | kUntrusted,
1124 | kFullyTrusted,
1125 | } ClientTrustLevel;
1126 |
1127 | typedef struct StringView StringView;
1128 |
1129 | // InspectorChannel
1130 |
1131 | typedef struct InspectorChannel InspectorChannel;
1132 | typedef struct InspectorChannelImpl {
1133 | void* data;
1134 | } InspectorChannelImpl;
1135 | InspectorChannelImpl *v8_inspector__Channel__IMPL__CREATE(Isolate *isolate);
1136 | void v8_inspector__Channel__IMPL__DELETE(InspectorChannelImpl *self);
1137 | void v8_inspector__Channel__IMPL__SET_DATA(InspectorChannelImpl* self, void *data);
1138 |
1139 | void v8_inspector__Channel__IMPL__sendResponse(
1140 | InspectorChannelImpl *self, void *data,
1141 | int callId, char *message, size_t length);
1142 | void v8_inspector__Channel__IMPL__sendNotification(
1143 | InspectorChannelImpl *self, void *data,
1144 | char *message, size_t length);
1145 | void v8_inspector__Channel__IMPL__flushProtocolNotifications(
1146 | InspectorChannelImpl *self, void *data);
1147 |
1148 | // InspectorClient
1149 |
1150 | typedef struct InspectorClient InspectorClient;
1151 | typedef struct InspectorClientImpl {
1152 | void* data;
1153 | } InspectorClientImpl;
1154 | InspectorClientImpl *v8_inspector__Client__IMPL__CREATE();
1155 | void v8_inspector__Client__IMPL__DELETE(InspectorClientImpl *self);
1156 | void v8_inspector__Client__IMPL__SET_DATA(InspectorClientImpl* self, void *data);
1157 |
1158 | int64_t v8_inspector__Client__IMPL__generateUniqueId(InspectorClientImpl *self);
1159 | void v8_inspector__Client__IMPL__runMessageLoopOnPause(
1160 | InspectorClientImpl *self, int contextGroupId);
1161 | void v8_inspector__Client__IMPL__quitMessageLoopOnPause(
1162 | InspectorClientImpl *self);
1163 | void v8_inspector__Client__IMPL__runIfWaitingForDebugger(
1164 | InspectorClientImpl *self, int contextGroupId);
1165 | void v8_inspector__Client__IMPL__consoleAPIMessage(
1166 | InspectorClientImpl *self, int contextGroupId, MessageErrorLevel level,
1167 | StringView *message, StringView *url, unsigned lineNumber,
1168 | unsigned columnNumber, StackTrace *StackTrace);
1169 | const Context* v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
1170 | InspectorClientImpl* self, void* data, int contextGroupId);
1171 | char* v8_inspector__Client__IMPL__valueSubtype(
1172 | InspectorClientImpl* self, Value value);
1173 | char* v8_inspector__Client__IMPL__descriptionForValueSubtype(
1174 | InspectorClientImpl* self, Context context, Value value);
1175 |
1176 | // RemoteObject
1177 | typedef struct RemoteObject RemoteObject;
1178 | typedef struct WebDriverValue WebDriverValue;
1179 | typedef struct ObjectPreview ObjectPreview;
1180 | typedef struct CustomPreview CustomPreview;
1181 |
1182 | // InspectorSession
1183 |
1184 | typedef struct InspectorSession InspectorSession;
1185 | void v8_inspector__Session__DELETE(InspectorSession *self);
1186 | void v8_inspector__Session__dispatchProtocolMessage(InspectorSession *session, Isolate *isolate, const char* msg, usize msg_len);
1187 | RemoteObject* v8_inspector__Session__wrapObject(
1188 | InspectorSession *session, Isolate *isolate,
1189 | const Context* ctx, const Value* val,
1190 | const char *grpname, usize grpname_len, bool generatepreview);
1191 |
1192 | bool v8_inspector__Session__unwrapObject(
1193 | InspectorSession *session,
1194 | const void* allocator,
1195 | CZigString* out_error,
1196 | CZigString in_objectId,
1197 | Value** out_value,
1198 | Context** out_context,
1199 | CZigString* out_objectGroup
1200 | );
1201 |
1202 | // Inspector
1203 | typedef struct Inspector Inspector;
1204 | Inspector* v8_inspector__Inspector__Create(Isolate* isolate, InspectorClientImpl* client);
1205 | void v8_inspector__Inspector__DELETE(Inspector *self);
1206 |
1207 | InspectorSession* v8_inspector__Inspector__Connect(
1208 | Inspector *self, int contextGroupId,
1209 | InspectorChannelImpl *channel,
1210 | ClientTrustLevel level);
1211 | void v8_inspector__Inspector__ContextCreated(Inspector *self, const char *name,
1212 | usize name_len, const char *origin,
1213 | usize origin_len,
1214 | const char *auxData, const usize auxData_len,
1215 | int contextGroupId,
1216 | const Context* context);
1217 |
1218 | // RemoteObject
1219 | void v8_inspector__RemoteObject__DELETE(RemoteObject *self);
1220 |
1221 | // RemoteObject - Type
1222 | bool v8_inspector__RemoteObject__getType(RemoteObject* self, const void* allocator, CZigString* out_type);
1223 | void v8_inspector__RemoteObject__setType(RemoteObject* self, CZigString type);
1224 |
1225 | // RemoteObject - Subtype
1226 | bool v8_inspector__RemoteObject__hasSubtype(RemoteObject* self);
1227 | bool v8_inspector__RemoteObject__getSubtype(RemoteObject* self, const void* allocator, CZigString* out_subtype);
1228 | void v8_inspector__RemoteObject__setSubtype(RemoteObject* self, CZigString subtype);
1229 |
1230 | // RemoteObject - ClassName
1231 | bool v8_inspector__RemoteObject__hasClassName(RemoteObject* self);
1232 | bool v8_inspector__RemoteObject__getClassName(RemoteObject* self, const void* allocator, CZigString* out_className);
1233 | void v8_inspector__RemoteObject__setClassName(RemoteObject* self, CZigString className);
1234 |
1235 | // RemoteObject - Value
1236 | bool v8_inspector__RemoteObject__hasValue(RemoteObject* self);
1237 | // Commented as these for now as the type should likely be the existing Value TBD
1238 | // v8_inspector::protocol::Value* v8_inspector__RemoteObject__getValue(Rem;eObject* self);
1239 | // void v8_inspector__RemoteObject__setValue(RemoteObject* self, v8_inspector::protocol::Value* value);
1240 |
1241 | //RemoteObject - UnserializableValue
1242 | bool v8_inspector__RemoteObject__hasUnserializableValue(RemoteObject* self);
1243 | bool v8_inspector__RemoteObject__getUnserializableValue(RemoteObject* self, const void* allocator, CZigString* out_unserializableValue);
1244 | void v8_inspector__RemoteObject__setUnserializableValue(RemoteObject* self, CZigString unserializableValue);
1245 |
1246 | // RemoteObject - Description
1247 | bool v8_inspector__RemoteObject__hasDescription(RemoteObject* self);
1248 | bool v8_inspector__RemoteObject__getDescription(RemoteObject* self, const void* allocator, CZigString* out_description);
1249 | void v8_inspector__RemoteObject__setDescription(RemoteObject* self, CZigString description);
1250 |
1251 | // RemoteObject - WebDriverValue
1252 | bool v8_inspector__RemoteObject__hasWebDriverValue(RemoteObject* self);
1253 | WebDriverValue* v8_inspector__RemoteObject__getWebDriverValue(RemoteObject* self);
1254 | void v8_inspector__RemoteObject__setWebDriverValue(RemoteObject* self, WebDriverValue* webDriverValue);
1255 |
1256 | // RemoteObject - ObjectId
1257 | bool v8_inspector__RemoteObject__hasObjectId(RemoteObject* self);
1258 | bool v8_inspector__RemoteObject__getObjectId(RemoteObject* self, const void* allocator, CZigString* out_objectId);
1259 | void v8_inspector__RemoteObject__setObjectId(RemoteObject* self, CZigString objectId);
1260 |
1261 | // RemoteObject - Preview
1262 | bool v8_inspector__RemoteObject__hasPreview(RemoteObject* self);
1263 | const ObjectPreview* v8_inspector__RemoteObject__getPreview(RemoteObject* self);
1264 | void v8_inspector__RemoteObject__setPreview(RemoteObject* self, ObjectPreview* preview);
1265 |
1266 | // RemoteObject - CustomPreview
1267 | bool v8_inspector__RemoteObject__hasCustomPreview(RemoteObject* self);
1268 | const CustomPreview* v8_inspector__RemoteObject__getCustomPreview(RemoteObject* self);
1269 | void v8_inspector__RemoteObject__setCustomPreview(RemoteObject* self, CustomPreview* customPreview);
1270 |
--------------------------------------------------------------------------------
/src/inspector.h:
--------------------------------------------------------------------------------
1 | #include "include/v8-inspector.h"
2 |
3 | #ifndef V8INSPECTORIMPL_H
4 | #define V8INSPECTORIMPL_H
5 |
6 | // InspectorChannel Implementation
7 | struct v8_inspector__Channel__IMPL
8 | : public v8_inspector::V8Inspector::Channel {
9 | using v8_inspector::V8Inspector::Channel::Channel;
10 |
11 | public:
12 | v8::Isolate *isolate;
13 | void *data;
14 |
15 | private:
16 | void sendResponse(int callId,
17 | std::unique_ptr message) override;
18 | void sendNotification(std::unique_ptr message) override;
19 | void flushProtocolNotifications() override;
20 | };
21 |
22 | // InspectorClient Implementation
23 | class v8_inspector__Client__IMPL
24 | : public v8_inspector::V8InspectorClient {
25 | using v8_inspector::V8InspectorClient::V8InspectorClient;
26 |
27 | public:
28 | void *data;
29 |
30 | private:
31 | int64_t generateUniqueId() override;
32 | void runMessageLoopOnPause(int contextGroupId) override;
33 | void quitMessageLoopOnPause() override;
34 | void runIfWaitingForDebugger(int contextGroupId) override;
35 | void consoleAPIMessage(int contextGroupId,
36 | v8::Isolate::MessageErrorLevel level,
37 | const v8_inspector::StringView& message,
38 | const v8_inspector::StringView& url,
39 | unsigned lineNumber, unsigned columnNumber,
40 | v8_inspector::V8StackTrace* stackTrace) override;
41 | v8::Local ensureDefaultContextInGroup(int contextGroupId) override;
42 | std::unique_ptr valueSubtype(v8::Local) override;
43 | std::unique_ptr descriptionForValueSubtype(v8::Local, v8::Local) override;
44 | };
45 |
46 | #endif // V8INSPECTORIMPL_H
47 |
--------------------------------------------------------------------------------
/src/inspector_subtypes.zig:
--------------------------------------------------------------------------------
1 | const c = @import("v8.zig").c;
2 |
3 | pub export fn v8_inspector__Client__IMPL__valueSubtype(
4 | _: *c.InspectorClientImpl,
5 | value: *const c.Value,
6 | ) callconv(.c) [*c]const u8 {
7 | _ = value;
8 | return null;
9 | }
10 |
11 | pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype(
12 | _: *c.InspectorClientImpl,
13 | context: *const c.Context,
14 | value: *const c.Value,
15 | ) callconv(.c) [*c]const u8 {
16 | _ = value;
17 | _ = context;
18 | return null;
19 | }
20 |
--------------------------------------------------------------------------------
/src/main_build.zig:
--------------------------------------------------------------------------------
1 | pub fn main() !void {}
2 |
--------------------------------------------------------------------------------
/src/shell.zig:
--------------------------------------------------------------------------------
1 | const std = @import("std");
2 | const v8 = @import("v8.zig");
3 |
4 | // Demo js repl.
5 |
6 | pub fn main() !void {
7 | repl();
8 | std.process.exit(0);
9 | }
10 |
11 | fn repl() void {
12 | var gpa = std.heap.GeneralPurposeAllocator(.{}){};
13 | defer _ = gpa.deinit();
14 | const alloc = gpa.allocator();
15 |
16 | var input_buf = std.ArrayList(u8).init(alloc);
17 | defer input_buf.deinit();
18 |
19 | const platform = v8.Platform.initDefault(0, true);
20 | defer platform.deinit();
21 |
22 | v8.initV8Platform(platform);
23 | defer v8.deinitV8Platform();
24 |
25 | v8.initV8();
26 | defer _ = v8.deinitV8();
27 |
28 | var params = v8.initCreateParams();
29 | params.array_buffer_allocator = v8.createDefaultArrayBufferAllocator();
30 | defer v8.destroyArrayBufferAllocator(params.array_buffer_allocator.?);
31 | var isolate = v8.Isolate.init(¶ms);
32 | defer isolate.deinit();
33 |
34 | isolate.enter();
35 | defer isolate.exit();
36 |
37 | var hscope: v8.HandleScope = undefined;
38 | hscope.init(isolate);
39 | defer hscope.deinit();
40 |
41 | var context = v8.Context.init(isolate, null, null);
42 | context.enter();
43 | defer context.exit();
44 |
45 | const origin = v8.String.initUtf8(isolate, "(shell)");
46 |
47 | printFmt(
48 | \\JS Repl
49 | \\exit with Ctrl+D or "exit()"
50 | \\
51 | , .{});
52 |
53 | while (true) {
54 | printFmt("\n> ", .{});
55 | if (getInput(&input_buf)) |input| {
56 | if (std.mem.eql(u8, input, "exit()")) {
57 | break;
58 | }
59 |
60 | var res: ExecuteResult = undefined;
61 | defer res.deinit();
62 | executeString(alloc, isolate, input, origin, &res);
63 | if (res.success) {
64 | printFmt("{s}", .{res.result.?});
65 | } else {
66 | printFmt("{s}", .{res.err.?});
67 | }
68 |
69 | while (platform.pumpMessageLoop(isolate, false)) {
70 | continue;
71 | }
72 | } else {
73 | printFmt("\n", .{});
74 | return;
75 | }
76 | }
77 | }
78 |
79 | fn getInput(input_buf: *std.ArrayList(u8)) ?[]const u8 {
80 | input_buf.clearRetainingCapacity();
81 | std.io.getStdIn().reader().readUntilDelimiterArrayList(input_buf, '\n', 1e9) catch |err| {
82 | if (err == error.EndOfStream) {
83 | return null;
84 | } else {
85 | unreachable;
86 | }
87 | };
88 | return input_buf.items;
89 | }
90 |
91 | pub fn printFmt(comptime format: []const u8, args: anytype) void {
92 | const stdout = std.io.getStdOut().writer();
93 | stdout.print(format, args) catch unreachable;
94 | }
95 |
96 | pub const ExecuteResult = struct {
97 | const Self = @This();
98 |
99 | alloc: std.mem.Allocator,
100 | result: ?[]const u8,
101 | err: ?[]const u8,
102 | success: bool,
103 |
104 | pub fn deinit(self: Self) void {
105 | if (self.result) |result| {
106 | self.alloc.free(result);
107 | }
108 | if (self.err) |err| {
109 | self.alloc.free(err);
110 | }
111 | }
112 | };
113 |
114 | pub fn executeString(alloc: std.mem.Allocator, isolate: v8.Isolate, src: []const u8, src_origin: v8.String, result: *ExecuteResult) void {
115 | var hscope: v8.HandleScope = undefined;
116 | hscope.init(isolate);
117 | defer hscope.deinit();
118 |
119 | var try_catch: v8.TryCatch = undefined;
120 | try_catch.init(isolate);
121 | defer try_catch.deinit();
122 |
123 | const origin = v8.ScriptOrigin.initDefault(isolate, src_origin.toValue());
124 |
125 | const context = isolate.getCurrentContext();
126 |
127 | const js_src = v8.String.initUtf8(isolate, src);
128 |
129 | const script = v8.Script.compile(context, js_src, origin) catch {
130 | setResultError(alloc, isolate, try_catch, result);
131 | return;
132 | };
133 | const script_res = script.run(context) catch {
134 | setResultError(alloc, isolate, try_catch, result);
135 | return;
136 | };
137 | result.* = .{
138 | .alloc = alloc,
139 | .result = valueToUtf8Alloc(alloc, isolate, context, script_res),
140 | .err = null,
141 | .success = true,
142 | };
143 | }
144 |
145 | fn setResultError(alloc: std.mem.Allocator, isolate: v8.Isolate, try_catch: v8.TryCatch, result: *ExecuteResult) void {
146 | result.* = .{
147 | .alloc = alloc,
148 | .result = null,
149 | .err = getTryCatchErrorString(alloc, isolate, try_catch),
150 | .success = false,
151 | };
152 | }
153 |
154 | pub fn valueToUtf8Alloc(alloc: std.mem.Allocator, isolate: v8.Isolate, ctx: v8.Context, any_value: anytype) []const u8 {
155 | const val = v8.getValue(any_value);
156 | const str = val.toString(ctx) catch unreachable;
157 | const len = str.lenUtf8(isolate);
158 | const buf = alloc.alloc(u8, len) catch unreachable;
159 | _ = str.writeUtf8(isolate, buf);
160 | return buf;
161 | }
162 |
163 | pub fn getTryCatchErrorString(alloc: std.mem.Allocator, isolate: v8.Isolate, try_catch: v8.TryCatch) []const u8 {
164 | var hscope: v8.HandleScope = undefined;
165 | hscope.init(isolate);
166 | defer hscope.deinit();
167 |
168 | const ctx = isolate.getCurrentContext();
169 |
170 | if (try_catch.getMessage()) |message| {
171 | var buf = std.ArrayList(u8).init(alloc);
172 | const writer = buf.writer();
173 |
174 | // Append source line.
175 | const source_line = message.getSourceLine(ctx).?;
176 | _ = appendValueAsUtf8(&buf, isolate, ctx, source_line);
177 | writer.writeAll("\n") catch unreachable;
178 |
179 | // Print wavy underline.
180 | const col_start = message.getStartColumn().?;
181 | const col_end = message.getEndColumn().?;
182 |
183 | var i: u32 = 0;
184 | while (i < col_start) : (i += 1) {
185 | writer.writeByte(' ') catch unreachable;
186 | }
187 | while (i < col_end) : (i += 1) {
188 | writer.writeByte('^') catch unreachable;
189 | }
190 | writer.writeByte('\n') catch unreachable;
191 |
192 | if (try_catch.getStackTrace(ctx)) |trace| {
193 | _ = appendValueAsUtf8(&buf, isolate, ctx, trace);
194 | writer.writeByte('\n') catch unreachable;
195 | }
196 |
197 | return buf.toOwnedSlice() catch unreachable;
198 | } else {
199 | // V8 didn't provide any extra information about this error, just get exception str.
200 | const exception = try_catch.getException().?;
201 | return valueToUtf8Alloc(alloc, isolate, ctx, exception);
202 | }
203 | }
204 |
205 | pub fn appendValueAsUtf8(arr: *std.ArrayList(u8), isolate: v8.Isolate, ctx: v8.Context, any_value: anytype) []const u8 {
206 | const val = v8.getValue(any_value);
207 | const str = val.toString(ctx) catch unreachable;
208 | const len = str.lenUtf8(isolate);
209 | const start = arr.items.len;
210 | arr.resize(start + len) catch unreachable;
211 | _ = str.writeUtf8(isolate, arr.items[start..arr.items.len]);
212 | return arr.items[start..];
213 | }
214 |
--------------------------------------------------------------------------------
/src/test.zig:
--------------------------------------------------------------------------------
1 | const std = @import("std");
2 | const t = std.testing;
3 | const v8 = @import("v8.zig");
4 |
5 | test {
6 | // Based on https://chromium.googlesource.com/v8/v8/+/branch-heads/6.8/samples/hello-world.cc
7 |
8 | const platform = v8.Platform.initDefault(0, true);
9 | defer platform.deinit();
10 |
11 | std.debug.print("v8 version: {s}\n", .{v8.getVersion()});
12 |
13 | v8.initV8Platform(platform);
14 | v8.initV8();
15 | defer {
16 | _ = v8.deinitV8();
17 | v8.deinitV8Platform();
18 | }
19 |
20 | var params = v8.initCreateParams();
21 | params.array_buffer_allocator = v8.createDefaultArrayBufferAllocator();
22 | defer v8.destroyArrayBufferAllocator(params.array_buffer_allocator.?);
23 |
24 | var isolate = v8.Isolate.init(¶ms);
25 | defer isolate.deinit();
26 |
27 | isolate.enter();
28 | defer isolate.exit();
29 |
30 | // Create a stack-allocated handle scope.
31 | var hscope: v8.HandleScope = undefined;
32 | hscope.init(isolate);
33 | defer hscope.deinit();
34 |
35 | // Create a new context.
36 | var context = v8.Context.init(isolate, null, null);
37 | context.enter();
38 | defer context.exit();
39 |
40 | // Create a string containing the JavaScript source code.
41 | const source = v8.String.initUtf8(isolate, "'Hello' + ', World! 🍏🍓' + Math.sin(Math.PI/2)");
42 |
43 | // Compile the source code.
44 | const script = try v8.Script.compile(context, source, null);
45 |
46 | // Run the script to get the result.
47 | const value = try script.run(context);
48 |
49 | // Convert the result to an UTF8 string and print it.
50 | const res = valueToRawUtf8Alloc(t.allocator, isolate, context, value);
51 | defer t.allocator.free(res);
52 |
53 | std.log.info("{s}", .{res});
54 | try t.expectEqualStrings(res, "Hello, World! 🍏🍓1");
55 | }
56 |
57 | pub fn valueToRawUtf8Alloc(alloc: std.mem.Allocator, isolate: v8.Isolate, ctx: v8.Context, val: v8.Value) []const u8 {
58 | const str = val.toString(ctx) catch unreachable;
59 | const len = str.lenUtf8(isolate);
60 | const buf = alloc.alloc(u8, len) catch unreachable;
61 | _ = str.writeUtf8(isolate, buf);
62 | return buf;
63 | }
64 |
--------------------------------------------------------------------------------