mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 20:25:44 +00:00
Bug 826807: Clean up JSAPI error handling in PeerConnection constraints r=bz
This commit is contained in:
parent
b6e5f7f663
commit
51ac10a00c
@ -593,53 +593,64 @@ nsresult
|
||||
PeerConnectionImpl::ConvertConstraints(
|
||||
const JS::Value& aConstraints, MediaConstraints* aObj, JSContext* aCx)
|
||||
{
|
||||
size_t i;
|
||||
jsval mandatory, optional;
|
||||
JSObject& constraints = aConstraints.toObject();
|
||||
|
||||
// Mandatory constraints.
|
||||
if (JS_GetProperty(aCx, &constraints, "mandatory", &mandatory)) {
|
||||
if (mandatory.isObject()) {
|
||||
// Mandatory constraints. Note that we only care if the constraint array exists
|
||||
if (!JS_GetProperty(aCx, &constraints, "mandatory", &mandatory)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!mandatory.isNullOrUndefined()) {
|
||||
if (!mandatory.isObject()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSObject* opts = JSVAL_TO_OBJECT(mandatory);
|
||||
JS::AutoIdArray mandatoryOpts(aCx, JS_Enumerate(aCx, opts));
|
||||
|
||||
// Iterate over each property.
|
||||
for (i = 0; i < mandatoryOpts.length(); i++) {
|
||||
for (size_t i = 0; i < mandatoryOpts.length(); i++) {
|
||||
jsval option, optionName;
|
||||
if (JS_GetPropertyById(aCx, opts, mandatoryOpts[i], &option)) {
|
||||
if (JS_IdToValue(aCx, mandatoryOpts[i], &optionName)) {
|
||||
if (!JS_GetPropertyById(aCx, opts, mandatoryOpts[i], &option) ||
|
||||
!JS_IdToValue(aCx, mandatoryOpts[i], &optionName) ||
|
||||
// We only support boolean constraints for now.
|
||||
if (JSVAL_IS_BOOLEAN(option)) {
|
||||
!JSVAL_IS_BOOLEAN(option)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSString* optionNameString = JS_ValueToString(aCx, optionName);
|
||||
if (!optionNameString) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ConvertUTF16toUTF8 stringVal(JS_GetStringCharsZ(aCx, optionNameString));
|
||||
aObj->setBooleanConstraint(stringVal.get(), JSVAL_TO_BOOLEAN(option), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Optional constraints.
|
||||
if (JS_GetProperty(aCx, &constraints, "optional", &optional)) {
|
||||
if (optional.isObject()) {
|
||||
JSObject* opts = JSVAL_TO_OBJECT(optional);
|
||||
if (JS_IsArrayObject(aCx, opts)) {
|
||||
uint32_t length;
|
||||
if (!JS_GetArrayLength(aCx, opts, &length)) {
|
||||
if (!JS_GetProperty(aCx, &constraints, "optional", &optional)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
if (!optional.isNullOrUndefined()) {
|
||||
if (!optional.isObject()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSObject* opts = JSVAL_TO_OBJECT(optional);
|
||||
uint32_t length;
|
||||
if (!JS_IsArrayObject(aCx, opts) ||
|
||||
!JS_GetArrayLength(aCx, opts, &length)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
jsval val;
|
||||
JS_GetElement(aCx, opts, i, &val);
|
||||
if (val.isObject()) {
|
||||
if (!JS_GetElement(aCx, opts, i, &val) ||
|
||||
!val.isObject()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// Extract name & value and store.
|
||||
// FIXME: MediaConstraints does not support optional constraints?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user