Bug 1173638. Make the constructors for Error and its subtypes get their filenames/linenumbers from the saved stack, not manually. r=fitzgen,bholley

The changes in webgl code are to ensure that we're in a reasonable compartment
while reporting a warning via the JS engine.
This commit is contained in:
Boris Zbarsky 2015-06-15 20:05:49 -04:00
parent 6d949db8b8
commit d7618f4f57
5 changed files with 25 additions and 9 deletions

View File

@ -492,7 +492,16 @@ WebGLContext::GenerateWarning(const char* fmt, va_list ap)
// no need to print to stderr, as JS_ReportWarning takes care of this for us.
AutoJSContext cx;
if (!mCanvasElement) {
return;
}
AutoJSAPI api;
if (!api.Init(mCanvasElement->OwnerDoc()->GetScopeObject())) {
return;
}
JSContext* cx = api.cx();
JS_ReportWarning(cx, "WebGL: %s", buf);
if (!ShouldGenerateWarnings()) {
JS_ReportWarning(cx,

View File

@ -253,9 +253,9 @@ PopulateReportBlame(JSContext* cx, JSErrorReport* report)
{
/*
* Walk stack until we find a frame that is associated with a non-builtin
* rather than a builtin frame.
* rather than a builtin frame and which we're allowed to know about.
*/
NonBuiltinFrameIter iter(cx);
NonBuiltinFrameIter iter(cx, cx->compartment()->principals());
if (iter.done())
return;

View File

@ -336,8 +336,8 @@ Error(JSContext* cx, unsigned argc, Value* vp)
return false;
}
/* Find the scripted caller. */
NonBuiltinFrameIter iter(cx);
/* Find the scripted caller, but only ones we're allowed to know about. */
NonBuiltinFrameIter iter(cx, cx->compartment()->principals());
/* Set the 'fileName' property. */
RootedString fileName(cx);
@ -867,7 +867,7 @@ ErrorReport::populateUncaughtExceptionReportVA(JSContext* cx, va_list ap)
// XXXbz this assumes the stack we have right now is still
// related to our exception object. It would be better if we
// could accept a passed-in stack of some sort instead.
NonBuiltinFrameIter iter(cx);
NonBuiltinFrameIter iter(cx, cx->compartment()->principals());
if (!iter.done()) {
ownedReport.filename = iter.scriptFilename();
ownedReport.lineno = iter.computeLine(&ownedReport.column);

View File

@ -1903,6 +1903,13 @@ class NonBuiltinFrameIter : public FrameIter
settle();
}
NonBuiltinFrameIter(JSContext* cx, JSPrincipals* principals)
: FrameIter(cx, FrameIter::ALL_CONTEXTS, FrameIter::GO_THROUGH_SAVED,
FrameIter::FOLLOW_DEBUGGER_EVAL_PREV_LINK, principals)
{
settle();
}
explicit NonBuiltinFrameIter(const FrameIter::Data& data)
: FrameIter(data)
{}

View File

@ -579,9 +579,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
is(e[name], undefined, name + " property censored after suspicious replacement");
}
testProperty('message', x => x == 'some message', 'some other message', 42);
testProperty('fileName', x => /xul/.test(x), 'otherFilename.html', new iwin.Object());
testProperty('columnNumber', x => x > 5 && x < 100, 99, 99.5);
testProperty('lineNumber', x => x > 100 && x < 10000, 50, 'foo');
testProperty('fileName', x => x == '', 'otherFilename.html', new iwin.Object());
testProperty('columnNumber', x => x == 1, 99, 99.5);
testProperty('lineNumber', x => x == 0, 50, 'foo');
// Note - an Exception newed via Xrays is going to have an empty stack given the
// current semantics and implementation. This tests the current behavior, but that