2010-03-24 10:32:40 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-24 10:32:40 +03:00
|
|
|
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2014-07-12 11:43:08 +04:00
|
|
|
#include "nsJSUtils.h"
|
2010-03-24 10:32:40 +03:00
|
|
|
|
2013-08-18 02:50:18 +04:00
|
|
|
#include "jsapi.h"
|
|
|
|
|
2010-03-24 10:32:40 +03:00
|
|
|
#include "mozStoragePrivateHelpers.h"
|
|
|
|
#include "mozStorageAsyncStatement.h"
|
|
|
|
#include "mozStorageAsyncStatementParams.h"
|
|
|
|
#include "mozIStorageStatement.h"
|
|
|
|
|
2016-12-14 00:33:46 +03:00
|
|
|
#include "xpc_make_class.h"
|
|
|
|
|
2010-03-24 10:32:40 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace storage {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// AsyncStatementParams
|
|
|
|
|
|
|
|
AsyncStatementParams::AsyncStatementParams(AsyncStatement *aStatement)
|
|
|
|
: mStatement(aStatement)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(mStatement != nullptr, "mStatement is null");
|
2010-03-24 10:32:40 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(
|
2010-03-24 10:32:40 +03:00
|
|
|
AsyncStatementParams
|
|
|
|
, mozIStorageStatementParams
|
|
|
|
, nsIXPCScriptable
|
|
|
|
)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIXPCScriptable
|
|
|
|
|
2017-01-23 05:33:58 +03:00
|
|
|
#define XPC_MAP_CLASSNAME AsyncStatementParams
|
2010-03-24 10:32:40 +03:00
|
|
|
#define XPC_MAP_QUOTED_CLASSNAME "AsyncStatementParams"
|
2017-01-23 05:33:58 +03:00
|
|
|
#define XPC_MAP_FLAGS (XPC_SCRIPTABLE_WANT_SETPROPERTY | \
|
|
|
|
XPC_SCRIPTABLE_WANT_RESOLVE | \
|
|
|
|
XPC_SCRIPTABLE_ALLOW_PROP_MODS_DURING_RESOLVE)
|
2010-03-24 10:32:40 +03:00
|
|
|
#include "xpc_map_end.h"
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AsyncStatementParams::SetProperty(
|
|
|
|
nsIXPConnectWrappedNative *aWrapper,
|
|
|
|
JSContext *aCtx,
|
|
|
|
JSObject *aScopeObj,
|
2010-07-15 10:19:36 +04:00
|
|
|
jsid aId,
|
2013-08-18 02:50:18 +04:00
|
|
|
JS::Value *_vp,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval
|
2010-03-24 10:32:40 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mStatement, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2010-07-15 10:19:36 +04:00
|
|
|
if (JSID_IS_INT(aId)) {
|
|
|
|
int idx = JSID_TO_INT(aId);
|
2010-03-24 10:32:40 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCtx, *_vp));
|
|
|
|
NS_ENSURE_TRUE(variant, NS_ERROR_UNEXPECTED);
|
|
|
|
nsresult rv = mStatement->BindByIndex(idx, variant);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-07-15 10:19:36 +04:00
|
|
|
else if (JSID_IS_STRING(aId)) {
|
|
|
|
JSString *str = JSID_TO_STRING(aId);
|
2014-07-12 11:43:08 +04:00
|
|
|
nsAutoJSString autoStr;
|
|
|
|
if (!autoStr.init(aCtx, str)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 name(autoStr);
|
2010-03-24 10:32:40 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCtx, *_vp));
|
|
|
|
NS_ENSURE_TRUE(variant, NS_ERROR_UNEXPECTED);
|
|
|
|
nsresult rv = mStatement->BindByName(name, variant);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = true;
|
2010-03-24 10:32:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-08 03:07:12 +03:00
|
|
|
AsyncStatementParams::Resolve(nsIXPConnectWrappedNative *aWrapper,
|
|
|
|
JSContext *aCtx,
|
|
|
|
JSObject *aScopeObj,
|
|
|
|
jsid aId,
|
|
|
|
bool *aResolvedp,
|
|
|
|
bool *_retval)
|
2010-03-24 10:32:40 +03:00
|
|
|
{
|
2013-12-21 03:58:36 +04:00
|
|
|
JS::Rooted<JSObject*> scopeObj(aCtx, aScopeObj);
|
|
|
|
|
2010-03-24 10:32:40 +03:00
|
|
|
NS_ENSURE_TRUE(mStatement, NS_ERROR_NOT_INITIALIZED);
|
2010-05-06 22:56:39 +04:00
|
|
|
// We do not throw at any point after this because we want to allow the
|
|
|
|
// prototype chain to be checked for the property.
|
2010-03-24 10:32:40 +03:00
|
|
|
|
2010-05-06 22:56:39 +04:00
|
|
|
bool resolved = false;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ok = true;
|
2010-07-15 10:19:36 +04:00
|
|
|
if (JSID_IS_INT(aId)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t idx = JSID_TO_INT(aId);
|
2010-03-24 10:32:40 +03:00
|
|
|
// All indexes are good because we don't know how many parameters there
|
|
|
|
// really are.
|
2015-05-01 22:03:17 +03:00
|
|
|
ok = ::JS_DefineElement(aCtx, scopeObj, idx, JS::UndefinedHandleValue,
|
|
|
|
JSPROP_RESOLVING);
|
2010-05-06 22:56:39 +04:00
|
|
|
resolved = true;
|
2010-03-24 10:32:40 +03:00
|
|
|
}
|
2010-07-15 10:19:36 +04:00
|
|
|
else if (JSID_IS_STRING(aId)) {
|
2010-03-24 10:32:40 +03:00
|
|
|
// We are unable to tell if there's a parameter with this name and so
|
|
|
|
// we must assume that there is. This screws the rest of the prototype
|
|
|
|
// chain, but people really shouldn't be depending on this anyways.
|
2014-04-30 13:10:33 +04:00
|
|
|
JS::Rooted<jsid> id(aCtx, aId);
|
2015-05-01 22:03:17 +03:00
|
|
|
ok = ::JS_DefinePropertyById(aCtx, scopeObj, id, JS::UndefinedHandleValue,
|
|
|
|
JSPROP_RESOLVING);
|
2010-05-06 22:56:39 +04:00
|
|
|
resolved = true;
|
2010-03-24 10:32:40 +03:00
|
|
|
}
|
|
|
|
|
2010-05-06 22:56:39 +04:00
|
|
|
*_retval = ok;
|
2014-11-08 03:07:12 +03:00
|
|
|
*aResolvedp = resolved && ok;
|
2010-03-24 10:32:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace storage
|
|
|
|
} // namespace mozilla
|