forked from rosebudai/OpenRCT2-Web
Fix PluginScope for promises
This commit is contained in:
1 parent
99dee55494
commit
e924c00a0d
3 files changed
+26
No files matched your search
@@ -1135,6 +1135,23 @@ void ScriptEngine::Tick()
|
||||
JSContext* jobCtx;
|
||||
while (true)
|
||||
{
|
||||
// TODO: this is a bit of a hack, perhaps the PluginScope class should be replaced by a better way of tracking context
|
||||
// Lookup the plugin from the context with a slow linear search
|
||||
JSContext* ctx = JS_GetPendingJobContext(_runtime);
|
||||
std::shared_ptr<Plugin> plugin;
|
||||
if (ctx != nullptr)
|
||||
{
|
||||
for (const auto& p : _plugins)
|
||||
{
|
||||
if (p->GetContext() == ctx)
|
||||
{
|
||||
plugin = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ScriptExecutionInfo::PluginScope scope(_execInfo, plugin, false);
|
||||
|
||||
if (JS_ExecutePendingJob(_runtime, &jobCtx) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
+8
@@ -12344,6 +12344,14 @@ bool JS_IsJobPending(JSRuntime *rt)
|
||||
return !list_empty(&rt->job_list);
|
||||
}
|
||||
|
||||
JSContext *JS_GetPendingJobContext(JSRuntime *rt)
|
||||
{
|
||||
if (JS_IsJobPending(rt)) {
|
||||
return list_entry(rt->job_list.next, JSJobEntry, link)->ctx;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* return < 0 if exception, 0 if no job pending, 1 if a job was
|
||||
executed successfully. the context of the job is stored in '*pctx' */
|
||||
int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx)
|
||||
|
||||
Vendored
+1
@@ -1193,6 +1193,7 @@ JS_EXTERN int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func,
|
||||
int argc, JSValueConst *argv);
|
||||
|
||||
JS_EXTERN bool JS_IsJobPending(JSRuntime *rt);
|
||||
JS_EXTERN JSContext *JS_GetPendingJobContext(JSRuntime *rt);
|
||||
JS_EXTERN int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx);
|
||||
|
||||
/* Structure to retrieve (de)serialized SharedArrayBuffer objects. */
|
||||
|
||||
Reference in new issue
Block a user