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 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Oracle Corporation code.
18 * The Initial Developer of the Original Code is
20 * Portions created by the Initial Developer are Copyright (C) 2004
21 * the Initial Developer. All Rights Reserved.
24 * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
25 * Shawn Wilsher <me@shawnwilsher.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
45 #include "mozStoragePrivateHelpers.h"
46 #include "mozStorageAsyncStatement.h"
47 #include "mozStorageAsyncStatementParams.h"
48 #include "mozIStorageStatement.h"
53 ////////////////////////////////////////////////////////////////////////////////
54 //// AsyncStatementParams
56 AsyncStatementParams::AsyncStatementParams(AsyncStatement
*aStatement
)
57 : mStatement(aStatement
)
59 NS_ASSERTION(mStatement
!= nsnull
, "mStatement is null");
64 , mozIStorageStatementParams
68 ////////////////////////////////////////////////////////////////////////////////
71 #define XPC_MAP_CLASSNAME AsyncStatementParams
72 #define XPC_MAP_QUOTED_CLASSNAME "AsyncStatementParams"
73 #define XPC_MAP_WANT_SETPROPERTY
74 #define XPC_MAP_WANT_NEWRESOLVE
75 #define XPC_MAP_FLAGS nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
76 #include "xpc_map_end.h"
79 AsyncStatementParams::SetProperty(
80 nsIXPConnectWrappedNative
*aWrapper
,
88 NS_ENSURE_TRUE(mStatement
, NS_ERROR_NOT_INITIALIZED
);
90 if (JSID_IS_INT(aId
)) {
91 int idx
= JSID_TO_INT(aId
);
93 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCtx
, *_vp
));
94 NS_ENSURE_TRUE(variant
, NS_ERROR_UNEXPECTED
);
95 nsresult rv
= mStatement
->BindByIndex(idx
, variant
);
96 NS_ENSURE_SUCCESS(rv
, rv
);
98 else if (JSID_IS_STRING(aId
)) {
99 JSString
*str
= JSID_TO_STRING(aId
);
101 const jschar
*chars
= JS_GetInternedStringCharsAndLength(str
, &length
);
102 NS_ConvertUTF16toUTF8
name(chars
, length
);
104 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCtx
, *_vp
));
105 NS_ENSURE_TRUE(variant
, NS_ERROR_UNEXPECTED
);
106 nsresult rv
= mStatement
->BindByName(name
, variant
);
107 NS_ENSURE_SUCCESS(rv
, rv
);
110 return NS_ERROR_INVALID_ARG
;
118 AsyncStatementParams::NewResolve(
119 nsIXPConnectWrappedNative
*aWrapper
,
128 NS_ENSURE_TRUE(mStatement
, NS_ERROR_NOT_INITIALIZED
);
129 // We do not throw at any point after this because we want to allow the
130 // prototype chain to be checked for the property.
132 bool resolved
= false;
134 if (JSID_IS_INT(aId
)) {
135 PRUint32 idx
= JSID_TO_INT(aId
);
136 // All indexes are good because we don't know how many parameters there
138 ok
= ::JS_DefineElement(aCtx
, aScopeObj
, idx
, JSVAL_VOID
, nsnull
,
142 else if (JSID_IS_STRING(aId
)) {
143 JSString
*str
= JSID_TO_STRING(aId
);
145 const jschar
*nameChars
= ::JS_GetInternedStringCharsAndLength(str
, &nameLength
);
147 // We are unable to tell if there's a parameter with this name and so
148 // we must assume that there is. This screws the rest of the prototype
149 // chain, but people really shouldn't be depending on this anyways.
150 ok
= ::JS_DefineUCProperty(aCtx
, aScopeObj
, nameChars
, nameLength
,
151 JSVAL_VOID
, nsnull
, nsnull
, 0);
156 *_objp
= resolved
&& ok
? aScopeObj
: nsnull
;
160 } // namespace storage
161 } // namespace mozilla