GfxInfoCollector.cpp 1.3 KB

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