Bug 583083 - Use the '//# sourceURL=display.js' directive's filename in js::SavedStacks; r=shu
authorNick Fitzgerald <fitzgen@gmail.com>
Wed, 15 Oct 2014 18:42:00 +0200
changeset 210633 c4d577ba087a
parent 210632 3dbe5e1f6a7d
child 210634 cd70b7fa7a12
push id50505
push usercbook@mozilla.com
push date2014-10-16 07:44 +0000
treeherdermozilla-inbound@9cdce80d5092 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs583083
milestone36.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 583083 - Use the '//# sourceURL=display.js' directive's filename in js::SavedStacks; r=shu
js/src/jit-test/tests/saved-stacks/display-url.js
js/src/vm/SavedStacks.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/saved-stacks/display-url.js
@@ -0,0 +1,26 @@
+eval(`
+  function a() {
+    return b();
+  }
+  //# sourceURL=source-a.js
+`);
+
+eval(`
+  function b() {
+    return c();
+  }
+  //# sourceURL=source-b.js
+`);
+
+eval(`
+  function c() {
+    return saveStack();
+  }
+  //# sourceURL=source-c.js
+`);
+
+let stack = a();
+print(stack);
+assertEq(stack.source, "source-c.js");
+assertEq(stack.parent.source, "source-b.js");
+assertEq(stack.parent.parent.source, "source-a.js");
--- a/js/src/vm/SavedStacks.cpp
+++ b/js/src/vm/SavedStacks.cpp
@@ -671,36 +671,43 @@ SavedStacks::getLocation(JSContext *cx, 
     assertSameCompartment(cx, this, iter.compartment());
 
     // When we have a |JSScript| for this frame, use a potentially memoized
     // location from our PCLocationMap and copy it into |locationp|. When we do
     // not have a |JSScript| for this frame (asm.js frames), we take a slow path
     // that doesn't employ memoization, and update |locationp|'s slots directly.
 
     if (!iter.hasScript()) {
-        const char *filename = iter.scriptFilename();
-        if (!filename)
-            filename = "";
-        locationp->source = Atomize(cx, filename, strlen(filename));
+        if (const char16_t *displayURL = iter.scriptDisplayURL()) {
+            locationp->source = AtomizeChars(cx, displayURL, js_strlen(displayURL));
+        } else {
+            const char *filename = iter.scriptFilename() ? iter.scriptFilename() : "";
+            locationp->source = Atomize(cx, filename, strlen(filename));
+        }
         if (!locationp->source)
             return false;
 
         locationp->line = iter.computeLine(&locationp->column);
         return true;
     }
 
     RootedScript script(cx, iter.script());
     jsbytecode *pc = iter.pc();
 
     PCKey key(script, pc);
     PCLocationMap::AddPtr p = pcLocationMap.lookupForAdd(key);
 
     if (!p) {
-        const char *filename = script->filename() ? script->filename() : "";
-        RootedAtom source(cx, Atomize(cx, filename, strlen(filename)));
+        RootedAtom source(cx);
+        if (const char16_t *displayURL = iter.scriptDisplayURL()) {
+            source = AtomizeChars(cx, displayURL, js_strlen(displayURL));
+        } else {
+            const char *filename = script->filename() ? script->filename() : "";
+            source = Atomize(cx, filename, strlen(filename));
+        }
         if (!source)
             return false;
 
         uint32_t column;
         uint32_t line = PCToLineNumber(script, pc, &column);
 
         LocationValue value(source, line, column);
         if (!pcLocationMap.add(p, key, value))