Bug 1254893 - Append "> wasm" to URLs of wasm Debugger.Sources to hack around blacklisting in devtools. (r=jimb)
authorShu-yu Guo <shu@rfrn.org>
Fri, 11 Mar 2016 21:43:21 -0800
changeset 288415 9ac34b44f27662f5a574b85bf9f4234c4f22f8ba
parent 288414 3300390349c66d11ca89c7862c165b8f241933f0
child 288416 293d196105f1d68eeb6c9a784772bed814e8e5ac
push id30079
push userryanvm@gmail.com
push dateSat, 12 Mar 2016 20:24:19 +0000
treeherdermozilla-central@d1d47ba19ce9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1254893
milestone48.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 1254893 - Append "> wasm" to URLs of wasm Debugger.Sources to hack around blacklisting in devtools. (r=jimb)
js/src/vm/Debugger.cpp
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -48,16 +48,18 @@ using namespace js;
 
 using JS::dbg::AutoEntryMonitor;
 using JS::dbg::Builder;
 using js::frontend::IsIdentifier;
 using mozilla::ArrayLength;
 using mozilla::DebugOnly;
 using mozilla::MakeScopeExit;
 using mozilla::Maybe;
+using mozilla::Some;
+using mozilla::Nothing;
 using mozilla::Variant;
 using mozilla::AsVariant;
 
 
 /*** Forward declarations ************************************************************************/
 
 extern const Class DebuggerFrame_class;
 
@@ -6488,40 +6490,56 @@ DebuggerSource_getText(JSContext* cx, un
     if (!str)
         return false;
 
     args.rval().setString(str);
     obj->setReservedSlot(JSSLOT_DEBUGSOURCE_TEXT, args.rval());
     return true;
 }
 
-struct DebuggerSourceGetURLMatcher
-{
-    using ReturnType = const char*;
+class DebuggerSourceGetURLMatcher
+{
+    JSContext* cx_;
+
+  public:
+    explicit DebuggerSourceGetURLMatcher(JSContext* cx) : cx_(cx) { }
+
+    using ReturnType = Maybe<JSString*>;
+
     ReturnType match(HandleScriptSource sourceObject) {
         ScriptSource* ss = sourceObject->source();
         MOZ_ASSERT(ss);
-        return ss->filename();
+        if (ss->filename()) {
+            JSString* str = NewStringCopyZ<CanGC>(cx_, ss->filename());
+            return Some(str);
+        }
+        return Nothing();
     }
     ReturnType match(Handle<WasmModuleObject*> wasmModule) {
-        return wasmModule->module().filename();
+        // TODOshu: Until wasm modules have real URLs, append "> wasm" to the
+        // end to prevent them from being blacklisted by devtools by having
+        // the same value as a source mapped URL.
+        char* buf = JS_smprintf("%s > wasm", wasmModule->module().filename());
+        JSString* str = NewStringCopyZ<CanGC>(cx_, buf);
+        JS_smprintf_free(buf);
+        return Some(str);
     }
 };
 
 static bool
 DebuggerSource_getURL(JSContext* cx, unsigned argc, Value* vp)
 {
     THIS_DEBUGSOURCE_REFERENT(cx, argc, vp, "(get url)", args, obj, referent);
 
-    DebuggerSourceGetURLMatcher matcher;
-    if (const char* url = referent.match(matcher)) {
-        JSString* str = NewStringCopyZ<CanGC>(cx, url);
-        if (!str)
-            return false;
-        args.rval().setString(str);
+    DebuggerSourceGetURLMatcher matcher(cx);
+    Maybe<JSString*> str = referent.match(matcher);
+    if (str.isSome()) {
+        if (!*str)
+            return false;
+        args.rval().setString(*str);
     } else {
         args.rval().setNull();
     }
     return true;
 }
 
 struct DebuggerSourceGetDisplayURLMatcher
 {