Completed
Push — wip-public-release ( 7c11a5...54ec9d )
by Bogdan
05:19
created

ExecutionContext::getFunctionSpec()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/php-v8-js-sandbox PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the
11
 * LICENSE file that was distributed with this source or visit
12
 * http://opensource.org/licenses/MIT
13
 */
14
15
16
namespace Pinepain\JsSandbox\Wrappers\FunctionComponents\Runtime;
17
18
19
use Pinepain\JsSandbox\NativeWrappers\NativeFunctionWrapper;
20
use Pinepain\JsSandbox\NativeWrappers\NativeFunctionWrapperInterface;
21
use Pinepain\JsSandbox\Specs\FunctionSpecInterface;
22
use Pinepain\JsSandbox\Wrappers\Runtime\RuntimeFunction;
23
use Pinepain\JsSandbox\Wrappers\WrapperInterface;
24
use V8\Context;
25
use V8\FunctionCallbackInfo;
26
use V8\FunctionObject;
27
use V8\Isolate;
28
use V8\ObjectValue;
29
30
31
class ExecutionContext implements ExecutionContextInterface
32
{
33
    /**
34
     * @var WrapperInterface
35
     */
36
    private $wrapper;
37
    /**
38
     * @var RuntimeFunction
39
     */
40
    private $runtime_function;
41
    /**
42
     * @var FunctionCallbackInfo
43
     */
44
    private $args;
45
    /**
46
     * @var FunctionSpecInterface
47
     */
48
    private $spec;
49
50
    public function __construct(WrapperInterface $wrapper, RuntimeFunction $runtime_function, FunctionCallbackInfo $args, FunctionSpecInterface $spec)
51
    {
52
        $this->wrapper          = $wrapper;
53
        $this->runtime_function = $runtime_function;
54
        $this->args             = $args;
55
        $this->spec             = $spec;
56
    }
57
58
    public function getIsolate(): Isolate
59
    {
60
        return $this->args->getIsolate();
61
    }
62
63
    public function getContext(): Context
64
    {
65
        return $this->args->getContext();
66
    }
67
68
    public function getThis(): ObjectValue
69
    {
70
        return $this->args->this();
71
    }
72
73
    public function getWrapper(): WrapperInterface
74
    {
75
        return $this->wrapper;
76
    }
77
78
    public function getFunctionCallbackInfo(): FunctionCallbackInfo
79
    {
80
        return $this->args;
81
    }
82
83
    public function getFunctionSpec(): FunctionSpecInterface
84
    {
85
        return $this->spec;
86
    }
87
88
    public function getRuntimeFunction(): RuntimeFunction
89
    {
90
        return $this->runtime_function;
91
    }
92
93
    public function getFunctionObject(): FunctionObject
94
    {
95
        // At this time we should always have request RuntimeFunction be in cache
96
        return $this->wrap($this->getRuntimeFunction());
97
    }
98
99
    public function wrap($value)
100
    {
101
        return $this->wrapper->wrap($this->getIsolate(), $this->getContext(), $value);
102
    }
103
104
    public function wrapNativeFunction(ObjectValue $recv, FunctionObject $function_object): NativeFunctionWrapperInterface
105
    {
106
        return new NativeFunctionWrapper($this->getContext(), $recv, $function_object, $this->getWrapper());
107
    }
108
}
109