Bug 843261. Add support for sequence<DOMString> arguments in WebIDL callbacks. r=peterv

This does allow people to accidentally hit the slower path through use
of non-const strings, but I think that's OK now that we're mostly
autogenerating this stuff
This commit is contained in:
Boris Zbarsky 2013-02-28 12:56:41 -05:00
parent 69e916da61
commit 3988338337
3 changed files with 26 additions and 18 deletions

View File

@ -5179,24 +5179,16 @@ ${doConversionsToJS}
(templateVars, type) = arg
assert not type.nullable() # flatMemberTypes never has nullable types
val = "mValue.m%(name)s.Value()" % templateVars
if type.isString():
# XPConnect string-to-JS conversion wants to mutate the string. So
# let's give it a string it can mutate
# XXXbz if we try to do a sequence of strings, this will kinda fail.
prepend = "nsString mutableStr(%s);\n" % val
val = "mutableStr"
else:
prepend = ""
if type.isObject():
# We'll have a NonNull<JSObject> while the wrapping code
# wants a JSObject*
val = "%s.get()" % val
elif type.isSpiderMonkeyInterface():
# We have a NonNull<TypedArray> object while the wrapping code
# wants a JSObject*. Cheat with .get() so we don't have to
# figure out the right reference type to cast to.
val = "%s.get()->Obj()" % val
wrapCode = prepend + wrapForType(
if type.isObject():
# We'll have a NonNull<JSObject> while the wrapping code
# wants a JSObject*
val = "%s.get()" % val
elif type.isSpiderMonkeyInterface():
# We have a NonNull<TypedArray> object while the wrapping code
# wants a JSObject*. Cheat with .get() so we don't have to
# figure out the right reference type to cast to.
val = "%s.get()->Obj()" % val
wrapCode = wrapForType(
type, self.descriptorProvider,
{
"jsvalRef": "*vp",

View File

@ -18,6 +18,8 @@ callback interface TestCallbackInterface {
attribute DOMString bar;
void doSomething();
long doSomethingElse(DOMString arg, TestInterface otherArg);
void doSequenceLongArg(sequence<long> arg);
void doSequenceStringArg(sequence<DOMString> arg);
};
callback interface TestSingleOperationCallbackInterface {

View File

@ -291,6 +291,20 @@ inline bool StringToJsval(JSContext *cx, nsAString &str, JS::Value *rval)
return NonVoidStringToJsval(cx, str, rval);
}
inline bool
NonVoidStringToJsval(JSContext* cx, const nsAString& str, JS::Value *rval)
{
nsString mutableCopy(str);
return NonVoidStringToJsval(cx, mutableCopy, rval);
}
inline bool
StringToJsval(JSContext* cx, const nsAString& str, JS::Value *rval)
{
nsString mutableCopy(str);
return StringToJsval(cx, mutableCopy, rval);
}
/**
* As above, but for mozilla::dom::DOMString.
*/