Skip to content

Commit

Permalink
Fixed segfault that occurred only when a timeout was set.
Browse files Browse the repository at this point in the history
  • Loading branch information
SLiV9 committed Apr 13, 2017
1 parent a212662 commit a52a08b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
8 changes: 3 additions & 5 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void Context::assign(Php::Parameters &params)
*
* @param params array with one parameter: the code to execute
* @return Php::Value
* @throws Php::Exception
*/
Php::Value Context::evaluate(Php::Parameters &params)
{
Expand Down Expand Up @@ -196,14 +197,11 @@ Php::Value Context::evaluate(Php::Parameters &params)
// in case we timeout we must terminate execution
if (status != std::cv_status::timeout) return;

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

// access the main threads context
v8::Local<v8::Context> context(_context);

// terminate execution
context->GetIsolate()->TerminateExecution();
_context->GetIsolate()->TerminateExecution();
}));

// execute the script
Expand Down
1 change: 1 addition & 0 deletions context.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Context : public Php::Base
*
* @param params array with one parameter: the code to execute
* @return Php::Value
* @throws Php::Exception
*/
Php::Value evaluate(Php::Parameters &params);
};
Expand Down
2 changes: 1 addition & 1 deletion stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Stack
*
* @return v8::Local<T>
*/
operator v8::Local<T> () const
operator const v8::Local<T> () const
{
// create the value
return v8::Local<T>::New(Isolate::get(), _handle);
Expand Down
6 changes: 5 additions & 1 deletion tests/test4.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

$context = new JS\Context();

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

0 comments on commit a52a08b

Please sign in to comment.