storage/src/mozStorageAsyncStatementJSHelper.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsIXPConnect.h"
michael@0 8 #include "mozStorageAsyncStatement.h"
michael@0 9 #include "mozStorageService.h"
michael@0 10
michael@0 11 #include "nsMemory.h"
michael@0 12 #include "nsString.h"
michael@0 13 #include "nsServiceManagerUtils.h"
michael@0 14
michael@0 15 #include "mozStorageAsyncStatementJSHelper.h"
michael@0 16
michael@0 17 #include "mozStorageAsyncStatementParams.h"
michael@0 18
michael@0 19 #include "jsapi.h"
michael@0 20
michael@0 21 namespace mozilla {
michael@0 22 namespace storage {
michael@0 23
michael@0 24 ////////////////////////////////////////////////////////////////////////////////
michael@0 25 //// AsyncStatementJSHelper
michael@0 26
michael@0 27 nsresult
michael@0 28 AsyncStatementJSHelper::getParams(AsyncStatement *aStatement,
michael@0 29 JSContext *aCtx,
michael@0 30 JSObject *aScopeObj,
michael@0 31 jsval *_params)
michael@0 32 {
michael@0 33 nsresult rv;
michael@0 34
michael@0 35 #ifdef DEBUG
michael@0 36 int32_t state;
michael@0 37 (void)aStatement->GetState(&state);
michael@0 38 NS_ASSERTION(state == mozIStorageAsyncStatement::MOZ_STORAGE_STATEMENT_READY,
michael@0 39 "Invalid state to get the params object - all calls will fail!");
michael@0 40 #endif
michael@0 41
michael@0 42 if (!aStatement->mStatementParamsHolder) {
michael@0 43 nsCOMPtr<mozIStorageStatementParams> params =
michael@0 44 new AsyncStatementParams(aStatement);
michael@0 45 NS_ENSURE_TRUE(params, NS_ERROR_OUT_OF_MEMORY);
michael@0 46
michael@0 47 JS::RootedObject scope(aCtx, aScopeObj);
michael@0 48 nsCOMPtr<nsIXPConnect> xpc(Service::getXPConnect());
michael@0 49 rv = xpc->WrapNative(
michael@0 50 aCtx,
michael@0 51 ::JS_GetGlobalForObject(aCtx, scope),
michael@0 52 params,
michael@0 53 NS_GET_IID(mozIStorageStatementParams),
michael@0 54 getter_AddRefs(aStatement->mStatementParamsHolder)
michael@0 55 );
michael@0 56 NS_ENSURE_SUCCESS(rv, rv);
michael@0 57 }
michael@0 58
michael@0 59 JS::Rooted<JSObject*> obj(aCtx);
michael@0 60 obj = aStatement->mStatementParamsHolder->GetJSObject();
michael@0 61 NS_ENSURE_STATE(obj);
michael@0 62
michael@0 63 *_params = OBJECT_TO_JSVAL(obj);
michael@0 64 return NS_OK;
michael@0 65 }
michael@0 66
michael@0 67 NS_IMETHODIMP_(MozExternalRefCountType) AsyncStatementJSHelper::AddRef() { return 2; }
michael@0 68 NS_IMETHODIMP_(MozExternalRefCountType) AsyncStatementJSHelper::Release() { return 1; }
michael@0 69 NS_INTERFACE_MAP_BEGIN(AsyncStatementJSHelper)
michael@0 70 NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
michael@0 71 NS_INTERFACE_MAP_ENTRY(nsISupports)
michael@0 72 NS_INTERFACE_MAP_END
michael@0 73
michael@0 74 ////////////////////////////////////////////////////////////////////////////////
michael@0 75 //// nsIXPCScriptable
michael@0 76
michael@0 77 #define XPC_MAP_CLASSNAME AsyncStatementJSHelper
michael@0 78 #define XPC_MAP_QUOTED_CLASSNAME "AsyncStatementJSHelper"
michael@0 79 #define XPC_MAP_WANT_GETPROPERTY
michael@0 80 #define XPC_MAP_FLAGS nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
michael@0 81 #include "xpc_map_end.h"
michael@0 82
michael@0 83 NS_IMETHODIMP
michael@0 84 AsyncStatementJSHelper::GetProperty(nsIXPConnectWrappedNative *aWrapper,
michael@0 85 JSContext *aCtx,
michael@0 86 JSObject *aScopeObj,
michael@0 87 jsid aId,
michael@0 88 jsval *_result,
michael@0 89 bool *_retval)
michael@0 90 {
michael@0 91 if (!JSID_IS_STRING(aId))
michael@0 92 return NS_OK;
michael@0 93
michael@0 94 // Cast to async via mozI* since direct from nsISupports is ambiguous.
michael@0 95 JS::RootedObject scope(aCtx, aScopeObj);
michael@0 96 JS::RootedId id(aCtx, aId);
michael@0 97 mozIStorageAsyncStatement *iAsyncStmt =
michael@0 98 static_cast<mozIStorageAsyncStatement *>(aWrapper->Native());
michael@0 99 AsyncStatement *stmt = static_cast<AsyncStatement *>(iAsyncStmt);
michael@0 100
michael@0 101 #ifdef DEBUG
michael@0 102 {
michael@0 103 nsISupports *supp = aWrapper->Native();
michael@0 104 nsCOMPtr<mozIStorageAsyncStatement> isStatement(do_QueryInterface(supp));
michael@0 105 NS_ASSERTION(isStatement, "How is this not an async statement?!");
michael@0 106 }
michael@0 107 #endif
michael@0 108
michael@0 109 if (::JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "params"))
michael@0 110 return getParams(stmt, aCtx, scope, _result);
michael@0 111
michael@0 112 return NS_OK;
michael@0 113 }
michael@0 114
michael@0 115 } // namespace storage
michael@0 116 } // namespace mozilla

mercurial