Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 }