Passed
Push — master ( acfd8f...2200ae )
by Bogdan
04:01
created

ExecutionContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 1
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/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\RuntimeFunctionInterface;
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 RuntimeFunctionInterface
39
     */
40
    private $runtime_function;
41
    /**
42
     * @var FunctionCallbackInfo
43
     */
44
    private $args;
45
    /**
46
     * @var FunctionSpecInterface
47
     */
48
    private $spec;
49
50 4
    public function __construct(WrapperInterface $wrapper, RuntimeFunctionInterface $runtime_function, FunctionCallbackInfo $args, FunctionSpecInterface $spec)
51
    {
52 4
        $this->wrapper          = $wrapper;
53 4
        $this->runtime_function = $runtime_function;
54 4
        $this->args             = $args;
55 4
        $this->spec             = $spec;
56 4
    }
57
58 3
    public function getIsolate(): Isolate
59
    {
60 3
        return $this->args->getIsolate();
61
    }
62
63 3
    public function getContext(): Context
64
    {
65 3
        return $this->args->getContext();
66
    }
67
68 1
    public function getThis(): ObjectValue
69
    {
70 1
        return $this->args->this();
71
    }
72
73 2
    public function getWrapper(): WrapperInterface
74
    {
75 2
        return $this->wrapper;
76
    }
77
78 2
    public function getRuntimeFunction(): RuntimeFunctionInterface
79
    {
80 2
        return $this->runtime_function;
81
    }
82
83 1
    public function getFunctionCallbackInfo(): FunctionCallbackInfo
84
    {
85 1
        return $this->args;
86
    }
87
88 1
    public function getFunctionSpec(): FunctionSpecInterface
89
    {
90 1
        return $this->spec;
91
    }
92
93 1
    public function getFunctionObject(): FunctionObject
94
    {
95
        // At this time we should always have request RuntimeFunction be in cache
96 1
        return $this->wrap($this->getRuntimeFunction());
97
    }
98
99 1
    public function wrap($value)
100
    {
101 1
        return $this->wrapper->wrap($this->getIsolate(), $this->getContext(), $value);
102
    }
103
104 1
    public function wrapNativeFunction(ObjectValue $recv, FunctionObject $function_object): NativeFunctionWrapperInterface
105
    {
106 1
        return new NativeFunctionWrapper($this->getIsolate(), $this->getContext(), $function_object, $this->getWrapper(), $recv);
107
    }
108
}
109