Bug 1178581 - Interning does not and should not imply infinite lifetime; r=sfink

This commit is contained in:
Terrence Cole
2015-06-30 07:58:31 -07:00
parent b865214844
commit 88f9bc5932
24 changed files with 115 additions and 122 deletions

View File

@@ -21,7 +21,7 @@ using namespace mozilla::plugins::parent;
/**
* NPIdentifiers in the chrome process are stored as jsids. The difficulty is in
* ensuring that string identifiers are rooted without interning them all. We
* ensuring that string identifiers are rooted without pinning them all. We
* assume that all NPIdentifiers passed into nsJSNPRuntime will not be used
* outside the scope of the NPAPI call (i.e., they won't be stored in the
* heap). Rooting is done using the StackIdentifier class, which roots the
@@ -31,7 +31,7 @@ using namespace mozilla::plugins::parent;
* generational or compacting GC. When Firefox implements a moving GC for
* strings, we will need to ensure that no movement happens while NPAPI code is
* on the stack: although StackIdentifier roots all identifiers used, the GC has
* no way to no that a jsid cast to an NPIdentifier needs to be fixed up if it
* no way to know that a jsid cast to an NPIdentifier needs to be fixed up if it
* is moved.
*/
@@ -39,7 +39,7 @@ class MOZ_STACK_CLASS StackIdentifier
{
public:
explicit StackIdentifier(const PluginIdentifier& aIdentifier,
bool aIntern = false);
bool aAtomizeAndPin = false);
bool Failed() const { return mFailed; }
NPIdentifier ToNPIdentifier() const { return mIdentifier; }
@@ -51,7 +51,7 @@ private:
JS::RootedId mId;
};
StackIdentifier::StackIdentifier(const PluginIdentifier& aIdentifier, bool aIntern)
StackIdentifier::StackIdentifier(const PluginIdentifier& aIdentifier, bool aAtomizeAndPin)
: mFailed(false),
mId(mCx)
{
@@ -64,8 +64,8 @@ StackIdentifier::StackIdentifier(const PluginIdentifier& aIdentifier, bool aInte
mFailed = true;
return;
}
if (aIntern) {
str = JS_InternJSString(mCx, str);
if (aAtomizeAndPin) {
str = JS_AtomizeAndPinJSString(mCx, str);
if (!str) {
NS_ERROR("Id can't be allocated");
mFailed = true;
@@ -509,9 +509,9 @@ PluginScriptableObjectParent::ScriptableEnumerate(NPObject* aObject,
}
for (uint32_t index = 0; index < *aCount; index++) {
// We intern the ID to avoid a GC hazard here. This could probably be fixed
// We pin the ID to avoid a GC hazard here. This could probably be fixed
// if the interface with nsJSNPRuntime were smarter.
StackIdentifier stackID(identifiers[index], true /* aIntern */);
StackIdentifier stackID(identifiers[index], true /* aAtomizeAndPin */);
if (stackID.Failed()) {
return false;
}