1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/xpwidgets/GfxInfoCollector.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* vim: se cin sw=2 ts=2 et : */ 1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "GfxInfoCollector.h" 1.12 +#include "jsapi.h" 1.13 +#include "nsString.h" 1.14 + 1.15 +using namespace mozilla; 1.16 +using namespace widget; 1.17 + 1.18 +void 1.19 +InfoObject::DefineProperty(const char *name, int value) 1.20 +{ 1.21 + if (!mOk) 1.22 + return; 1.23 + 1.24 + mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE); 1.25 +} 1.26 + 1.27 +void 1.28 +InfoObject::DefineProperty(const char *name, nsAString &value) 1.29 +{ 1.30 + if (!mOk) 1.31 + return; 1.32 + 1.33 + const nsString &flat = PromiseFlatString(value); 1.34 + JS::Rooted<JSString*> string(mCx, JS_NewUCStringCopyN(mCx, static_cast<const jschar*>(flat.get()), 1.35 + flat.Length())); 1.36 + if (!string) 1.37 + mOk = false; 1.38 + 1.39 + if (!mOk) 1.40 + return; 1.41 + 1.42 + mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE); 1.43 +} 1.44 + 1.45 +void 1.46 +InfoObject::DefineProperty(const char *name, const char *value) 1.47 +{ 1.48 + nsAutoString string = NS_ConvertASCIItoUTF16(value); 1.49 + DefineProperty(name, string); 1.50 +} 1.51 + 1.52 +InfoObject::InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(true) 1.53 +{ 1.54 + mObj = JS_NewObject(mCx, nullptr, JS::NullPtr(), JS::NullPtr()); 1.55 + if (!mObj) 1.56 + mOk = false; 1.57 +}