|
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 { |
|
18 if (!mOk) |
|
19 return; |
|
20 |
|
21 mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE); |
|
22 } |
|
23 |
|
24 void |
|
25 InfoObject::DefineProperty(const char *name, nsAString &value) |
|
26 { |
|
27 if (!mOk) |
|
28 return; |
|
29 |
|
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; |
|
35 |
|
36 if (!mOk) |
|
37 return; |
|
38 |
|
39 mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE); |
|
40 } |
|
41 |
|
42 void |
|
43 InfoObject::DefineProperty(const char *name, const char *value) |
|
44 { |
|
45 nsAutoString string = NS_ConvertASCIItoUTF16(value); |
|
46 DefineProperty(name, string); |
|
47 } |
|
48 |
|
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 } |