mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 18:08:58 +00:00
Bug 1400081 - Don't use -1 to represent an unset JSGCParamKey. r=sfink.
Because UBSan complains about casting -1: > runtime error: load of value 4294967295, which is not a valid value for type 'JSGCParamKey' --HG-- extra : rebase_source : ff972b29f9a89fcbe50d9f105196bcd8f06486bd
This commit is contained in:
parent
af3b468649
commit
5f1dacafee
@ -885,9 +885,9 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSContext* aWorkerCx)
|
||||
// This is the real place where we set the max memory for the runtime.
|
||||
for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
|
||||
const JSSettings::JSGCSetting& setting = gcSettings[index];
|
||||
if (setting.IsSet()) {
|
||||
if (setting.key.isSome()) {
|
||||
NS_ASSERTION(setting.value, "Can't handle 0 values!");
|
||||
JS_SetGCParameter(aWorkerCx, setting.key, setting.value);
|
||||
JS_SetGCParameter(aWorkerCx, *setting.key, setting.value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1935,7 +1935,7 @@ RuntimeService::Init()
|
||||
}
|
||||
|
||||
// Initialize JSSettings.
|
||||
if (!sDefaultJSSettings.gcSettings[0].IsSet()) {
|
||||
if (sDefaultJSSettings.gcSettings[0].key.isNothing()) {
|
||||
sDefaultJSSettings.contextOptions = JS::ContextOptions();
|
||||
sDefaultJSSettings.chrome.maxScriptRuntime = -1;
|
||||
sDefaultJSSettings.chrome.compartmentOptions.behaviors().setVersion(JSVERSION_DEFAULT);
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include <stdint.h>
|
||||
#include "nsAutoPtr.h"
|
||||
@ -102,25 +103,12 @@ struct JSSettings
|
||||
|
||||
struct JSGCSetting
|
||||
{
|
||||
JSGCParamKey key;
|
||||
mozilla::Maybe<JSGCParamKey> key;
|
||||
uint32_t value;
|
||||
|
||||
JSGCSetting()
|
||||
: key(static_cast<JSGCParamKey>(-1)), value(0)
|
||||
: key(), value(0)
|
||||
{ }
|
||||
|
||||
bool
|
||||
IsSet() const
|
||||
{
|
||||
return key != static_cast<JSGCParamKey>(-1);
|
||||
}
|
||||
|
||||
void
|
||||
Unset()
|
||||
{
|
||||
key = static_cast<JSGCParamKey>(-1);
|
||||
value = 0;
|
||||
}
|
||||
};
|
||||
|
||||
// There are several settings that we know we need so it makes sense to
|
||||
@ -166,11 +154,11 @@ struct JSSettings
|
||||
|
||||
for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
|
||||
JSSettings::JSGCSetting& setting = gcSettings[index];
|
||||
if (setting.key == aKey) {
|
||||
if (setting.key.isSome() && *setting.key == aKey) {
|
||||
foundSetting = &setting;
|
||||
break;
|
||||
}
|
||||
if (!firstEmptySetting && !setting.IsSet()) {
|
||||
if (!firstEmptySetting && setting.key.isNothing()) {
|
||||
firstEmptySetting = &setting;
|
||||
}
|
||||
}
|
||||
@ -183,13 +171,13 @@ struct JSSettings
|
||||
return false;
|
||||
}
|
||||
}
|
||||
foundSetting->key = aKey;
|
||||
foundSetting->key = mozilla::Some(aKey);
|
||||
foundSetting->value = aValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (foundSetting) {
|
||||
foundSetting->Unset();
|
||||
foundSetting->key.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user