Bug 987112. Remove the redundant and somewhat annoying parentObject argument to dictionary ToObject() methods. r=bholley

This commit is contained in:
Boris Zbarsky 2014-03-29 01:45:10 -04:00
parent 192bc01f54
commit d4a40b2bea
12 changed files with 28 additions and 29 deletions

View File

@ -67,7 +67,7 @@ Activity::Initialize(nsPIDOMWindow* aWindow,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JS::Value> optionsValue(aCx); JS::Rooted<JS::Value> optionsValue(aCx);
if (!aOptions.ToObject(aCx, JS::NullPtr(), &optionsValue)) { if (!aOptions.ToObject(aCx, &optionsValue)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

View File

@ -689,7 +689,7 @@ Console::ProfileMethod(JSContext* aCx, const nsAString& aAction,
} }
JS::Rooted<JS::Value> eventValue(aCx); JS::Rooted<JS::Value> eventValue(aCx);
if (!event.ToObject(aCx, JS::NullPtr(), &eventValue)) { if (!event.ToObject(aCx, &eventValue)) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return; return;
} }
@ -1001,7 +1001,7 @@ Console::ProcessCallData(ConsoleCallData* aData)
} }
JS::Rooted<JS::Value> eventValue(cx); JS::Rooted<JS::Value> eventValue(cx);
if (!event.ToObject(cx, JS::NullPtr(), &eventValue)) { if (!event.ToObject(cx, &eventValue)) {
Throw(cx, NS_ERROR_FAILURE); Throw(cx, NS_ERROR_FAILURE);
return; return;
} }
@ -1300,7 +1300,7 @@ Console::StartTimer(JSContext* aCx, const JS::Value& aName,
RootedDictionary<ConsoleTimerError> error(aCx); RootedDictionary<ConsoleTimerError> error(aCx);
JS::Rooted<JS::Value> value(aCx); JS::Rooted<JS::Value> value(aCx);
if (!error.ToObject(aCx, JS::NullPtr(), &value)) { if (!error.ToObject(aCx, &value)) {
return JS::UndefinedValue(); return JS::UndefinedValue();
} }
@ -1332,7 +1332,7 @@ Console::StartTimer(JSContext* aCx, const JS::Value& aName,
timer.mStarted = aTimestamp; timer.mStarted = aTimestamp;
JS::Rooted<JS::Value> value(aCx); JS::Rooted<JS::Value> value(aCx);
if (!timer.ToObject(aCx, JS::NullPtr(), &value)) { if (!timer.ToObject(aCx, &value)) {
return JS::UndefinedValue(); return JS::UndefinedValue();
} }
@ -1366,7 +1366,7 @@ Console::StopTimer(JSContext* aCx, const JS::Value& aName,
timer.mDuration = aTimestamp - entry; timer.mDuration = aTimestamp - entry;
JS::Rooted<JS::Value> value(aCx); JS::Rooted<JS::Value> value(aCx);
if (!timer.ToObject(aCx, JS::NullPtr(), &value)) { if (!timer.ToObject(aCx, &value)) {
return JS::UndefinedValue(); return JS::UndefinedValue();
} }
@ -1414,7 +1414,7 @@ Console::IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
RootedDictionary<ConsoleCounterError> error(aCx); RootedDictionary<ConsoleCounterError> error(aCx);
JS::Rooted<JS::Value> value(aCx); JS::Rooted<JS::Value> value(aCx);
if (!error.ToObject(aCx, JS::NullPtr(), &value)) { if (!error.ToObject(aCx, &value)) {
return JS::UndefinedValue(); return JS::UndefinedValue();
} }
@ -1430,7 +1430,7 @@ Console::IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
data.mCount = count; data.mCount = count;
JS::Rooted<JS::Value> value(aCx); JS::Rooted<JS::Value> value(aCx);
if (!data.ToObject(aCx, JS::NullPtr(), &value)) { if (!data.ToObject(aCx, &value)) {
return JS::UndefinedValue(); return JS::UndefinedValue();
} }

View File

@ -5678,7 +5678,7 @@ nsGlobalWindow::DispatchResizeEvent(const nsIntSize& aSize)
detail.mWidth = aSize.width; detail.mWidth = aSize.width;
detail.mHeight = aSize.height; detail.mHeight = aSize.height;
JS::Rooted<JS::Value> detailValue(cx); JS::Rooted<JS::Value> detailValue(cx);
if (!detail.ToObject(cx, JS::NullPtr(), &detailValue)) { if (!detail.ToObject(cx, &detailValue)) {
return false; return false;
} }

View File

@ -4672,7 +4672,7 @@ if (!returnArray) {
False) False)
if type.isDictionary(): if type.isDictionary():
return (wrapAndSetPtr("%s.ToObject(cx, ${obj}, ${jsvalHandle})" % result), return (wrapAndSetPtr("%s.ToObject(cx, ${jsvalHandle})" % result),
False) False)
if type.isDate(): if type.isDate():
@ -9319,7 +9319,7 @@ if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
if self.dictionary.parent: if self.dictionary.parent:
body += ( body += (
"// Per spec, we define the parent's members first\n" "// Per spec, we define the parent's members first\n"
"if (!%s::ToObject(cx, parentObject, rval)) {\n" "if (!%s::ToObject(cx, rval)) {\n"
" return false;\n" " return false;\n"
"}\n" "}\n"
"JS::Rooted<JSObject*> obj(cx, &rval.toObject());\n" "JS::Rooted<JSObject*> obj(cx, &rval.toObject());\n"
@ -9339,7 +9339,6 @@ if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
return ClassMethod("ToObject", "bool", [ return ClassMethod("ToObject", "bool", [
Argument('JSContext*', 'cx'), Argument('JSContext*', 'cx'),
Argument('JS::Handle<JSObject*>', 'parentObject'),
Argument('JS::MutableHandle<JS::Value>', 'rval'), Argument('JS::MutableHandle<JS::Value>', 'rval'),
], const=True, body=body) ], const=True, body=body)
@ -9598,7 +9597,9 @@ if (""",
'jsvalRef': "temp", 'jsvalRef': "temp",
'jsvalHandle': "&temp", 'jsvalHandle': "&temp",
'returnsNewObject': False, 'returnsNewObject': False,
'obj': "parentObject", # 'obj' can just be allowed to be the string "obj", since that
# will be our dictionary object, which is presumably itself in
# the right scope.
'typedArraysAreStructs': True 'typedArraysAreStructs': True
}) })
conversion = CGGeneric(innerTemplate) conversion = CGGeneric(innerTemplate)

View File

@ -160,7 +160,7 @@ BrowserElementParent::DispatchOpenWindowEvent(Element* aOpenerFrameElement,
JS::Rooted<JSObject*> global(cx, sgo->GetGlobalJSObject()); JS::Rooted<JSObject*> global(cx, sgo->GetGlobalJSObject());
JSAutoCompartment ac(cx, global); JSAutoCompartment ac(cx, global);
if (!detail.ToObject(cx, global, &val)) { if (!detail.ToObject(cx, &val)) {
MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM."); MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM.");
return BrowserElementParent::OPEN_WINDOW_IGNORED; return BrowserElementParent::OPEN_WINDOW_IGNORED;
} }
@ -332,9 +332,7 @@ NS_IMETHODIMP DispatchAsyncScrollEventRunnable::Run()
JSAutoCompartment ac(cx, globalJSObject); JSAutoCompartment ac(cx, globalJSObject);
JS::Rooted<JS::Value> val(cx); JS::Rooted<JS::Value> val(cx);
// We can get away with a null global here because if (!detail.ToObject(cx, &val)) {
// AsyncScrollEventDetail only contains numeric values.
if (!detail.ToObject(cx, JS::NullPtr(), &val)) {
MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM."); MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM.");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

View File

@ -90,7 +90,7 @@ static nsresult CompareDictionaries(JSContext* aCx, JSObject *aA,
JS::Rooted<JSObject*> a(aCx, aA); JS::Rooted<JSObject*> a(aCx, aA);
JSAutoCompartment ac(aCx, aA); JSAutoCompartment ac(aCx, aA);
JS::Rooted<JS::Value> bval(aCx); JS::Rooted<JS::Value> bval(aCx);
aB.ToObject(aCx, JS::NullPtr(), &bval); aB.ToObject(aCx, &bval);
JS::Rooted<JSObject*> b(aCx, &bval.toObject()); JS::Rooted<JSObject*> b(aCx, &bval.toObject());
// Iterate over each property in A, and check if it is in B // Iterate over each property in A, and check if it is in B

View File

@ -101,7 +101,7 @@ DesktopNotification::PostDesktopNotification()
ops.mTextClickable = true; ops.mTextClickable = true;
ops.mManifestURL = manifestUrl; ops.mManifestURL = manifestUrl;
if (!ops.ToObject(cx, JS::NullPtr(), &val)) { if (!ops.ToObject(cx, &val)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

View File

@ -583,7 +583,7 @@ Notification::ShowInternal()
ops.mLang = mLang; ops.mLang = mLang;
ops.mTag = mTag; ops.mTag = mTag;
if (!ops.ToObject(cx, JS::NullPtr(), &val)) { if (!ops.ToObject(cx, &val)) {
NS_WARNING("Converting dict to object failed!"); NS_WARNING("Converting dict to object failed!");
return; return;
} }

View File

@ -208,7 +208,7 @@ NetworkWorker::DispatchNetworkResult(const NetworkResultOptions& aOptions)
mozilla::AutoSafeJSContext cx; mozilla::AutoSafeJSContext cx;
JS::RootedValue val(cx); JS::RootedValue val(cx);
if (!aOptions.ToObject(cx, JS::NullPtr(), &val)) { if (!aOptions.ToObject(cx, &val)) {
return; return;
} }

View File

@ -281,7 +281,7 @@ WifiProxyService::DispatchWifiResult(const WifiResultOptions& aOptions, const ns
mozilla::AutoSafeJSContext cx; mozilla::AutoSafeJSContext cx;
JS::Rooted<JS::Value> val(cx); JS::Rooted<JS::Value> val(cx);
if (!aOptions.ToObject(cx, JS::NullPtr(), &val)) { if (!aOptions.ToObject(cx, &val)) {
return; return;
} }

View File

@ -641,7 +641,7 @@ inDOMUtils::ColorNameToRGB(const nsAString& aColorName, JSContext* aCx,
triple.mG = NS_GET_G(color); triple.mG = NS_GET_G(color);
triple.mB = NS_GET_B(color); triple.mB = NS_GET_B(color);
if (!triple.ToObject(aCx, JS::NullPtr(), aValue)) { if (!triple.ToObject(aCx, aValue)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

View File

@ -317,7 +317,7 @@ LookupHelper::ConstructAnswer(LookupArgument *aArgument)
} }
JS::RootedValue val(cx); JS::RootedValue val(cx);
if (!dict.ToObject(cx, JS::NullPtr(), &val)) { if (!dict.ToObject(cx, &val)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -400,7 +400,7 @@ Dashboard::GetSockets(SocketData *aSocketData)
dict.mSent += socketData->mTotalSent; dict.mSent += socketData->mTotalSent;
dict.mReceived += socketData->mTotalRecv; dict.mReceived += socketData->mTotalRecv;
JS::RootedValue val(cx); JS::RootedValue val(cx);
if (!dict.ToObject(cx, JS::NullPtr(), &val)) if (!dict.ToObject(cx, &val))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
socketData->mCallback->OnDashboardDataAvailable(val); socketData->mCallback->OnDashboardDataAvailable(val);
@ -503,7 +503,7 @@ Dashboard::GetHttpConnections(HttpData *aHttpData)
} }
JS::RootedValue val(cx); JS::RootedValue val(cx);
if (!dict.ToObject(cx, JS::NullPtr(), &val)) { if (!dict.ToObject(cx, &val)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -630,7 +630,7 @@ Dashboard::GetWebSocketConnections(WebSocketRequest *aWsRequest)
} }
JS::RootedValue val(cx); JS::RootedValue val(cx);
if (!dict.ToObject(cx, JS::NullPtr(), &val)) { if (!dict.ToObject(cx, &val)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
wsRequest->mCallback->OnDashboardDataAvailable(val); wsRequest->mCallback->OnDashboardDataAvailable(val);
@ -717,7 +717,7 @@ Dashboard::GetDNSCacheEntries(DnsData *dnsData)
} }
JS::RootedValue val(cx); JS::RootedValue val(cx);
if (!dict.ToObject(cx, JS::NullPtr(), &val)) { if (!dict.ToObject(cx, &val)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
dnsData->mCallback->OnDashboardDataAvailable(val); dnsData->mCallback->OnDashboardDataAvailable(val);
@ -819,7 +819,7 @@ Dashboard::GetConnectionStatus(ConnectionData *aConnectionData)
dict.mStatus = connectionData->mStatus; dict.mStatus = connectionData->mStatus;
JS::RootedValue val(cx); JS::RootedValue val(cx);
if (!dict.ToObject(cx, JS::NullPtr(), &val)) if (!dict.ToObject(cx, &val))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
connectionData->mCallback->OnDashboardDataAvailable(val); connectionData->mCallback->OnDashboardDataAvailable(val);