Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit a8cd558

Browse files
committed
Pass runtime function to allow on the fly callback swap
1 parent 1157ac8 commit a8cd558

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/Wrappers/FunctionComponents/FunctionCallHandler.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
namespace Pinepain\JsSandbox\Wrappers\FunctionComponents;
1717

1818

19-
use Pinepain\JsSandbox\Specs\FunctionSpecInterface;
2019
use Pinepain\JsSandbox\Wrappers\FunctionComponents\Runtime\ColdExecutionContextInterface;
20+
use Pinepain\JsSandbox\Wrappers\Runtime\RuntimeFunctionInterface;
2121
use Throwable;
2222
use V8\FunctionCallbackInfo;
2323

@@ -59,9 +59,12 @@ public function __construct(
5959
$this->return_setter = $return_setter;
6060
}
6161

62-
public function wrap(callable $callback, FunctionSpecInterface $spec, ColdExecutionContextInterface $cold_execution_context)
62+
public function wrap(RuntimeFunctionInterface $function, ColdExecutionContextInterface $cold_execution_context)
6363
{
64-
return function (FunctionCallbackInfo $args) use ($callback, $spec, $cold_execution_context) {
64+
return function (FunctionCallbackInfo $args) use ($function, $cold_execution_context) {
65+
$spec = $function->getSpec();
66+
$callback = $function->getCallback();
67+
6568
$arguments = $this->arguments_extractor->extract($args, $spec);
6669

6770
if ($spec->getDecorators()) {

src/Wrappers/FunctionComponents/FunctionCallHandlerInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
use Pinepain\JsSandbox\Specs\FunctionSpecInterface;
2020
use Pinepain\JsSandbox\Wrappers\FunctionComponents\Runtime\ColdExecutionContextInterface;
21+
use Pinepain\JsSandbox\Wrappers\Runtime\RuntimeFunctionInterface;
2122

2223

2324
interface FunctionCallHandlerInterface
2425
{
25-
public function wrap(callable $callback, FunctionSpecInterface $spec, ColdExecutionContextInterface $cold_execution_context);
26+
public function wrap(RuntimeFunctionInterface $function, ColdExecutionContextInterface $cold_execution_context);
2627
}

src/Wrappers/FunctionWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function wrap(Isolate $isolate, Context $context, $value): FunctionObject
7777

7878
$cold_execution_context = new ColdExecutionContext($this->wrapper, $value);
7979

80-
$callback = $this->handler->wrap($value->getCallback(), $value->getSpec(), $cold_execution_context);
80+
$callback = $this->handler->wrap($value, $cold_execution_context);
8181
$callback = $this->guard->guard($callback);
8282

8383
$f = new FunctionObject($context, $callback);

0 commit comments

Comments
 (0)