/src/mozilla-central/widget/GfxInfoCollector.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
7 | | |
8 | | #include "GfxInfoCollector.h" |
9 | | #include "jsapi.h" |
10 | | #include "nsString.h" |
11 | | |
12 | | using namespace mozilla; |
13 | | using namespace widget; |
14 | | |
15 | | void |
16 | | InfoObject::DefineProperty(const char *name, int value) |
17 | 0 | { |
18 | 0 | if (!mOk) |
19 | 0 | return; |
20 | 0 | |
21 | 0 | mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE); |
22 | 0 | } |
23 | | |
24 | | void |
25 | | InfoObject::DefineProperty(const char *name, nsAString &value) |
26 | 0 | { |
27 | 0 | if (!mOk) |
28 | 0 | return; |
29 | 0 | |
30 | 0 | const nsString &flat = PromiseFlatString(value); |
31 | 0 | JS::Rooted<JSString*> string(mCx, JS_NewUCStringCopyN(mCx, static_cast<const char16_t*>(flat.get()), |
32 | 0 | flat.Length())); |
33 | 0 | if (!string) |
34 | 0 | mOk = false; |
35 | 0 |
|
36 | 0 | if (!mOk) |
37 | 0 | return; |
38 | 0 | |
39 | 0 | mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE); |
40 | 0 | } |
41 | | |
42 | | void |
43 | | InfoObject::DefineProperty(const char *name, const char *value) |
44 | 0 | { |
45 | 0 | nsAutoString string = NS_ConvertASCIItoUTF16(value); |
46 | 0 | DefineProperty(name, string); |
47 | 0 | } |
48 | | |
49 | | InfoObject::InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(true) |
50 | 0 | { |
51 | 0 | mObj = JS_NewPlainObject(aCx); |
52 | 0 | if (!mObj) |
53 | 0 | mOk = false; |
54 | 0 | } |