widget/xpwidgets/GfxInfoCollector.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* vim: se cin sw=2 ts=2 et : */
     2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     3  *
     4  * This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include "GfxInfoCollector.h"
     9 #include "jsapi.h"
    10 #include "nsString.h"
    12 using namespace mozilla;
    13 using namespace widget;
    15 void
    16 InfoObject::DefineProperty(const char *name, int value)
    17 {
    18   if (!mOk)
    19     return;
    21   mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE);
    22 }
    24 void
    25 InfoObject::DefineProperty(const char *name, nsAString &value)
    26 {
    27   if (!mOk)
    28     return;
    30   const nsString &flat = PromiseFlatString(value);
    31   JS::Rooted<JSString*> string(mCx, JS_NewUCStringCopyN(mCx, static_cast<const jschar*>(flat.get()),
    32                                                         flat.Length()));
    33   if (!string)
    34     mOk = false;
    36   if (!mOk)
    37     return;
    39   mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE);
    40 }
    42 void
    43 InfoObject::DefineProperty(const char *name, const char *value)
    44 {
    45   nsAutoString string = NS_ConvertASCIItoUTF16(value);
    46   DefineProperty(name, string);
    47 }
    49 InfoObject::InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(true)
    50 {
    51   mObj = JS_NewObject(mCx, nullptr, JS::NullPtr(), JS::NullPtr());
    52   if (!mObj)
    53     mOk = false;
    54 }

mercurial