@@ -56,6 +56,10 @@ void CV8ResourceImpl::ProcessDynamicImports()
56
56
dynamicImports.clear ();
57
57
}
58
58
59
+ static std::string bootstrap_code =
60
+ #include " bootstrap.js.gen"
61
+ ;
62
+
59
63
extern V8Module altModule;
60
64
bool CV8ResourceImpl::Start ()
61
65
{
@@ -94,34 +98,24 @@ bool CV8ResourceImpl::Start()
94
98
alt::IPackage::File* file = pkg->OpenFile (path);
95
99
96
100
size_t fileSize = pkg->GetFileSize (file);
97
- uint8_t * byteBuffer = new uint8_t [ fileSize] ;
98
- pkg->ReadFile (file, byteBuffer, fileSize);
101
+ std::vector< uint8_t > byteBuffer ( fileSize) ;
102
+ pkg->ReadFile (file, byteBuffer. data () , fileSize);
99
103
pkg->CloseFile (file);
100
104
101
- isUsingBytecode = IsBytecodeModule (byteBuffer, fileSize);
105
+ isUsingBytecode = IsBytecodeModule (byteBuffer. data () , fileSize);
102
106
103
107
Log::Info << " [V8] Starting script " << path << Log::Endl;
104
108
105
109
bool result = V8Helpers::TryCatch ([&]() {
106
110
v8::MaybeLocal<v8::Module> maybeModule;
107
- if (!isUsingBytecode)
108
- {
109
- alt::String src{ (char *)byteBuffer, fileSize };
110
- v8::ScriptOrigin scriptOrigin (isolate, V8Helpers::JSValue (path), 0 , 0 , false , -1 , v8::Local<v8::Value>(), false , false , true , v8::Local<v8::PrimitiveArray>());
111
- v8::ScriptCompiler::Source source{ V8Helpers::JSValue (src), scriptOrigin };
112
- maybeModule = v8::ScriptCompiler::CompileModule (isolate, &source);
113
- }
114
- else
115
- {
116
- maybeModule = ResolveBytecode (path, byteBuffer, fileSize);
117
- }
111
+ v8::ScriptOrigin scriptOrigin (isolate, V8Helpers::JSValue (" <bootstrapper>" ), 0 , 0 , false , -1 , v8::Local<v8::Value>(), false , false , true , v8::Local<v8::PrimitiveArray>());
112
+ v8::ScriptCompiler::Source source{ V8Helpers::JSValue (bootstrap_code), scriptOrigin };
113
+ maybeModule = v8::ScriptCompiler::CompileModule (isolate, &source);
118
114
119
115
if (maybeModule.IsEmpty ()) return false ;
120
116
121
117
v8::Local<v8::Module> curModule = maybeModule.ToLocalChecked ();
122
118
123
- modules.emplace (path, v8::UniquePersistent<v8::Module>{ isolate, curModule });
124
-
125
119
auto exports = altModule.GetExports (isolate, ctx);
126
120
// Overwrite global console object
127
121
auto console = ctx->Global ()->Get (ctx, V8Helpers::JSValue (" console" )).ToLocalChecked ().As <v8::Object>();
@@ -141,13 +135,16 @@ bool CV8ResourceImpl::Start()
141
135
ctx->Global ()->Set (ctx, V8Helpers::JSValue (" clearTimeout" ), exports->Get (ctx, V8Helpers::JSValue (" clearTimeout" )).ToLocalChecked ());
142
136
143
137
ctx->Global ()->Set (ctx, V8Helpers::JSValue (" __internal_get_exports" ), v8::Function::New (ctx, &StaticRequire).ToLocalChecked ());
138
+ ctx->Global ()->Set (ctx, V8Helpers::JSValue (" __internal_main_path" ), V8Helpers::JSValue (path));
144
139
145
140
bool res = curModule->InstantiateModule (ctx, CV8ScriptRuntime::ResolveModule).IsJust ();
146
141
147
142
if (!res) return false ;
148
143
149
144
v8::MaybeLocal<v8::Value> v = curModule->Evaluate (ctx);
150
145
146
+ isPreloading = false ;
147
+
151
148
if (v.IsEmpty ()) return false ;
152
149
153
150
if (curModule->GetStatus () == v8::Module::Status::kErrored )
@@ -165,17 +162,9 @@ bool CV8ResourceImpl::Start()
165
162
alt::MValue _exports = V8Helpers::V8ToMValue (curModule->GetModuleNamespace ());
166
163
resource->SetExports (_exports.As <alt::IMValueDict>());
167
164
168
- if (curModule->IsGraphAsync ()) Log::Warning << " [V8] Top level await is an experimental feature, use it at your own risk" << Log::Endl;
169
-
170
165
Log::Info << " [V8] Started script " << path << Log::Endl;
171
166
return true ;
172
167
});
173
- delete byteBuffer;
174
-
175
- if (!result)
176
- {
177
- modules.erase (path);
178
- }
179
168
180
169
DispatchStartEvent (!result);
181
170
@@ -514,9 +503,9 @@ v8::MaybeLocal<v8::Value> CV8ResourceImpl::GetSyntheticModuleExport(v8::Local<v8
514
503
return v8::MaybeLocal<v8::Value>();
515
504
}
516
505
517
- void CV8ResourceImpl::HandleWebViewEventQueue (const alt::Ref<alt::IWebView> view)
506
+ void CV8ResourceImpl::HandleWebViewEventQueue (alt::Ref<alt::IWebView> view)
518
507
{
519
- auto & eventQueuesMap = this -> GetWebviewsEventQueue ();
508
+ auto & eventQueuesMap = GetWebviewsEventQueue ();
520
509
if (!eventQueuesMap.count (view)) return ;
521
510
522
511
auto & eventQueue = eventQueuesMap.at (view);
0 commit comments