Bug 1869043 assert that graph set access is main thread only r=padenot
[gecko.git] / widget / GfxInfoCollector.cpp
blob6ad8494586b47db083161c98b14fcd6c0147fb40
1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 "js/PropertyAndElement.h" // JS_DefineProperty
11 #include "nsString.h"
13 using namespace mozilla;
14 using namespace widget;
16 void InfoObject::DefineProperty(const char* name, int value) {
17 if (!mOk) return;
19 mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE);
22 void InfoObject::DefineProperty(const char* name, const nsAString& value) {
23 if (!mOk) return;
25 const nsString& flat = PromiseFlatString(value);
26 JS::Rooted<JSString*> string(
27 mCx, JS_NewUCStringCopyN(mCx, static_cast<const char16_t*>(flat.get()),
28 flat.Length()));
29 if (!string) mOk = false;
31 if (!mOk) return;
33 mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE);
36 void InfoObject::DefineProperty(const char* name, const char* value) {
37 nsAutoString string = NS_ConvertASCIItoUTF16(value);
38 DefineProperty(name, string);
41 InfoObject::InfoObject(JSContext* aCx) : mCx(aCx), mObj(aCx), mOk(true) {
42 mObj = JS_NewPlainObject(aCx);
43 if (!mObj) mOk = false;