-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathcontext_preserving.phpt
78 lines (68 loc) · 1.4 KB
/
context_preserving.phpt
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
--TEST--
Test V8::executeString() : test context preserving
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$JS_set = <<< EOT
var preserved = "ORIGINAL";
print("Set variable (" + PHP.ctx + ")\\n");
EOT;
$JS_change = <<< EOT
preserved = "CHANGED";
print("Change variable (" + PHP.ctx + ")\\n");
EOT;
$JS_read = <<< EOT
print("Read variable (" + PHP.ctx + ")\\n");
print("Result: " + preserved + "\\n");
EOT;
// First context: Set variable
$a = new V8Js();
$a->ctx = '#1';
try {
echo '1. ';
$a->executeString($JS_set, 'set.js');
} catch (V8JsScriptException $e) {
var_dump($e);
}
// Second context: Change variable
$b = new V8Js();
$b->ctx = '#2';
try {
echo '2. ';
$b->executeString($JS_change, 'change.js');
} catch (V8JsScriptException $e) {
var_dump($e);
}
// First context: Read variable
try {
echo '3. ';
$a->executeString($JS_read, 'read.js');
} catch (V8JsScriptException $e) {
var_dump($e);
}
// First context: Change variable
try {
echo '4. ';
$a->executeString($JS_change, 'change.js');
} catch (V8JsScriptException $e) {
var_dump($e);
}
// First context: Read variable again
try {
echo '5. ';
$a->executeString($JS_read, 'read.js');
} catch (V8JsScriptException $e) {
var_dump($e);
}
?>
===EOF===
--EXPECT--
1. Set variable (#1)
2. Change variable (#2)
3. Read variable (#1)
Result: ORIGINAL
4. Change variable (#1)
5. Read variable (#1)
Result: CHANGED
===EOF===