mirror of
https://github.com/matrix-construct/construct
synced 2024-11-18 07:50:57 +01:00
ircd::js: Use a script object in the task (more flexible than function).
This commit is contained in:
parent
f54c4215b4
commit
333b0dca5a
2 changed files with 3 additions and 4 deletions
|
@ -30,7 +30,7 @@ struct task
|
||||||
{
|
{
|
||||||
uint64_t pid;
|
uint64_t pid;
|
||||||
struct global global; // global / this / root scope object
|
struct global global; // global / this / root scope object
|
||||||
heap_function main; // main generator wrapper function
|
heap_script main; // main generator wrapper script
|
||||||
struct generator generator; // generator state
|
struct generator generator; // generator state
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -175,11 +175,10 @@ try
|
||||||
|
|
||||||
// TODO: options
|
// TODO: options
|
||||||
JS::CompileOptions opts(*cx);
|
JS::CompileOptions opts(*cx);
|
||||||
JS::AutoObjectVector stack(*cx);
|
|
||||||
|
|
||||||
// The function must be compiled in this scope and returned as a heap_function
|
// The function must be compiled in this scope and returned as a heap_function
|
||||||
// before the compartment destructs.
|
// before the compartment destructs.
|
||||||
return heap_function { stack, opts, "main", {}, source };
|
return heap_script { opts, source };
|
||||||
}()}
|
}()}
|
||||||
,generator{[this]
|
,generator{[this]
|
||||||
{
|
{
|
||||||
|
@ -190,7 +189,7 @@ try
|
||||||
// The run() closure provides safety for entering the JS engine.
|
// The run() closure provides safety for entering the JS engine.
|
||||||
value state(run([this]
|
value state(run([this]
|
||||||
{
|
{
|
||||||
return this->main(this->global);
|
return this->main();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Construct the generator object here on the stack while in a compartment. The
|
// Construct the generator object here on the stack while in a compartment. The
|
||||||
|
|
Loading…
Reference in a new issue