Skip to content

Commit 120fd7d

Browse files
committed
Fix segfault when assigning 'null' value to the context.
1 parent 3cbbf33 commit 120fd7d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

platform.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,17 @@ Platform::Platform() :
5454
*/
5555
Platform::~Platform()
5656
{
57-
// we are no longer running
58-
_running = false;
57+
// we stop the platform first
58+
stop();
59+
}
60+
61+
/**
62+
* Stop running the platform.
63+
*/
64+
void Platform::stop()
65+
{
66+
// we set it to false, but if the old value was not true then we leap out
67+
if (!_running.exchange(false)) return;
5968

6069
// signal the thread in case it is waiting for input
6170
_condition.notify_one();
@@ -159,8 +168,8 @@ void Platform::shutdown()
159168
// still not set, we need to create it now
160169
if (result != nullptr)
161170
{
162-
// create the platform
163-
delete result;
171+
// we need to stop the platform before disposing and shutting it down
172+
result->stop();
164173

165174
// and shut down the engine (this also takes care of the ICU) and the platform
166175
v8::V8::Dispose();
@@ -171,7 +180,10 @@ void Platform::shutdown()
171180

172181
// store the new platform
173182
platform.store(nullptr, std::memory_order_relaxed);
174-
}
183+
184+
// delete the platform
185+
delete result;
186+
}
175187
}
176188
}
177189

platform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class Platform : public v8::Platform
6363
* @var std::thread
6464
*/
6565
std::thread _worker;
66+
67+
/**
68+
* (blocking) method to stop running a platform.
69+
*/
70+
void stop();
6671

6772
/**
6873
* Execute some work, this is called

value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ v8::Handle<v8::Value> value(const Php::Value &input)
8383
// the value can be of many types
8484
switch (input.type())
8585
{
86-
case Php::Type::Null: /* don't set anything, let it be empty */ break;
86+
case Php::Type::Null: result = v8::Null(Isolate::get()); break;
8787
case Php::Type::Numeric: result = v8::Integer::New(Isolate::get(), input); break;
8888
case Php::Type::Float: result = v8::Number::New(Isolate::get(), input); break;
8989
case Php::Type::Bool: result = v8::Boolean::New(Isolate::get(), input); break;

0 commit comments

Comments
 (0)