tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Variant.cpp (1822B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "Variant.h"
      8 
      9 #include "nsCOMPtr.h"
     10 
     11 extern "C" {
     12 
     13 using namespace mozilla::storage;
     14 
     15 /**
     16 * Return the data type of the given variant.  This method used to be exposed
     17 * to XPCOM, but since bug 1507540 it's marked [notxpcom] in the interface
     18 * definition, so we need this C function to access it from Rust.
     19 */
     20 uint16_t NS_GetDataType(nsIVariant* aVariant) {
     21  return aVariant->GetDataType();
     22 }
     23 
     24 // Convenience functions to create Storage variants from Rust.
     25 void NS_NewStorageNullVariant(nsIVariant** aVariant) {
     26  nsCOMPtr<nsIVariant> variant = new NullVariant();
     27  variant.forget(aVariant);
     28 }
     29 
     30 void NS_NewStorageBooleanVariant(bool aValue, nsIVariant** aVariant) {
     31  nsCOMPtr<nsIVariant> variant = new BooleanVariant(aValue);
     32  variant.forget(aVariant);
     33 }
     34 
     35 void NS_NewStorageIntegerVariant(int64_t aValue, nsIVariant** aVariant) {
     36  nsCOMPtr<nsIVariant> variant = new IntegerVariant(aValue);
     37  variant.forget(aVariant);
     38 }
     39 
     40 void NS_NewStorageFloatVariant(double aValue, nsIVariant** aVariant) {
     41  nsCOMPtr<nsIVariant> variant = new FloatVariant(aValue);
     42  variant.forget(aVariant);
     43 }
     44 
     45 void NS_NewStorageTextVariant(const nsAString& aValue, nsIVariant** aVariant) {
     46  nsCOMPtr<nsIVariant> variant = new TextVariant(aValue);
     47  variant.forget(aVariant);
     48 }
     49 
     50 void NS_NewStorageUTF8TextVariant(const nsACString& aValue,
     51                                  nsIVariant** aVariant) {
     52  nsCOMPtr<nsIVariant> variant = new UTF8TextVariant(aValue);
     53  variant.forget(aVariant);
     54 }
     55 
     56 }  // extern "C"