mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 866432 - Replace AutoValueRooter with JS::Rooted<JS::Value> in gecko. r=smaug
--HG-- extra : rebase_source : 0897fc8f3968619185b754e13ca6119cb1c0f46d
This commit is contained in:
parent
0bc736c249
commit
2d851ac486
@ -675,9 +675,8 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
||||
}
|
||||
}
|
||||
|
||||
JS::AutoValueRooter objectsv(ctx);
|
||||
objectsv.set(OBJECT_TO_JSVAL(aObjectsArray));
|
||||
if (!JS_WrapValue(ctx, objectsv.jsval_addr()))
|
||||
JS::Rooted<JS::Value> objectsv(ctx, JS::ObjectValue(*aObjectsArray));
|
||||
if (!JS_WrapValue(ctx, objectsv.address()))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
JS::Value json = JSVAL_NULL;
|
||||
@ -698,7 +697,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
||||
BOOLEAN_TO_JSVAL(aSync), nullptr, nullptr, JSPROP_ENUMERATE);
|
||||
JS_DefineProperty(ctx, param, "json", json, nullptr, nullptr, JSPROP_ENUMERATE); // deprecated
|
||||
JS_DefineProperty(ctx, param, "data", json, nullptr, nullptr, JSPROP_ENUMERATE);
|
||||
JS_DefineProperty(ctx, param, "objects", objectsv.jsval_value(), nullptr, nullptr, JSPROP_ENUMERATE);
|
||||
JS_DefineProperty(ctx, param, "objects", objectsv, nullptr, nullptr, JSPROP_ENUMERATE);
|
||||
|
||||
JS::Value thisValue = JSVAL_VOID;
|
||||
|
||||
@ -729,23 +728,21 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
||||
thisValue.setObject(*object);
|
||||
}
|
||||
|
||||
JS::Value rval = JSVAL_VOID;
|
||||
|
||||
JS::AutoValueRooter argv(ctx);
|
||||
argv.set(OBJECT_TO_JSVAL(param));
|
||||
JS::Rooted<JS::Value> rval(ctx, JSVAL_VOID);
|
||||
JS::Rooted<JS::Value> argv(ctx, JS::ObjectValue(*param));
|
||||
|
||||
{
|
||||
JSObject* thisObject = JSVAL_TO_OBJECT(thisValue);
|
||||
|
||||
JSAutoCompartment tac(ctx, thisObject);
|
||||
if (!JS_WrapValue(ctx, argv.jsval_addr()))
|
||||
if (!JS_WrapValue(ctx, argv.address()))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
JS_CallFunctionValue(ctx, thisObject,
|
||||
funval, 1, argv.jsval_addr(), &rval);
|
||||
funval, 1, argv.address(), rval.address());
|
||||
if (aJSONRetVal) {
|
||||
nsString json;
|
||||
if (JS_Stringify(ctx, &rval, nullptr, JSVAL_NULL,
|
||||
if (JS_Stringify(ctx, rval.address(), nullptr, JSVAL_NULL,
|
||||
JSONCreator, &json)) {
|
||||
aJSONRetVal->AppendElement(json);
|
||||
}
|
||||
|
@ -787,12 +787,12 @@ nsJSObjWrapper::NP_SetProperty(NPObject *npobj, NPIdentifier id,
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
JS::Value v = NPVariantToJSVal(npp, cx, value);
|
||||
JS::AutoValueRooter tvr(cx, v);
|
||||
JS::Rooted<JS::Value> v(cx, NPVariantToJSVal(npp, cx, value));
|
||||
|
||||
NS_ASSERTION(NPIdentifierIsInt(id) || NPIdentifierIsString(id),
|
||||
"id must be either string or int!\n");
|
||||
ok = ::JS_SetPropertyById(cx, npjsobj->mJSObj, NPIdentifierToJSId(id), &v);
|
||||
ok = ::JS_SetPropertyById(cx, npjsobj->mJSObj, NPIdentifierToJSId(id),
|
||||
v.address());
|
||||
|
||||
// return ok == JS_TRUE to quiet down compiler warning, even if
|
||||
// return ok is what we really want.
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "jsapi.h"
|
||||
#include "prio.h"
|
||||
|
||||
using namespace JS;
|
||||
|
||||
namespace mozilla {
|
||||
namespace scache {
|
||||
|
||||
@ -397,29 +399,28 @@ TestEarlyShutdown() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
static bool
|
||||
GetHistogramCounts(const char *testmsg, const nsACString &histogram_id,
|
||||
JSContext *cx, JS::Value *counts)
|
||||
JSContext *cx, MutableHandle<Value> counts)
|
||||
{
|
||||
nsCOMPtr<nsITelemetry> telemetry = do_GetService("@mozilla.org/base/telemetry;1");
|
||||
JS::AutoValueRooter h(cx);
|
||||
nsresult trv = telemetry->GetHistogramById(histogram_id, cx, h.addr());
|
||||
Rooted<Value> h(cx);
|
||||
nsresult trv = telemetry->GetHistogramById(histogram_id, cx, h.address());
|
||||
if (NS_FAILED(trv)) {
|
||||
fail("%s: couldn't get histogram %s", testmsg, ToNewCString(histogram_id));
|
||||
return false;
|
||||
}
|
||||
passed(testmsg);
|
||||
|
||||
JS::AutoValueRooter snapshot_val(cx);
|
||||
Rooted<Value> snapshot_val(cx);
|
||||
JSFunction *snapshot_fn = NULL;
|
||||
JS::AutoValueRooter ss(cx);
|
||||
return (JS_GetProperty(cx, JSVAL_TO_OBJECT(h.value()), "snapshot",
|
||||
snapshot_val.addr())
|
||||
&& (snapshot_fn = JS_ValueToFunction(cx, snapshot_val.value()))
|
||||
&& JS::Call(cx, JSVAL_TO_OBJECT(h.value()),
|
||||
snapshot_fn, 0, NULL, ss.addr())
|
||||
&& JS_GetProperty(cx, JSVAL_TO_OBJECT(ss.value()),
|
||||
"counts", counts));
|
||||
Rooted<Value> ss(cx);
|
||||
return (JS_GetProperty(cx, JSVAL_TO_OBJECT(h), "snapshot",
|
||||
snapshot_val.address())
|
||||
&& (snapshot_fn = JS_ValueToFunction(cx, snapshot_val))
|
||||
&& JS::Call(cx, JSVAL_TO_OBJECT(h),
|
||||
snapshot_fn, 0, NULL, ss.address())
|
||||
&& JS_GetProperty(cx, JSVAL_TO_OBJECT(ss), "counts", counts.address()));
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -436,7 +437,7 @@ CompareCountArrays(JSContext *cx, JSObject *before, JSObject *after)
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < before_size; ++i) {
|
||||
JS::Value before_num, after_num;
|
||||
Value before_num, after_num;
|
||||
|
||||
if (!(JS_GetElement(cx, before, i, &before_num)
|
||||
&& JS_GetElement(cx, after, i, &after_num))) {
|
||||
@ -532,14 +533,16 @@ int main(int argc, char** argv)
|
||||
NS_NAMED_LITERAL_CSTRING(age_histogram_id, "STARTUP_CACHE_AGE_HOURS");
|
||||
NS_NAMED_LITERAL_CSTRING(invalid_histogram_id, "STARTUP_CACHE_INVALID");
|
||||
|
||||
JS::AutoValueRooter age_before_counts(cx);
|
||||
if (use_js && !GetHistogramCounts("STARTUP_CACHE_AGE_HOURS histogram before test",
|
||||
age_histogram_id, cx, age_before_counts.addr()))
|
||||
Rooted<Value> age_before_counts(cx);
|
||||
if (use_js &&
|
||||
!GetHistogramCounts("STARTUP_CACHE_AGE_HOURS histogram before test",
|
||||
age_histogram_id, cx, &age_before_counts))
|
||||
use_js = false;
|
||||
|
||||
JS::AutoValueRooter invalid_before_counts(cx);
|
||||
if (use_js && !GetHistogramCounts("STARTUP_CACHE_INVALID histogram before test",
|
||||
invalid_histogram_id, cx, invalid_before_counts.addr()))
|
||||
Rooted<Value> invalid_before_counts(cx);
|
||||
if (use_js &&
|
||||
!GetHistogramCounts("STARTUP_CACHE_INVALID histogram before test",
|
||||
invalid_histogram_id, cx, &invalid_before_counts))
|
||||
use_js = false;
|
||||
|
||||
nsresult scrv;
|
||||
@ -561,25 +564,27 @@ int main(int argc, char** argv)
|
||||
if (NS_FAILED(TestEarlyShutdown()))
|
||||
rv = 1;
|
||||
|
||||
JS::AutoValueRooter age_after_counts(cx);
|
||||
if (use_js && !GetHistogramCounts("STARTUP_CACHE_AGE_HOURS histogram after test",
|
||||
age_histogram_id, cx, age_after_counts.addr()))
|
||||
Rooted<Value> age_after_counts(cx);
|
||||
if (use_js &&
|
||||
!GetHistogramCounts("STARTUP_CACHE_AGE_HOURS histogram after test",
|
||||
age_histogram_id, cx, &age_after_counts))
|
||||
use_js = false;
|
||||
|
||||
if (NS_FAILED(TestHistogramValues("age samples", use_js, cx,
|
||||
JSVAL_TO_OBJECT(age_before_counts.value()),
|
||||
JSVAL_TO_OBJECT(age_after_counts.value()))))
|
||||
age_before_counts.toObjectOrNull(),
|
||||
age_after_counts.toObjectOrNull())))
|
||||
rv = 1;
|
||||
|
||||
JS::AutoValueRooter invalid_after_counts(cx);
|
||||
if (use_js && !GetHistogramCounts("STARTUP_CACHE_INVALID histogram after test",
|
||||
invalid_histogram_id, cx, invalid_after_counts.addr()))
|
||||
Rooted<Value> invalid_after_counts(cx);
|
||||
if (use_js &&
|
||||
!GetHistogramCounts("STARTUP_CACHE_INVALID histogram after test",
|
||||
invalid_histogram_id, cx, &invalid_after_counts))
|
||||
use_js = false;
|
||||
|
||||
// STARTUP_CACHE_INVALID should have been triggered by TestIgnoreDiskCache()
|
||||
if (NS_FAILED(TestHistogramValues("invalid disk cache", use_js, cx,
|
||||
JSVAL_TO_OBJECT(invalid_before_counts.value()),
|
||||
JSVAL_TO_OBJECT(invalid_after_counts.value()))))
|
||||
invalid_before_counts.toObjectOrNull(),
|
||||
invalid_after_counts.toObjectOrNull())))
|
||||
rv = 1;
|
||||
|
||||
return rv;
|
||||
|
Loading…
Reference in New Issue
Block a user