Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

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: #97

PR-URL: #374
Reviewed-By: Kyle Farnung <[email protected]>
Reviewed-By: Hitesh Kanwathirtha <[email protected]>
Reviewed-By: Kunal Pathak <[email protected]>
Reviewed-By: Jimmy Thomson <[email protected]>
  • Loading branch information
Mike Kaufman committed Aug 21, 2017
1 parent fd0d4a3 commit 5e01643
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 @@ -471,6 +471,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 5e01643

Please sign in to comment.