From fda7de87522701815972630fec28ddbe9f197a2b Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 19 Sep 2013 16:02:03 -0400 Subject: [PATCH] Bug 918330 - GfxInfoCollector.h should not include jsapi.h - r=ehsan --- widget/xpwidgets/GfxInfoBase.h | 1 + widget/xpwidgets/GfxInfoCollector.cpp | 53 +++++++++++++++++++++++++++ widget/xpwidgets/GfxInfoCollector.h | 42 +++------------------ widget/xpwidgets/moz.build | 1 + 4 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 widget/xpwidgets/GfxInfoCollector.cpp diff --git a/widget/xpwidgets/GfxInfoBase.h b/widget/xpwidgets/GfxInfoBase.h index 28704a5ff21..e7007a56283 100644 --- a/widget/xpwidgets/GfxInfoBase.h +++ b/widget/xpwidgets/GfxInfoBase.h @@ -18,6 +18,7 @@ #include "GfxInfoCollector.h" #include "nsIGfxInfoDebug.h" #include "mozilla/Mutex.h" +#include "js/Value.h" namespace mozilla { namespace widget { diff --git a/widget/xpwidgets/GfxInfoCollector.cpp b/widget/xpwidgets/GfxInfoCollector.cpp new file mode 100644 index 00000000000..8f077443c98 --- /dev/null +++ b/widget/xpwidgets/GfxInfoCollector.cpp @@ -0,0 +1,53 @@ +/* vim: se cin sw=2 ts=2 et : */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "GfxInfoCollector.h" +#include "jsapi.h" +#include "nsStringGlue.h" + +using namespace mozilla; +using namespace widget; + +void +InfoObject::DefineProperty(const char *name, int value) +{ + if (!mOk) + return; + + mOk = JS_DefineProperty(mCx, mObj, name, INT_TO_JSVAL(value), NULL, NULL, JSPROP_ENUMERATE); +} + +void +InfoObject::DefineProperty(const char *name, nsAString &value) +{ + if (!mOk) + return; + + const nsString &flat = PromiseFlatString(value); + JSString *string = JS_NewUCStringCopyN(mCx, static_cast(flat.get()), flat.Length()); + if (!string) + mOk = false; + + if (!mOk) + return; + + mOk = JS_DefineProperty(mCx, mObj, name, STRING_TO_JSVAL(string), NULL, NULL, JSPROP_ENUMERATE); +} + +void +InfoObject::DefineProperty(const char *name, const char *value) +{ + nsAutoString string = NS_ConvertASCIItoUTF16(value); + DefineProperty(name, string); +} + +InfoObject::InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(true) +{ + mObj = JS_NewObject(mCx, NULL, NULL, NULL); + if (!mObj) + mOk = false; +} \ No newline at end of file diff --git a/widget/xpwidgets/GfxInfoCollector.h b/widget/xpwidgets/GfxInfoCollector.h index bafbfd66c8c..c4c1a618ee1 100644 --- a/widget/xpwidgets/GfxInfoCollector.h +++ b/widget/xpwidgets/GfxInfoCollector.h @@ -8,8 +8,9 @@ #ifndef __mozilla_widget_GfxInfoCollector_h__ #define __mozilla_widget_GfxInfoCollector_h__ -#include "jsapi.h" #include "mozilla/Attributes.h" +#include "nsStringFwd.h" +#include "js/RootingAPI.h" namespace mozilla { namespace widget { @@ -22,44 +23,13 @@ class MOZ_STACK_CLASS InfoObject friend class GfxInfoBase; public: - void DefineProperty(const char *name, int value) - { - if (!mOk) - return; - - mOk = JS_DefineProperty(mCx, mObj, name, INT_TO_JSVAL(value), NULL, NULL, JSPROP_ENUMERATE); - } - - void DefineProperty(const char *name, nsAString &value) - { - if (!mOk) - return; - - const nsString &flat = PromiseFlatString(value); - JSString *string = JS_NewUCStringCopyN(mCx, static_cast(flat.get()), flat.Length()); - if (!string) - mOk = false; - - if (!mOk) - return; - - mOk = JS_DefineProperty(mCx, mObj, name, STRING_TO_JSVAL(string), NULL, NULL, JSPROP_ENUMERATE); - } - - void DefineProperty(const char *name, const char *value) - { - nsAutoString string = NS_ConvertASCIItoUTF16(value); - DefineProperty(name, string); - } + void DefineProperty(const char *name, int value); + void DefineProperty(const char *name, nsAString &value); + void DefineProperty(const char *name, const char *value); private: // We need to ensure that this object lives on the stack so that GC sees it properly - InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(true) - { - mObj = JS_NewObject(mCx, NULL, NULL, NULL); - if (!mObj) - mOk = false; - } + InfoObject(JSContext *aCx); InfoObject(InfoObject&); JSContext *mCx; diff --git a/widget/xpwidgets/moz.build b/widget/xpwidgets/moz.build index 61b2707d3e2..287fac0f460 100644 --- a/widget/xpwidgets/moz.build +++ b/widget/xpwidgets/moz.build @@ -15,6 +15,7 @@ CPP_SOURCES += [ 'APZCCallbackHelper.cpp', 'GfxDriverInfo.cpp', 'GfxInfoBase.cpp', + 'GfxInfoCollector.cpp', 'GfxInfoWebGL.cpp', 'InputData.cpp', 'PuppetWidget.cpp',