Bug 1027552 - Align values in BluetoothAttributeEvent.attrs with webidl, r=btian

This commit is contained in:
Jocelyn Liu 2014-06-23 10:32:58 +08:00
parent 92ea56e2a5
commit b9397c68ff
3 changed files with 20 additions and 3 deletions

View File

@ -699,7 +699,10 @@ BluetoothAdapter::EnableDisable(bool aEnable)
}
nsTArray<nsString> types;
types.AppendElement(NS_LITERAL_STRING("State"));
BT_APPEND_ENUM_STRING(types,
BluetoothAdapterAttribute,
BluetoothAdapterAttribute::State);
DispatchAttributeEvent(types);
nsRefPtr<BluetoothReplyRunnable> 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);
}
}

View File

@ -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 \

View File

@ -260,7 +260,9 @@ BluetoothManager::DispatchAttributeEvent()
JSAutoCompartment ac(cx, scope);
nsTArray<nsString> types;
types.AppendElement(NS_LITERAL_STRING("DefaultAdapter"));
BT_APPEND_ENUM_STRING(types,
BluetoothManagerAttribute,
BluetoothManagerAttribute::DefaultAdapter);
if (!ToJSValue(cx, types, &value)) {
JS_ClearPendingException(cx);