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

Commit 0dff926

Browse files
committed
Add test for PropertyCallbackInfo
1 parent 87fd600 commit 0dff926

File tree

4 files changed

+198
-5
lines changed

4 files changed

+198
-5
lines changed

src/php_v8_isolate.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static PHP_METHOD(V8Isolate, GetEnteredContext) {
371371
PHP_V8_ISOLATE_REQUIRE_IN_CONTEXT(isolate);
372372

373373
v8::Local<v8::Context> local_context = php_v8_isolate->isolate->GetEnteredContext();
374-
374+
375375
php_v8_context_t *php_v8_context = php_v8_context_get_reference(local_context);
376376

377377
ZVAL_OBJ(return_value, &php_v8_context->std);

stubs/src/Script.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public function GetContext(): Context
4545
}
4646

4747
/**
48-
* Runs the script returning the resulting value. It will be run in the
49-
* context in which it was created (ScriptCompiler::CompileBound or
50-
* UnboundScript::BindToCurrentContext()).
48+
* Runs the script returning the resulting value.
5149
*
5250
* @param \V8\Context $context
5351
*

stubs/src/StackTrace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(array $frames, ArrayObject $as_array)
5353
/**
5454
* Returns a StackFrame at a particular index.
5555
*
56-
* @return StackFrame
56+
* @return StackFrame[]
5757
*/
5858
public function GetFrames() : array
5959
{

tests/V8PropertyCallbackInfo.phpt

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
--TEST--
2+
V8\PropertyCallbackInfo
3+
--SKIPIF--
4+
<?php if (!extension_loaded("v8")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
use V8\Context;
9+
use V8\Isolate;
10+
use V8\NameValue;
11+
use V8\ObjectValue;
12+
use V8\PropertyCallbackInfo;
13+
use V8\Script;
14+
use V8\StringValue;
15+
16+
/** @var \Phpv8Testsuite $helper */
17+
$helper = require '.testsuite.php';
18+
19+
$isolate = new Isolate();
20+
21+
$context = new Context($isolate);
22+
23+
$prop_value = 'foo';
24+
25+
$getter = function (NameValue $property, PropertyCallbackInfo $info) use (&$prop_value, $helper, $isolate, $context) {
26+
27+
$helper->message('Property callback called');
28+
$helper->line();
29+
30+
$helper->header('Object representation');
31+
$helper->dump($info);
32+
$helper->space();
33+
34+
$helper->assert('Callback info holds original isolate object', $info->GetIsolate(), $isolate);
35+
$helper->assert('Callback info holds original isolate object', $info->GetContext(), $context);
36+
37+
$helper->space();
38+
39+
$info->GetReturnValue()->Set(new StringValue($info->GetIsolate(), $prop_value));
40+
};
41+
42+
43+
$obj = new ObjectValue($context);
44+
45+
$obj->SetAccessor($context, new StringValue($isolate, 'test'), $getter);
46+
47+
$context->GlobalObject()->Set($context, new StringValue($isolate, 'obj'), $obj);
48+
49+
$script1 = new Script($context, new StringValue($isolate, 'obj.test'));
50+
51+
52+
$helper->dump($script1->Run($context)->ToString($context)->Value());
53+
54+
?>
55+
--EXPECT--
56+
Property callback called
57+
58+
Object representation:
59+
----------------------
60+
object(V8\PropertyCallbackInfo)#8 (6) {
61+
["isolate":"V8\CallbackInfo":private]=>
62+
object(V8\Isolate)#2 (5) {
63+
["snapshot":"V8\Isolate":private]=>
64+
NULL
65+
["time_limit":"V8\Isolate":private]=>
66+
float(0)
67+
["time_limit_hit":"V8\Isolate":private]=>
68+
bool(false)
69+
["memory_limit":"V8\Isolate":private]=>
70+
int(0)
71+
["memory_limit_hit":"V8\Isolate":private]=>
72+
bool(false)
73+
}
74+
["context":"V8\CallbackInfo":private]=>
75+
object(V8\Context)#3 (1) {
76+
["isolate":"V8\Context":private]=>
77+
object(V8\Isolate)#2 (5) {
78+
["snapshot":"V8\Isolate":private]=>
79+
NULL
80+
["time_limit":"V8\Isolate":private]=>
81+
float(0)
82+
["time_limit_hit":"V8\Isolate":private]=>
83+
bool(false)
84+
["memory_limit":"V8\Isolate":private]=>
85+
int(0)
86+
["memory_limit_hit":"V8\Isolate":private]=>
87+
bool(false)
88+
}
89+
}
90+
["this":"V8\CallbackInfo":private]=>
91+
object(V8\ObjectValue)#5 (2) {
92+
["isolate":"V8\Value":private]=>
93+
object(V8\Isolate)#2 (5) {
94+
["snapshot":"V8\Isolate":private]=>
95+
NULL
96+
["time_limit":"V8\Isolate":private]=>
97+
float(0)
98+
["time_limit_hit":"V8\Isolate":private]=>
99+
bool(false)
100+
["memory_limit":"V8\Isolate":private]=>
101+
int(0)
102+
["memory_limit_hit":"V8\Isolate":private]=>
103+
bool(false)
104+
}
105+
["context":"V8\ObjectValue":private]=>
106+
object(V8\Context)#3 (1) {
107+
["isolate":"V8\Context":private]=>
108+
object(V8\Isolate)#2 (5) {
109+
["snapshot":"V8\Isolate":private]=>
110+
NULL
111+
["time_limit":"V8\Isolate":private]=>
112+
float(0)
113+
["time_limit_hit":"V8\Isolate":private]=>
114+
bool(false)
115+
["memory_limit":"V8\Isolate":private]=>
116+
int(0)
117+
["memory_limit_hit":"V8\Isolate":private]=>
118+
bool(false)
119+
}
120+
}
121+
}
122+
["holder":"V8\CallbackInfo":private]=>
123+
object(V8\ObjectValue)#5 (2) {
124+
["isolate":"V8\Value":private]=>
125+
object(V8\Isolate)#2 (5) {
126+
["snapshot":"V8\Isolate":private]=>
127+
NULL
128+
["time_limit":"V8\Isolate":private]=>
129+
float(0)
130+
["time_limit_hit":"V8\Isolate":private]=>
131+
bool(false)
132+
["memory_limit":"V8\Isolate":private]=>
133+
int(0)
134+
["memory_limit_hit":"V8\Isolate":private]=>
135+
bool(false)
136+
}
137+
["context":"V8\ObjectValue":private]=>
138+
object(V8\Context)#3 (1) {
139+
["isolate":"V8\Context":private]=>
140+
object(V8\Isolate)#2 (5) {
141+
["snapshot":"V8\Isolate":private]=>
142+
NULL
143+
["time_limit":"V8\Isolate":private]=>
144+
float(0)
145+
["time_limit_hit":"V8\Isolate":private]=>
146+
bool(false)
147+
["memory_limit":"V8\Isolate":private]=>
148+
int(0)
149+
["memory_limit_hit":"V8\Isolate":private]=>
150+
bool(false)
151+
}
152+
}
153+
}
154+
["return_value":"V8\CallbackInfo":private]=>
155+
object(V8\ReturnValue)#9 (2) {
156+
["isolate":"V8\ReturnValue":private]=>
157+
object(V8\Isolate)#2 (5) {
158+
["snapshot":"V8\Isolate":private]=>
159+
NULL
160+
["time_limit":"V8\Isolate":private]=>
161+
float(0)
162+
["time_limit_hit":"V8\Isolate":private]=>
163+
bool(false)
164+
["memory_limit":"V8\Isolate":private]=>
165+
int(0)
166+
["memory_limit_hit":"V8\Isolate":private]=>
167+
bool(false)
168+
}
169+
["context":"V8\ReturnValue":private]=>
170+
object(V8\Context)#3 (1) {
171+
["isolate":"V8\Context":private]=>
172+
object(V8\Isolate)#2 (5) {
173+
["snapshot":"V8\Isolate":private]=>
174+
NULL
175+
["time_limit":"V8\Isolate":private]=>
176+
float(0)
177+
["time_limit_hit":"V8\Isolate":private]=>
178+
bool(false)
179+
["memory_limit":"V8\Isolate":private]=>
180+
int(0)
181+
["memory_limit_hit":"V8\Isolate":private]=>
182+
bool(false)
183+
}
184+
}
185+
}
186+
["should_throw_on_error":"V8\PropertyCallbackInfo":private]=>
187+
bool(false)
188+
}
189+
190+
191+
Callback info holds original isolate object: ok
192+
Callback info holds original isolate object: ok
193+
194+
195+
string(3) "foo"

0 commit comments

Comments
 (0)