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

Commit 7d94fe6

Browse files
committed
Check whether returned context is empty in V8\Isolate\GetEnteredContext() instead of checking InContext()
1 parent c853d30 commit 7d94fe6

File tree

6 files changed

+132
-16
lines changed

6 files changed

+132
-16
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ project(php_v8)
33

44
# NOTE: This CMake file is just for syntax highlighting in CLion
55

6-
include_directories(/usr/local/opt/v8@5.8/include)
7-
include_directories(/usr/local/opt/v8@5.8/include/libplatform)
6+
include_directories(/usr/local/opt/v8@5.9/include)
7+
include_directories(/usr/local/opt/v8@5.9/include/libplatform)
88

99
include_directories(/usr/local/include/php)
1010
include_directories(/usr/local/include/php/TSRM)

Vagrantfile

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5+
VAGRANTFILE_API_VERSION = "2"
6+
7+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8+
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" # Prevent TTY Errors
9+
10+
config.vm.box = "bento/ubuntu-16.04"
11+
12+
# config.vm.box_check_update = false
13+
14+
config.vm.network "private_network", ip: "192.168.33.44"
15+
# config.vm.network "public_network"
16+
17+
# If true, then any SSH connections made will enable agent forwarding.
18+
# Default value: false
19+
# config.ssh.forward_agent = true
20+
21+
config.vm.synced_folder ".", "/home/vagrant/php-v8"
22+
23+
# Provider-specific configuration so you can fine-tune various
24+
# backing providers for Vagrant. These expose provider-specific options.
25+
# Example for VirtualBox:
26+
#
27+
config.vm.provider "virtualbox" do |vb|
28+
# Don't boot with headless mode
29+
# vb.gui = true
30+
31+
# Use VBoxManage to customize the VM. For example to change memory:
32+
vb.customize ["modifyvm", :id, "--memory", 2048]
33+
vb.customize ["modifyvm", :id, "--cpus", 2]
34+
end
35+
#
36+
# View the documentation for the provider you're using for more
37+
# information on available options.
38+
39+
# Enable provisioning with CFEngine. CFEngine Community packages are
40+
# automatically installed. For example, configure the host as a
41+
# policy server and optionally a policy file to run:
42+
#
43+
# config.vm.provision "cfengine" do |cf|
44+
# cf.am_policy_hub = true
45+
# # cf.run_file = "motd.cf"
46+
# end
47+
#
48+
# You can also configure and bootstrap a client to an existing
49+
# policy server:
50+
#
51+
# config.vm.provision "cfengine" do |cf|
52+
# cf.policy_server_address = "10.0.2.15"
53+
# end
54+
55+
# Enable provisioning with Puppet stand alone. Puppet manifests
56+
# are contained in a directory path relative to this Vagrantfile.
57+
# You will need to create the manifests directory and a manifest in
58+
# the file default.pp in the manifests_path directory.
59+
#
60+
# config.vm.provision "puppet" do |puppet|
61+
# puppet.manifests_path = "manifests"
62+
# puppet.manifest_file = "default.pp"
63+
# end
64+
65+
# Enable provisioning with chef solo, specifying a cookbooks path, roles
66+
# path, and data_bags path (all relative to this Vagrantfile), and adding
67+
# some recipes and/or roles.
68+
#
69+
# config.vm.provision "chef_solo" do |chef|
70+
# chef.cookbooks_path = "../my-recipes/cookbooks"
71+
# chef.roles_path = "../my-recipes/roles"
72+
# chef.data_bags_path = "../my-recipes/data_bags"
73+
# chef.add_recipe "mysql"
74+
# chef.add_role "web"
75+
#
76+
# # You may also specify custom JSON attributes:
77+
# chef.json = { mysql_password: "foo" }
78+
# end
79+
80+
#config.vm.provision "shell", path: './provision/provision.sh', privileged: false
81+
end

src/php_v8_isolate.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,13 @@ static PHP_METHOD(V8Isolate, GetEnteredContext) {
363363
PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);
364364
PHP_V8_ENTER_ISOLATE(php_v8_isolate)
365365

366-
PHP_V8_ISOLATE_REQUIRE_IN_CONTEXT(isolate);
367-
368366
v8::Local<v8::Context> local_context = php_v8_isolate->isolate->GetEnteredContext();
369367

368+
if (local_context.IsEmpty()) {
369+
PHP_V8_THROW_EXCEPTION("Isolate doesn't have entered context");
370+
return;
371+
}
372+
370373
php_v8_context_t *php_v8_context = php_v8_context_get_reference(local_context);
371374

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

tests/V8Isolate.phpt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ $helper->header('Object representation');
1616
$helper->dump($isolate);
1717
$helper->line();
1818

19-
try {
20-
$isolate->GetEnteredContext();
21-
} catch (Exception $e) {
22-
$helper->exception_export($e);
23-
}
24-
25-
$helper->line();
2619
$helper->method_export($isolate, 'GetHeapStatistics');
2720

2821
$isolate = null;
@@ -43,10 +36,8 @@ object(V8\Isolate)#2 (5) {
4336
bool(false)
4437
}
4538

46-
V8\Exceptions\Exception: Not in context!
47-
4839
V8\Isolate->GetHeapStatistics():
49-
object(V8\HeapStatistics)#29 (9) {
40+
object(V8\HeapStatistics)#28 (9) {
5041
["total_heap_size":"V8\HeapStatistics":private]=>
5142
float(%d)
5243
["total_heap_size_executable":"V8\HeapStatistics":private]=>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
V8\Isolate::GetEnteredContext()
3+
--SKIPIF--
4+
<?php if (!extension_loaded("v8")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
/** @var \Phpv8Testsuite $helper */
8+
$helper = require '.testsuite.php';
9+
10+
require '.v8-helpers.php';
11+
$v8_helper = new PhpV8Helpers($helper);
12+
13+
14+
$isolate = new \V8\Isolate();
15+
16+
try {
17+
$isolate->GetEnteredContext();
18+
}catch (\V8\Exceptions\Exception $e) {
19+
$helper->exception_export($e);
20+
}
21+
22+
23+
$helper->line();
24+
25+
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) use ($helper) {
26+
$helper->assert('Isolate has entered context', $info->GetIsolate()->GetEnteredContext() === $info->GetContext());
27+
});
28+
29+
30+
$global_tpl = new \V8\ObjectTemplate($isolate);
31+
$global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_tpl);
32+
33+
$context = new \V8\Context($isolate, $global_tpl);
34+
35+
$v8_helper->CompileTryRun($context, 'test()');
36+
37+
38+
39+
?>
40+
--EXPECT--
41+
V8\Exceptions\Exception: Isolate doesn't have entered context
42+
43+
Isolate has entered context: ok

tests/V8Isolate_ThrowException.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ $v8_helper = new PhpV8Helpers($helper);
1313

1414
$isolate = new \V8\Isolate();
1515

16-
$helper->line();
17-
1816
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) {
1917
$value = count($info->Arguments()) ? $info->Arguments()[0] : new \V8\StringValue($info->GetIsolate(), "exception");
2018

0 commit comments

Comments
 (0)