Bug 1134955. Be more careful with how we stringify property ids for error message reporting. r=jorendorff

This commit is contained in:
Boris Zbarsky 2015-02-20 14:16:26 -05:00
parent 2d938ea149
commit 6c042f3a3c
7 changed files with 39 additions and 6 deletions

View File

@ -58,3 +58,4 @@ skip-if = debug == false
[test_promise_rejections_from_jsimplemented.html]
skip-if = debug == false
[test_worker_UnwrapArg.html]
[test_crossOriginWindowSymbolAccess.html]

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test for accessing symbols on a cross-origin window</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<iframe src="http://www1.w3c-test.org/common/blank.html"></iframe>
<script>
async_test(function (t) {
window.addEventListener("load", t.step_func(
function() {
assert_equals(document.querySelector("iframe").contentDocument, null, "Should have a crossorigin frame");
assert_throws(new Error(), function() {
frames[0][Symbol.iterator];
}, "Should throw exception on cross-origin Window symbol-named get");
assert_throws(new Error(), function() {
frames[0].location[Symbol.iterator];
}, "Should throw exception on cross-origin Location symbol-named get");
t.done();
}
));
}, "Check Symbol access on load");
</script>

View File

@ -1749,7 +1749,8 @@ ReportPropertyError(JSContext *cx,
const unsigned errorNumber,
HandleId id)
{
RootedString str(cx, IdToString(cx, id));
RootedValue idVal(cx, IdToValue(id));
RootedString str(cx, ValueToSource(cx, idVal));
if (!str)
return false;

View File

@ -142,7 +142,7 @@ MSG_DEF(JSMSG_CSP_BLOCKED_EVAL, 0, JSEXN_ERR, "call to eval() blocked by
MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 0, JSEXN_ERR, "call to Function() blocked by CSP")
// Wrappers
MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 1, JSEXN_ERR, "Permission denied to define accessor property '{0}'")
MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 1, JSEXN_ERR, "Permission denied to define accessor property {0}")
MSG_DEF(JSMSG_DEAD_OBJECT, 0, JSEXN_TYPEERR, "can't access dead object")
MSG_DEF(JSMSG_UNWRAP_DENIED, 0, JSEXN_ERR, "permission denied to unwrap object")
@ -346,7 +346,7 @@ MSG_DEF(JSMSG_INVALID_TRAP_RESULT, 2, JSEXN_TYPEERR, "trap {1} for {0} retur
MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property")
MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter")
MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 0, JSEXN_ERR, "Permission denied to access object")
MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 1, JSEXN_ERR, "Permission denied to access property '{0}'")
MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 1, JSEXN_ERR, "Permission denied to access property {0}")
MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object")
MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target")
MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined")

View File

@ -411,7 +411,8 @@ js::Throw(JSContext *cx, jsid id, unsigned errorNumber)
{
MOZ_ASSERT(js_ErrorFormatString[errorNumber].argCount == 1);
JSString *idstr = IdToString(cx, id);
RootedValue idVal(cx, IdToValue(id));
JSString *idstr = ValueToSource(cx, idVal);
if (!idstr)
return false;
JSAutoByteString bytes(cx, idstr);

View File

@ -38,7 +38,11 @@ js::AutoEnterPolicy::reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id)
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr,
JSMSG_OBJECT_ACCESS_DENIED);
} else {
JSString *str = IdToString(cx, id);
RootedValue idVal(cx, IdToValue(id));
JSString *str = ValueToSource(cx, idVal);
if (!str) {
return;
}
AutoStableStringChars chars(cx);
const char16_t *prop = nullptr;
if (str->ensureFlat(cx) && chars.initTwoByte(cx, str))

View File

@ -108,7 +108,10 @@ SecurityWrapper<Base>::defineProperty(JSContext *cx, HandleObject wrapper,
HandleId id, MutableHandle<PropertyDescriptor> desc) const
{
if (desc.getter() || desc.setter()) {
JSString *str = IdToString(cx, id);
RootedValue idVal(cx, IdToValue(id));
JSString *str = ValueToSource(cx, idVal);
if (!str)
return false;
AutoStableStringChars chars(cx);
const char16_t *prop = nullptr;
if (str->ensureFlat(cx) && chars.initTwoByte(cx, str))