This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathStackTrace.php
103 lines (88 loc) · 2.42 KB
/
StackTrace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php declare(strict_types=1);
/**
* This file is part of the phpv8/php-v8 PHP extension.
*
* Copyright (c) 2015-2018 Bogdan Padalko <thepinepain@gmail.com>
*
* Licensed under the MIT license: http://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the
* LICENSE file that was distributed with this source or visit
* http://opensource.org/licenses/MIT
*/
namespace V8;
use V8\Exceptions\Exception;
/**
* Representation of a JavaScript stack trace. The information collected is a
* snapshot of the execution stack and the information remains valid after
* execution continues.
*/
class StackTrace
{
const MIN_FRAME_LIMIT = 0;
const MAX_FRAME_LIMIT = 1000;
/**
* @var array|StackFrame[]
*/
private $frames;
/**
* @param StackFrame[] $frames
*/
public function __construct(array $frames)
{
$this->frames = $frames;
}
/**
* Returns a StackFrame at a particular index.
*
* @return StackFrame[]
*/
public function getFrames(): array
{
return $this->frames;
}
/**
* Returns a StackFrame at a particular index.
*
* @param int $index
*
* @return StackFrame
*
* @throws Exception When index is out of range
*/
public function getFrame(int $index): StackFrame
{
if ($index < 0 || !isset($this->frames[$index])) {
throw new Exception('Frame index is out of range');
}
return $this->frames[$index];
}
/**
* Returns the number of StackFrames.
*
* @return int
*/
public function getFrameCount(): int
{
return count($this->frames);
}
/**
* Grab a snapshot of the current JavaScript execution stack.
*
* \param frame_limit The maximum number of stack frames we want to capture.
* \param options Enumerates the set of things we will capture for each
* StackFrame.
*
* @param Isolate $isolate
* @param int $frame_limit
*
* TODO: try to minimize effect of invalid args
* Note, that having large (or negative) $frame_limit number may cause OutOfMemory error.
* To minimize any potentially erroneous usage, allowed range for $frame_limit is [0, 1000] (boundaries included).
*
* @return StackTrace
*/
public static function currentStackTrace(Isolate $isolate, int $frame_limit): StackTrace
{
}
}