Skip to content

Commit

Permalink
chakrashim: ref count data sent to SetEmbedderData
Browse files Browse the repository at this point in the history
JS Objects passed to SetEmbedderData need to have JsAddRef/JsRelease
called, otherwise they could be GC'd prematurely.

Fixes: nodejs#97
  • Loading branch information
Mike Kaufman committed Aug 18, 2017
1 parent 5aa5042 commit 4d04cbb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions deps/chakrashim/src/jsrtcontextshim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,15 @@ void ContextShim::SetAlignedPointerInEmbedderData(int index, void * value) {
if (embedderData.size() < minSize) {
embedderData.resize(minSize);
}

// ensure reference counting, otherwise objects can be GC'd. JsAddRef/
// JsRelease will handle cases if the pointer is not valid for ref counts.
void * oldValue = embedderData[index];
if (oldValue != nullptr) {
JsRelease(oldValue, nullptr);
}
JsAddRef(value, nullptr);

embedderData[index] = value;
} catch(const std::exception&) {
}
Expand Down

0 comments on commit 4d04cbb

Please sign in to comment.