44#include < cstddef>
55#include < cstdint>
66#include < cstdio>
7- #include < iostream>
8- #include < memory>
7+ #include < thread>
98
109#include " cppgc/allocation.h"
10+ #include " cppgc/persistent.h"
1111#include " cppgc/platform.h"
12+ #include " libplatform/libplatform.h"
1213#include " support.h"
1314#include " unicode/locid.h"
1415#include " v8-callbacks.h"
15- #include " v8/include/cppgc/persistent.h"
16- #include " v8/include/libplatform/libplatform.h"
17- #include " v8/include/v8-cppgc.h"
18- #include " v8/include/v8-fast-api-calls.h"
19- #include " v8/include/v8-inspector.h"
20- #include " v8/include/v8-internal.h"
21- #include " v8/include/v8-platform.h"
22- #include " v8/include/v8-profiler.h"
23- #include " v8/include/v8.h"
24- #include " v8/src/api/api-inl.h"
25- #include " v8/src/api/api.h"
26- #include " v8/src/base/debug/stack_trace.h"
27- #include " v8/src/base/sys-info.h"
28- #include " v8/src/execution/isolate-utils-inl.h"
29- #include " v8/src/execution/isolate-utils.h"
16+ #include " v8-cppgc.h"
17+ #include " v8-fast-api-calls.h"
18+ #include " v8-inspector.h"
19+ #include " v8-internal.h"
20+ #include " v8-platform.h"
21+ #include " v8-profiler.h"
22+ #include " v8.h"
3023#include " v8/src/flags/flags.h"
3124#include " v8/src/libplatform/default-platform.h"
32- #include " v8/src/objects/objects-inl.h"
33- #include " v8/src/objects/objects.h"
34- #include " v8/src/objects/smi.h"
3525
3626using namespace support ;
3727
@@ -125,9 +115,6 @@ static_assert(sizeof(v8::Isolate::DisallowJavascriptExecutionScope) == 12,
125115#endif
126116
127117extern " C" {
128- const extern int v8__internal__Internals__kIsolateEmbedderDataOffset =
129- v8::internal::Internals::kIsolateEmbedderDataOffset ;
130-
131118void v8__V8__SetFlagsFromCommandLine (int * argc, char ** argv,
132119 const char * usage) {
133120 namespace i = v8::internal;
@@ -204,6 +191,14 @@ uint32_t v8__Isolate__GetNumberOfDataSlots(v8::Isolate* isolate) {
204191 return isolate->GetNumberOfDataSlots ();
205192}
206193
194+ void * v8__Isolate__GetData (v8::Isolate* isolate, uint32_t slot) {
195+ return isolate->GetData (slot);
196+ }
197+
198+ void v8__Isolate__SetData (v8::Isolate* isolate, uint32_t slot, void * data) {
199+ isolate->SetData (slot, data);
200+ }
201+
207202const v8::Data* v8__Isolate__GetDataFromSnapshotOnce (v8::Isolate* isolate,
208203 size_t index) {
209204 return maybe_local_to_ptr (isolate->GetDataFromSnapshotOnce <v8::Data>(index));
@@ -577,17 +572,17 @@ bool v8__Data__EQ(const v8::Data& self, const v8::Data& other) {
577572}
578573
579574bool v8__Data__IsBigInt (const v8::Data& self) {
580- return IsBigInt (* v8::Utils::OpenHandle (& self));
575+ return self. IsValue () && reinterpret_cast < const v8::Value&>( self). IsBigInt ( );
581576}
582577
583578bool v8__Data__IsBoolean (const v8::Data& self) {
584- return IsBoolean (* v8::Utils::OpenHandle (& self));
579+ return self. IsValue () && reinterpret_cast < const v8::Value&>( self). IsBoolean ( );
585580}
586581
587582bool v8__Data__IsContext (const v8::Data& self) { return self.IsContext (); }
588583
589584bool v8__Data__IsFixedArray (const v8::Data& self) {
590- return IsFixedArray (* v8::Utils::OpenHandle (&self) );
585+ return self. IsFixedArray ();
591586}
592587
593588bool v8__Data__IsFunctionTemplate (const v8::Data& self) {
@@ -597,33 +592,34 @@ bool v8__Data__IsFunctionTemplate(const v8::Data& self) {
597592bool v8__Data__IsModule (const v8::Data& self) { return self.IsModule (); }
598593
599594bool v8__Data__IsModuleRequest (const v8::Data& self) {
600- return IsModuleRequest (* v8::Utils::OpenHandle (&self) );
595+ return self. IsModuleRequest ();
601596}
602597
603598bool v8__Data__IsName (const v8::Data& self) {
604- return IsName (* v8::Utils::OpenHandle (& self));
599+ return self. IsValue () && reinterpret_cast < const v8::Value&>( self). IsName ( );
605600}
606601
607602bool v8__Data__IsNumber (const v8::Data& self) {
608- return IsNumber (* v8::Utils::OpenHandle (& self));
603+ return self. IsValue () && reinterpret_cast < const v8::Value&>( self). IsNumber ( );
609604}
610605
611606bool v8__Data__IsObjectTemplate (const v8::Data& self) {
612607 return self.IsObjectTemplate ();
613608}
614609
615610bool v8__Data__IsPrimitive (const v8::Data& self) {
616- return IsPrimitive (*v8::Utils::OpenHandle (&self)) && !self.IsPrivate ();
611+ return self.IsValue () &&
612+ reinterpret_cast <const v8::Value&>(self).IsPrimitive ();
617613}
618614
619615bool v8__Data__IsPrivate (const v8::Data& self) { return self.IsPrivate (); }
620616
621617bool v8__Data__IsString (const v8::Data& self) {
622- return IsString (* v8::Utils::OpenHandle (& self));
618+ return self. IsValue () && reinterpret_cast < const v8::Value&>( self). IsString ( );
623619}
624620
625621bool v8__Data__IsSymbol (const v8::Data& self) {
626- return IsPublicSymbol (* v8::Utils::OpenHandle (& self));
622+ return self. IsValue () && reinterpret_cast < const v8::Value&>( self). IsSymbol ( );
627623}
628624
629625bool v8__Data__IsValue (const v8::Data& self) { return self.IsValue (); }
@@ -896,6 +892,8 @@ const v8::String* v8__Value__TypeOf(v8::Value& self, v8::Isolate* isolate) {
896892 return local_to_ptr (self.TypeOf (isolate));
897893}
898894
895+ uint32_t v8__Value__GetHash (v8::Value& self) { return self.GetHash (); }
896+
899897const v8::Primitive* v8__Null (v8::Isolate* isolate) {
900898 return local_to_ptr (v8::Null (isolate));
901899}
@@ -954,12 +952,6 @@ two_pointers_t v8__ArrayBuffer__GetBackingStore(const v8::ArrayBuffer& self) {
954952 return make_pod<two_pointers_t >(ptr_to_local (&self)->GetBackingStore ());
955953}
956954
957- v8::BackingStore* v8__BackingStore__EmptyBackingStore (bool shared) {
958- std::unique_ptr<i::BackingStoreBase> u = i::BackingStore::EmptyBackingStore (
959- shared ? i::SharedFlag::kShared : i::SharedFlag::kNotShared );
960- return static_cast <v8::BackingStore*>(u.release ());
961- }
962-
963955bool v8__BackingStore__IsResizableByUserJavaScript (
964956 const v8::BackingStore& self) {
965957 return ptr_to_local (&self)->IsResizableByUserJavaScript ();
@@ -2361,10 +2353,10 @@ const v8::Object* v8__PropertyCallbackInfo__Holder(
23612353 return local_to_ptr (self.HolderV2 ());
23622354}
23632355
2364- v8::internal::Address * v8__PropertyCallbackInfo__GetReturnValue (
2356+ uintptr_t * v8__PropertyCallbackInfo__GetReturnValue (
23652357 const v8::PropertyCallbackInfo<v8::Value>& self) {
23662358 v8::ReturnValue<v8::Value> rv = self.GetReturnValue ();
2367- return *reinterpret_cast <v8::internal::Address **>(&rv);
2359+ return *reinterpret_cast <uintptr_t **>(&rv);
23682360}
23692361
23702362bool v8__PropertyCallbackInfo__ShouldThrowOnError (
@@ -2877,8 +2869,6 @@ class UnprotectedDefaultPlatform : public v8::platform::DefaultPlatform {
28772869 using PriorityMode = v8::platform::PriorityMode;
28782870 using TracingController = v8::TracingController;
28792871
2880- static constexpr int kMaxThreadPoolSize = 16 ;
2881-
28822872 public:
28832873 explicit UnprotectedDefaultPlatform (
28842874 int thread_pool_size, IdleTaskSupport idle_task_support,
@@ -2888,28 +2878,8 @@ class UnprotectedDefaultPlatform : public v8::platform::DefaultPlatform {
28882878 std::move (tracing_controller),
28892879 priority_mode) {}
28902880
2891- static std::unique_ptr<v8::Platform> New (
2892- int thread_pool_size, IdleTaskSupport idle_task_support,
2893- InProcessStackDumping in_process_stack_dumping,
2894- std::unique_ptr<TracingController> tracing_controller = {},
2895- PriorityMode priority_mode = PriorityMode::kDontApply ) {
2896- // This implementation is semantically equivalent to the implementation of
2897- // `v8::platform::NewDefaultPlatform()`.
2898- DCHECK_GE (thread_pool_size, 0 );
2899- if (thread_pool_size < 1 ) {
2900- thread_pool_size =
2901- std::max (v8::base::SysInfo::NumberOfProcessors () - 1 , 1 );
2902- }
2903- thread_pool_size = std::min (thread_pool_size, kMaxThreadPoolSize );
2904- if (in_process_stack_dumping == InProcessStackDumping::kEnabled ) {
2905- v8::base::debug::EnableInProcessStackDumping ();
2906- }
2907- return std::make_unique<UnprotectedDefaultPlatform>(
2908- thread_pool_size, idle_task_support, std::move (tracing_controller),
2909- priority_mode);
2910- }
2911-
29122881 v8::ThreadIsolatedAllocator* GetThreadIsolatedAllocator () override {
2882+ // DefaultThreadIsolatedAllocator is PKU protected
29132883 return nullptr ;
29142884 }
29152885};
@@ -2926,11 +2896,14 @@ v8::Platform* v8__Platform__NewDefaultPlatform(int thread_pool_size,
29262896
29272897v8::Platform* v8__Platform__NewUnprotectedDefaultPlatform (
29282898 int thread_pool_size, bool idle_task_support) {
2929- return UnprotectedDefaultPlatform::New (
2930- thread_pool_size,
2931- idle_task_support ? v8::platform::IdleTaskSupport::kEnabled
2932- : v8::platform::IdleTaskSupport::kDisabled ,
2933- v8::platform::InProcessStackDumping::kDisabled , nullptr )
2899+ if (thread_pool_size < 1 ) {
2900+ thread_pool_size = std::thread::hardware_concurrency ();
2901+ }
2902+ thread_pool_size = std::max (std::min (thread_pool_size, 16 ), 1 );
2903+ return std::make_unique<UnprotectedDefaultPlatform>(
2904+ thread_pool_size, idle_task_support
2905+ ? v8::platform::IdleTaskSupport::kEnabled
2906+ : v8::platform::IdleTaskSupport::kDisabled )
29342907 .release ();
29352908}
29362909
@@ -3422,28 +3395,6 @@ void v8__HeapProfiler__TakeHeapSnapshot(v8::Isolate* isolate,
34223395 const_cast <v8::HeapSnapshot*>(snapshot)->Delete ();
34233396}
34243397
3425- v8::Isolate* v8__internal__GetIsolateFromHeapObject (const v8::Data& data) {
3426- namespace i = v8::internal;
3427- i::Tagged<i::Object> object (reinterpret_cast <const i::Address&>(data));
3428- i::Isolate* isolate;
3429- return IsHeapObject (object) &&
3430- i::GetIsolateFromHeapObject (object.GetHeapObject (), &isolate)
3431- ? reinterpret_cast <v8::Isolate*>(isolate)
3432- : nullptr ;
3433- }
3434-
3435- int v8__Value__GetHash (const v8::Value& data) {
3436- namespace i = v8::internal;
3437- i::Tagged<i::Object> object (reinterpret_cast <const i::Address&>(data));
3438- i::Isolate* isolate;
3439- int hash = IsHeapObject (object) && i::GetIsolateFromHeapObject (
3440- object.GetHeapObject (), &isolate)
3441- ? i::Object::GetOrCreateHash (object, isolate).value ()
3442- : i::Smi::ToInt (i::Object::GetHash (object));
3443- assert (hash != 0 );
3444- return hash;
3445- }
3446-
34473398void v8__HeapStatistics__CONSTRUCT (uninit_t <v8::HeapStatistics>* buf) {
34483399 // Should be <= than its counterpart in src/isolate.rs
34493400 static_assert (sizeof (v8::HeapStatistics) <= sizeof (uintptr_t [16 ]),
0 commit comments