From b9397c68fff197f5e088b74be8dee5ddda1b0c2c Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Mon, 23 Jun 2014 10:32:58 +0800 Subject: [PATCH] Bug 1027552 - Align values in BluetoothAttributeEvent.attrs with webidl, r=btian --- dom/bluetooth2/BluetoothAdapter.cpp | 7 +++++-- dom/bluetooth2/BluetoothCommon.h | 12 ++++++++++++ dom/bluetooth2/BluetoothManager.cpp | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/dom/bluetooth2/BluetoothAdapter.cpp b/dom/bluetooth2/BluetoothAdapter.cpp index 72517e5b4587..7248bafc093b 100644 --- a/dom/bluetooth2/BluetoothAdapter.cpp +++ b/dom/bluetooth2/BluetoothAdapter.cpp @@ -699,7 +699,10 @@ BluetoothAdapter::EnableDisable(bool aEnable) } nsTArray types; - types.AppendElement(NS_LITERAL_STRING("State")); + BT_APPEND_ENUM_STRING(types, + BluetoothAdapterAttribute, + BluetoothAdapterAttribute::State); + DispatchAttributeEvent(types); nsRefPtr result = @@ -792,7 +795,7 @@ BluetoothAdapter::HandlePropertyChanged(const BluetoothValue& aValue) // BluetoothAdapterAttribute properties if (IsAdapterAttributeChanged(type, arr[i].value())) { SetPropertyByValue(arr[i]); - types.AppendElement(arr[i].name()); + BT_APPEND_ENUM_STRING(types, BluetoothAdapterAttribute, type); } } diff --git a/dom/bluetooth2/BluetoothCommon.h b/dom/bluetooth2/BluetoothCommon.h index 44d3c8192132..eca1973a19a2 100644 --- a/dom/bluetooth2/BluetoothCommon.h +++ b/dom/bluetooth2/BluetoothCommon.h @@ -83,6 +83,18 @@ extern bool gBluetoothDebugFlag; } \ } while(0) +/** + * Convert an enum value to string then append it to an array. + */ +#define BT_APPEND_ENUM_STRING(array, enumType, enumValue) \ + do { \ + uint32_t index = uint32_t(enumValue); \ + nsAutoString name; \ + name.AssignASCII(enumType##Values::strings[index].value, \ + enumType##Values::strings[index].length); \ + array.AppendElement(name); \ + } while(0) \ + #define BEGIN_BLUETOOTH_NAMESPACE \ namespace mozilla { namespace dom { namespace bluetooth { #define END_BLUETOOTH_NAMESPACE \ diff --git a/dom/bluetooth2/BluetoothManager.cpp b/dom/bluetooth2/BluetoothManager.cpp index 6bf0c514ae83..2fc68b2cb938 100644 --- a/dom/bluetooth2/BluetoothManager.cpp +++ b/dom/bluetooth2/BluetoothManager.cpp @@ -260,7 +260,9 @@ BluetoothManager::DispatchAttributeEvent() JSAutoCompartment ac(cx, scope); nsTArray types; - types.AppendElement(NS_LITERAL_STRING("DefaultAdapter")); + BT_APPEND_ENUM_STRING(types, + BluetoothManagerAttribute, + BluetoothManagerAttribute::DefaultAdapter); if (!ToJSValue(cx, types, &value)) { JS_ClearPendingException(cx);