mozStorageStatementJSHelper.h (1725B)
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 #ifndef MOZSTORAGESTATEMENTJSHELPER_H 8 #define MOZSTORAGESTATEMENTJSHELPER_H 9 10 #include "nsIXPCScriptable.h" 11 12 class Statement; 13 14 namespace mozilla { 15 namespace storage { 16 17 class StatementParams; 18 class StatementRow; 19 20 class StatementJSHelper : public nsIXPCScriptable { 21 public: 22 NS_DECL_ISUPPORTS 23 NS_DECL_NSIXPCSCRIPTABLE 24 25 private: 26 nsresult getRow(Statement*, JSContext*, JSObject*, JS::Value*); 27 nsresult getParams(Statement*, JSContext*, JSObject*, JS::Value*); 28 }; 29 30 /** 31 * Wrappers used to clean up the references JS helpers hold to the statement. 32 * For cycle-avoidance reasons they do not hold reference-counted references, 33 * so it is important we do this. 34 */ 35 36 class StatementParamsHolder final : public nsISupports { 37 public: 38 NS_DECL_ISUPPORTS 39 40 explicit StatementParamsHolder(StatementParams* aParams) : mParams(aParams) {} 41 42 StatementParams* Get() const { 43 MOZ_ASSERT(mParams); 44 return mParams; 45 } 46 47 private: 48 virtual ~StatementParamsHolder(); 49 50 RefPtr<StatementParams> mParams; 51 }; 52 53 class StatementRowHolder final : public nsISupports { 54 public: 55 NS_DECL_ISUPPORTS 56 57 explicit StatementRowHolder(StatementRow* aRow) : mRow(aRow) {} 58 59 StatementRow* Get() const { 60 MOZ_ASSERT(mRow); 61 return mRow; 62 } 63 64 private: 65 virtual ~StatementRowHolder(); 66 67 RefPtr<StatementRow> mRow; 68 }; 69 70 } // namespace storage 71 } // namespace mozilla 72 73 #endif // MOZSTORAGESTATEMENTJSHELPER_H