Bug 785057 - Return an error after js exceptions. r=bz

Return PL_DHASH_STOP if JS_SetProperty fails, and check
the return code of the enumerator to propagate the failure
back to javascript through the return value of mozGetMetadata.

In addition, use JS_DefineProperty in mozGetMetadata so
web content can't intercept and alter our creation calls.

JS_SetProperty() will define a new property if it doesn't
exist, but it will also call any existing setters, in
particular those on Object.prototype. This is confusing
for an object that created by a platform object method
from internal data.
This commit is contained in:
Ralph Giles 2012-09-14 16:04:46 -04:00
parent 490fadced3
commit 7bfebb737a

View File

@ -1445,8 +1445,10 @@ nsHTMLMediaElement::BuildObjectFromTags(nsCStringHashKey::KeyType aKey,
nsString wideValue = NS_ConvertUTF8toUTF16(aValue);
JSString* string = JS_NewUCStringCopyZ(args->cx, wideValue.Data());
JS::Value value = STRING_TO_JSVAL(string);
if (!JS_SetProperty(args->cx, args->tags, aKey.Data(), &value)) {
if (!JS_DefineProperty(args->cx, args->tags, aKey.Data(), value,
NULL, NULL, JSPROP_ENUMERATE)) {
NS_WARNING("Failed to set metadata property");
return PL_DHASH_STOP;
}
return PL_DHASH_NEXT;
@ -1465,7 +1467,13 @@ nsHTMLMediaElement::MozGetMetadata(JSContext* cx, JS::Value* aValue)
}
if (mTags) {
MetadataIterCx iter = {cx, tags};
mTags->EnumerateRead(BuildObjectFromTags, static_cast<void*>(&iter));
uint32_t ret = mTags->EnumerateRead(BuildObjectFromTags,
static_cast<void*>(&iter));
LOG(PR_LOG_DEBUG, ("tag enumerator returned %d", ret));
if (ret == PL_DHASH_STOP) {
NS_WARNING("couldn't create metadata object!");
return NS_ERROR_FAILURE;
}
}
*aValue = OBJECT_TO_JSVAL(tags);