Bug 1261207 - Forward declare `js::ScriptSource` instead of casting `void*` pointers; r=jimb
authorNick Fitzgerald <fitzgen@gmail.com>
Thu, 31 Mar 2016 23:07:34 -0700
changeset 291131 9d39b91bba9c192fe3cca3c772e3e83e96b9a298
parent 291130 53400e993cb8a295a72dc247436b862844686588
child 291132 1d2d0e61c4d1d045fc41c7393f8c583e88d8549c
push id74479
push userkcambridge@mozilla.com
push dateFri, 01 Apr 2016 06:10:58 +0000
treeherdermozilla-inbound@906bb507cee3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1261207
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 1261207 - Forward declare `js::ScriptSource` instead of casting `void*` pointers; r=jimb MozReview-Commit-ID: KfzlLDjCYIn
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -6202,34 +6202,33 @@ JS_IsIdentifier(const char16_t* chars, s
     return js::frontend::IsIdentifier(chars, length);
 }
 
 namespace JS {
 
 void AutoFilename::reset()
 {
     if (ss_) {
-        reinterpret_cast<ScriptSource*>(ss_)->decref();
+        ss_->decref();
         ss_ = nullptr;
     }
     if (filename_.is<const char*>())
         filename_.as<const char*>() = nullptr;
     else
         filename_.as<UniqueChars>().reset();
 }
 
-void AutoFilename::setScriptSource(void* p)
+void AutoFilename::setScriptSource(js::ScriptSource* p)
 {
     MOZ_ASSERT(!ss_);
     MOZ_ASSERT(!get());
     ss_ = p;
     if (p) {
-        ScriptSource* ss = reinterpret_cast<ScriptSource*>(p);
-        ss->incref();
-        setUnowned(ss->filename());
+        p->incref();
+        setUnowned(p->filename());
     }
 }
 
 void AutoFilename::setUnowned(const char* filename)
 {
     MOZ_ASSERT(!get());
     filename_.as<const char*>() = filename;
 }
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -5557,23 +5557,26 @@ JS_IsIdentifier(JSContext* cx, JS::Handl
 /**
  * Test whether the given chars + length are a valid ECMAScript identifier.
  * This version is infallible, so just returns whether the chars are an
  * identifier.
  */
 extern JS_PUBLIC_API(bool)
 JS_IsIdentifier(const char16_t* chars, size_t length);
 
+namespace js {
+class ScriptSource;
+} // namespace js
+
 namespace JS {
 
 class MOZ_RAII JS_PUBLIC_API(AutoFilename)
 {
   private:
-    // Actually a ScriptSource, not put here to avoid including the world.
-    void* ss_;
+    js::ScriptSource* ss_;
     mozilla::Variant<const char*, UniqueChars> filename_;
 
     AutoFilename(const AutoFilename&) = delete;
     AutoFilename& operator=(const AutoFilename&) = delete;
 
   public:
     AutoFilename()
       : ss_(nullptr),
@@ -5583,17 +5586,17 @@ class MOZ_RAII JS_PUBLIC_API(AutoFilenam
     ~AutoFilename() {
         reset();
     }
 
     void reset();
 
     void setOwned(UniqueChars&& filename);
     void setUnowned(const char* filename);
-    void setScriptSource(void* ss);
+    void setScriptSource(js::ScriptSource* ss);
 
     const char* get() const;
 };
 
 /**
  * Return the current filename, line number and column number of the most
  * currently running frame. Returns true if a scripted frame was found, false
  * otherwise.