Bug 918330 - GfxInfoCollector.h should not include jsapi.h - r=ehsan

This commit is contained in:
Benoit Jacob 2013-09-19 16:02:03 -04:00
parent 12410f1623
commit fda7de8752
4 changed files with 61 additions and 36 deletions

View File

@ -18,6 +18,7 @@
#include "GfxInfoCollector.h" #include "GfxInfoCollector.h"
#include "nsIGfxInfoDebug.h" #include "nsIGfxInfoDebug.h"
#include "mozilla/Mutex.h" #include "mozilla/Mutex.h"
#include "js/Value.h"
namespace mozilla { namespace mozilla {
namespace widget { namespace widget {

View File

@ -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<const jschar*>(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;
}

View File

@ -8,8 +8,9 @@
#ifndef __mozilla_widget_GfxInfoCollector_h__ #ifndef __mozilla_widget_GfxInfoCollector_h__
#define __mozilla_widget_GfxInfoCollector_h__ #define __mozilla_widget_GfxInfoCollector_h__
#include "jsapi.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "nsStringFwd.h"
#include "js/RootingAPI.h"
namespace mozilla { namespace mozilla {
namespace widget { namespace widget {
@ -22,44 +23,13 @@ class MOZ_STACK_CLASS InfoObject
friend class GfxInfoBase; friend class GfxInfoBase;
public: public:
void DefineProperty(const char *name, int value) void DefineProperty(const char *name, int value);
{ void DefineProperty(const char *name, nsAString &value);
if (!mOk) void DefineProperty(const char *name, const char *value);
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<const jschar*>(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);
}
private: private:
// We need to ensure that this object lives on the stack so that GC sees it properly // 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) InfoObject(JSContext *aCx);
{
mObj = JS_NewObject(mCx, NULL, NULL, NULL);
if (!mObj)
mOk = false;
}
InfoObject(InfoObject&); InfoObject(InfoObject&);
JSContext *mCx; JSContext *mCx;

View File

@ -15,6 +15,7 @@ CPP_SOURCES += [
'APZCCallbackHelper.cpp', 'APZCCallbackHelper.cpp',
'GfxDriverInfo.cpp', 'GfxDriverInfo.cpp',
'GfxInfoBase.cpp', 'GfxInfoBase.cpp',
'GfxInfoCollector.cpp',
'GfxInfoWebGL.cpp', 'GfxInfoWebGL.cpp',
'InputData.cpp', 'InputData.cpp',
'PuppetWidget.cpp', 'PuppetWidget.cpp',