Bug 1274193 part 9 - Do principal filtering in DescribeScriptedCallerForCompilation and use GO_THROUGH_SAVED. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 24 May 2016 14:38:34 +0200
changeset 337764 8fa9dceab5e6426764a81e383e4b331ecc41d2e4
parent 337763 ee7ad0668921821cb699c20974bacb88d59514ce
child 337765 472fd2e0cf31ade0406443a8980acd200d8569c1
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1274193
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1274193 part 9 - Do principal filtering in DescribeScriptedCallerForCompilation and use GO_THROUGH_SAVED. r=luke
js/src/builtin/Eval.cpp
js/src/jit-test/tests/basic/eval-introduction-principals.js
js/src/jsscript.cpp
--- a/js/src/builtin/Eval.cpp
+++ b/js/src/builtin/Eval.cpp
@@ -288,24 +288,30 @@ EvalKernel(JSContext* cx, HandleValue v,
             enclosing = callerScript->innermostStaticScope(pc);
         else
             enclosing = &cx->global()->lexicalScope().staticBlock();
         Rooted<StaticEvalScope*> staticScope(cx, StaticEvalScope::create(cx, enclosing));
         if (!staticScope)
             return false;
 
         CompileOptions options(cx);
-        options.setFileAndLine(filename, 1)
-               .setIsRunOnce(true)
+        options.setIsRunOnce(true)
                .setForEval(true)
                .setNoScriptRval(false)
                .setMutedErrors(mutedErrors)
-               .setIntroductionInfo(introducerFilename, "eval", lineno, maybeScript, pcOffset)
                .maybeMakeStrictMode(evalType == DIRECT_EVAL && IsStrictEvalPC(pc));
 
+        if (introducerFilename) {
+            options.setFileAndLine(filename, 1);
+            options.setIntroductionInfo(introducerFilename, "eval", lineno, maybeScript, pcOffset);
+        } else {
+            options.setFileAndLine("eval", 1);
+            options.setIntroductionType("eval");
+        }
+
         AutoStableStringChars linearChars(cx);
         if (!linearChars.initTwoByte(cx, linearStr))
             return false;
 
         const char16_t* chars = linearChars.twoByteRange().start().get();
         SourceBufferHolder::Ownership ownership = linearChars.maybeGiveOwnershipToCaller()
                                                   ? SourceBufferHolder::GiveOwnership
                                                   : SourceBufferHolder::NoOwnership;
@@ -370,24 +376,30 @@ js::DirectEvalStringFromIon(JSContext* c
             introducerFilename = maybeScript->scriptSource()->introducerFilename();
 
         RootedObject enclosing(cx, callerScript->innermostStaticScope(pc));
         Rooted<StaticEvalScope*> staticScope(cx, StaticEvalScope::create(cx, enclosing));
         if (!staticScope)
             return false;
 
         CompileOptions options(cx);
-        options.setFileAndLine(filename, 1)
-               .setIsRunOnce(true)
+        options.setIsRunOnce(true)
                .setForEval(true)
                .setNoScriptRval(false)
                .setMutedErrors(mutedErrors)
-               .setIntroductionInfo(introducerFilename, "eval", lineno, maybeScript, pcOffset)
                .maybeMakeStrictMode(IsStrictEvalPC(pc));
 
+        if (introducerFilename) {
+            options.setFileAndLine(filename, 1);
+            options.setIntroductionInfo(introducerFilename, "eval", lineno, maybeScript, pcOffset);
+        } else {
+            options.setFileAndLine("eval", 1);
+            options.setIntroductionType("eval");
+        }
+
         AutoStableStringChars linearChars(cx);
         if (!linearChars.initTwoByte(cx, linearStr))
             return false;
 
         const char16_t* chars = linearChars.twoByteRange().start().get();
         SourceBufferHolder::Ownership ownership = linearChars.maybeGiveOwnershipToCaller()
                                                   ? SourceBufferHolder::GiveOwnership
                                                   : SourceBufferHolder::NoOwnership;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/eval-introduction-principals.js
@@ -0,0 +1,16 @@
+// Ensure the introduction info for eval scripts respects principal checks.
+
+function myAPI(f) { return f(); }
+
+var contentGlobal = newGlobal({principal: 0x1});
+contentGlobal.chrome = this;
+contentGlobal.eval("\n" +
+		   "function contentTest() { chrome.myAPI(eval.bind(undefined, 'chrome.stack = Error().stack;')) };\n" +
+		   "contentTest();");
+
+// Note that the stack below does not include the current filename or file
+// line numbers, and there's no trace of the myAPI call between the two
+// evals.
+assertEq(stack, "@eval line 2 > eval:1:16\n" +
+                "contentTest@eval:2:26\n" +
+                "@eval:3:1\n");
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -3365,17 +3365,17 @@ js::DescribeScriptedCallerForCompilation
 
         *file = maybeScript->filename();
         *linenop = GET_UINT32(nextpc);
         *pcOffset = pc - maybeScript->code();
         *mutedErrors = maybeScript->mutedErrors();
         return;
     }
 
-    NonBuiltinFrameIter iter(cx, FrameIter::STOP_AT_SAVED);
+    NonBuiltinFrameIter iter(cx, cx->compartment()->principals());
 
     if (iter.done()) {
         maybeScript.set(nullptr);
         *file = nullptr;
         *linenop = 0;
         *pcOffset = 0;
         *mutedErrors = false;
         return;