Skip to content

Commit a52a08b

Browse files
committed
Fixed segfault that occurred only when a timeout was set.
1 parent a212662 commit a52a08b

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

context.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void Context::assign(Php::Parameters &params)
141141
*
142142
* @param params array with one parameter: the code to execute
143143
* @return Php::Value
144+
* @throws Php::Exception
144145
*/
145146
Php::Value Context::evaluate(Php::Parameters &params)
146147
{
@@ -196,14 +197,11 @@ Php::Value Context::evaluate(Php::Parameters &params)
196197
// in case we timeout we must terminate execution
197198
if (status != std::cv_status::timeout) return;
198199

199-
// create a handle, so the local variable created below falls out of scope
200+
// create a handle for the local variable that is created by dereferencing _context
200201
v8::HandleScope scope(Isolate::get());
201202

202-
// access the main threads context
203-
v8::Local<v8::Context> context(_context);
204-
205203
// terminate execution
206-
context->GetIsolate()->TerminateExecution();
204+
_context->GetIsolate()->TerminateExecution();
207205
}));
208206

209207
// execute the script

context.h

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class Context : public Php::Base
116116
*
117117
* @param params array with one parameter: the code to execute
118118
* @return Php::Value
119+
* @throws Php::Exception
119120
*/
120121
Php::Value evaluate(Php::Parameters &params);
121122
};

stack.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Stack
9191
*
9292
* @return v8::Local<T>
9393
*/
94-
operator v8::Local<T> () const
94+
operator const v8::Local<T> () const
9595
{
9696
// create the value
9797
return v8::Local<T>::New(Isolate::get(), _handle);

tests/test4.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
$context = new JS\Context();
44

5-
$context->evaluate("3;", 5);
5+
for ($i = 1; $i <= 1000000; $i++)
6+
{
7+
if ($i % 1000 == 0) echo($i . PHP_EOL);
8+
$context->evaluate("$i;", 1);
9+
}

0 commit comments

Comments
 (0)