Skip to content

Instantly share code, notes, and snippets.

@reuben
Created April 23, 2013 23:52
Show Gist options
  • Save reuben/5448458 to your computer and use it in GitHub Desktop.
Save reuben/5448458 to your computer and use it in GitHub Desktop.
dictionary ContactFindSortOptions {
DOMString sortBy;
DOMString sortOrder = "ascending";
};
dictionary ContactFindOptions : ContactFindSortOptions {
DOMString filterValue;
DOMString filterOp;
any filterBy; // e.g. ["givenName", "nickname"]
unsigned long filterLimit;
};
[NoInterfaceObject, NavigatorProperty="mozContacts",
JSImplementation="@mozilla.org/contactManager;1"]
interface ContactManager {
DOMRequest find(optional ContactFindOptions options);
DOMCursor getAll(optional ContactFindSortOptions options);
};
0:46.33 /Users/Reuben/Development/inbound-obj-dbg/dom/bindings/ContactsBinding.cpp:5084:10: error: member function 'ToObject' not viable: 'this' argument has type 'const mozilla::dom::ContactFindOptions', but function is not marked const
0:46.33 if (!options.ToObject(cx, mCallback, &argv[0])) {
0:46.33 ^~~~~~~
0:46.33 /Users/Reuben/Development/inbound-obj-dbg/dom/bindings/ContactsBinding.cpp:255:21: note: 'ToObject' declared here
0:46.33 ContactFindOptions::ToObject(JSContext* cx, JSObject* parentObject, JS::Value *vp)
0:46.33 ^
0:46.33 /Users/Reuben/Development/inbound-obj-dbg/dom/bindings/ContactsBinding.cpp:5139:10: error: member function 'ToObject' not viable: 'this' argument has type 'const mozilla::dom::ContactFindSortOptions', but function is not marked const
0:46.33 if (!options.ToObject(cx, mCallback, &argv[0])) {
0:46.33 ^~~~~~~
0:46.33 /Users/Reuben/Development/inbound-obj-dbg/dom/bindings/ContactsBinding.cpp:105:25: note: 'ToObject' declared here
0:46.33 ContactFindSortOptions::ToObject(JSContext* cx, JSObject* parentObject, JS::Value *vp)
0:46.33 ^
0:46.33 2 errors generated.
already_AddRefed<DOMRequest>
ContactManagerJSImpl::Find(const ContactFindOptions& options, ErrorResult& aRv, ExceptionHandling aExceptionHandling)
{
CallSetup s(mCallback, aRv, aExceptionHandling);
JSContext* cx = s.GetContext();
if (!cx) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JS::Value rval = JSVAL_VOID;
JS::AutoValueVector argv(cx);
if (!argv.resize(1)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
unsigned argc = 1;
do {
if (!options.ToObject(cx, mCallback, &argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
break;
} while (0);
JS::Value callable;
if (!GetCallableProperty(cx, "find", &callable)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
if (!JS_CallFunctionValue(cx, mCallback, callable,
argc, argv.begin(), &rval)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
NonNull<mozilla::dom::DOMRequest> rvalDecl;
if (rval.isObject()) {
{
nsresult rv = UnwrapObject<prototypes::id::DOMRequest, mozilla::dom::DOMRequest>(cx, &rval.toObject(), rvalDecl);
if (NS_FAILED(rv)) {
ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMRequest");
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
} else {
ThrowErrorMessage(cx, MSG_NOT_OBJECT);
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
NS_ADDREF(rvalDecl.Ptr());
return rvalDecl.Ptr();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment