Bug 1614879 [wpt PR 21750] - Set request mode for beacon request with non-cors-safeli...
[gecko.git] / widget / GfxInfoCollector.cpp
blob262b2206cd31c235ea140c7c173c1a084b31e365
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 "nsString.h"
12 using namespace mozilla;
13 using namespace widget;
15 void InfoObject::DefineProperty(const char* name, int value) {
16 if (!mOk) return;
18 mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE);
21 void InfoObject::DefineProperty(const char* name, nsAString& value) {
22 if (!mOk) return;
24 const nsString& flat = PromiseFlatString(value);
25 JS::Rooted<JSString*> string(
26 mCx, JS_NewUCStringCopyN(mCx, static_cast<const char16_t*>(flat.get()),
27 flat.Length()));
28 if (!string) mOk = false;
30 if (!mOk) return;
32 mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE);
35 void InfoObject::DefineProperty(const char* name, const char* value) {
36 nsAutoString string = NS_ConvertASCIItoUTF16(value);
37 DefineProperty(name, string);
40 InfoObject::InfoObject(JSContext* aCx) : mCx(aCx), mObj(aCx), mOk(true) {
41 mObj = JS_NewPlainObject(aCx);
42 if (!mObj) mOk = false;