michael@0: /* vim: se cin sw=2 ts=2 et : */ michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "GfxInfoCollector.h" michael@0: #include "jsapi.h" michael@0: #include "nsString.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace widget; michael@0: michael@0: void michael@0: InfoObject::DefineProperty(const char *name, int value) michael@0: { michael@0: if (!mOk) michael@0: return; michael@0: michael@0: mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE); michael@0: } michael@0: michael@0: void michael@0: InfoObject::DefineProperty(const char *name, nsAString &value) michael@0: { michael@0: if (!mOk) michael@0: return; michael@0: michael@0: const nsString &flat = PromiseFlatString(value); michael@0: JS::Rooted string(mCx, JS_NewUCStringCopyN(mCx, static_cast(flat.get()), michael@0: flat.Length())); michael@0: if (!string) michael@0: mOk = false; michael@0: michael@0: if (!mOk) michael@0: return; michael@0: michael@0: mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE); michael@0: } michael@0: michael@0: void michael@0: InfoObject::DefineProperty(const char *name, const char *value) michael@0: { michael@0: nsAutoString string = NS_ConvertASCIItoUTF16(value); michael@0: DefineProperty(name, string); michael@0: } michael@0: michael@0: InfoObject::InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(true) michael@0: { michael@0: mObj = JS_NewObject(mCx, nullptr, JS::NullPtr(), JS::NullPtr()); michael@0: if (!mObj) michael@0: mOk = false; michael@0: }