mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1025183
P3 Add ScalarValueString to webidl Codegen.py r=bz
This commit is contained in:
parent
952c4315b6
commit
fe24346780
@ -25,6 +25,7 @@
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsUTF8Utils.h"
|
||||
#include "WrapperFactory.h"
|
||||
#include "xpcprivate.h"
|
||||
#include "XPCQuickStubs.h"
|
||||
@ -2161,6 +2162,36 @@ NonVoidByteStringToJsval(JSContext *cx, const nsACString &str,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename T> static void
|
||||
NormalizeScalarValueStringInternal(JSContext* aCx, T& aString)
|
||||
{
|
||||
char16_t* start = aString.BeginWriting();
|
||||
// Must use const here because we can't pass char** to UTF16CharEnumerator as
|
||||
// it expects const char**. Unclear why this is illegal...
|
||||
const char16_t* nextChar = start;
|
||||
const char16_t* end = aString.Data() + aString.Length();
|
||||
while (nextChar < end) {
|
||||
uint32_t enumerated = UTF16CharEnumerator::NextChar(&nextChar, end);
|
||||
if (enumerated == UCS2_REPLACEMENT_CHAR) {
|
||||
int32_t lastCharIndex = (nextChar - start) - 1;
|
||||
start[lastCharIndex] = static_cast<char16_t>(enumerated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NormalizeScalarValueString(JSContext* aCx, nsAString& aString)
|
||||
{
|
||||
NormalizeScalarValueStringInternal(aCx, aString);
|
||||
}
|
||||
|
||||
void
|
||||
NormalizeScalarValueString(JSContext* aCx, binding_detail::FakeString& aString)
|
||||
{
|
||||
NormalizeScalarValueStringInternal(aCx, aString);
|
||||
}
|
||||
|
||||
bool
|
||||
ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
|
||||
bool nullable, nsACString& result)
|
||||
|
@ -1900,6 +1900,12 @@ ConvertJSValueToString(JSContext* cx, JS::Handle<JS::Value> v,
|
||||
return AssignJSString(cx, result, s);
|
||||
}
|
||||
|
||||
void
|
||||
NormalizeScalarValueString(JSContext* aCx, nsAString& aString);
|
||||
|
||||
void
|
||||
NormalizeScalarValueString(JSContext* aCx, binding_detail::FakeString& aString);
|
||||
|
||||
bool
|
||||
ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
|
||||
bool nullable, nsACString& result);
|
||||
|
@ -4567,7 +4567,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||
declArgs=declArgs,
|
||||
holderArgs=holderArgs)
|
||||
|
||||
if type.isDOMString():
|
||||
if type.isDOMString() or type.isScalarValueString():
|
||||
assert not isEnforceRange and not isClamp
|
||||
|
||||
treatAs = {
|
||||
@ -4585,11 +4585,17 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||
nullBehavior = treatAs[treatNullAs]
|
||||
|
||||
def getConversionCode(varName):
|
||||
normalizeCode = ""
|
||||
if type.isScalarValueString():
|
||||
normalizeCode = "NormalizeScalarValueString(cx, %s);\n" % varName
|
||||
|
||||
conversionCode = (
|
||||
"if (!ConvertJSValueToString(cx, ${val}, %s, %s, %s)) {\n"
|
||||
"%s"
|
||||
"}\n" % (nullBehavior, undefinedBehavior, varName,
|
||||
exceptionCodeIndented.define()))
|
||||
"}\n"
|
||||
"%s" % (nullBehavior, undefinedBehavior, varName,
|
||||
exceptionCodeIndented.define(), normalizeCode))
|
||||
|
||||
if defaultValue is None:
|
||||
return conversionCode
|
||||
|
||||
@ -5504,7 +5510,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
||||
wrappingCode += wrapAndSetPtr(wrap, failed)
|
||||
return (wrappingCode, False)
|
||||
|
||||
if type.isDOMString():
|
||||
if type.isDOMString() or type.isScalarValueString():
|
||||
if type.nullable():
|
||||
return (wrapAndSetPtr("xpc::StringToJsval(cx, %s, ${jsvalHandle})" % result), False)
|
||||
else:
|
||||
@ -5782,7 +5788,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider,
|
||||
if returnType.nullable():
|
||||
result = CGTemplatedType("Nullable", result)
|
||||
return result, None, None, None
|
||||
if returnType.isDOMString():
|
||||
if returnType.isDOMString() or returnType.isScalarValueString():
|
||||
if isMember:
|
||||
return CGGeneric("nsString"), "ref", None, None
|
||||
return CGGeneric("DOMString"), "ref", None, None
|
||||
@ -8172,7 +8178,7 @@ def getUnionAccessorSignatureType(type, descriptorProvider):
|
||||
typeName = CGGeneric(type.name)
|
||||
return CGWrapper(typeName, post=" const &")
|
||||
|
||||
if type.isDOMString():
|
||||
if type.isDOMString() or type.isScalarValueString():
|
||||
return CGGeneric("const nsAString&")
|
||||
|
||||
if type.isByteString():
|
||||
@ -11798,7 +11804,7 @@ class CGNativeMember(ClassMethod):
|
||||
return (result.define(),
|
||||
"%s(%s)" % (result.define(), defaultReturnArg),
|
||||
"return ${declName};\n")
|
||||
if type.isDOMString():
|
||||
if type.isDOMString() or type.isScalarValueString():
|
||||
if isMember:
|
||||
# No need for a third element in the isMember case
|
||||
return "nsString", None, None
|
||||
@ -11918,7 +11924,7 @@ class CGNativeMember(ClassMethod):
|
||||
def getArgs(self, returnType, argList):
|
||||
args = [self.getArg(arg) for arg in argList]
|
||||
# Now the outparams
|
||||
if returnType.isDOMString():
|
||||
if returnType.isDOMString() or returnType.isScalarValueString():
|
||||
args.append(Argument("nsString&", "aRetVal"))
|
||||
elif returnType.isByteString():
|
||||
args.append(Argument("nsCString&", "aRetVal"))
|
||||
@ -12044,7 +12050,7 @@ class CGNativeMember(ClassMethod):
|
||||
|
||||
return type.name, True, True
|
||||
|
||||
if type.isDOMString():
|
||||
if type.isDOMString() or type.isScalarValueString():
|
||||
if isMember:
|
||||
declType = "nsString"
|
||||
else:
|
||||
@ -13847,7 +13853,7 @@ class CGEventGetter(CGNativeMember):
|
||||
memberName = CGDictionary.makeMemberName(self.member.identifier.name)
|
||||
if (type.isPrimitive() and type.tag() in builtinNames) or type.isEnum() or type.isGeckoInterface():
|
||||
return "return " + memberName + ";\n"
|
||||
if type.isDOMString() or type.isByteString():
|
||||
if type.isDOMString() or type.isByteString() or type.isScalarValueString():
|
||||
return "aRetVal = " + memberName + ";\n"
|
||||
if type.isSpiderMonkeyInterface() or type.isObject():
|
||||
return fill(
|
||||
@ -14221,7 +14227,7 @@ class CGEventClass(CGBindingImplClass):
|
||||
nativeType = CGGeneric(type.unroll().inner.identifier.name)
|
||||
if type.nullable():
|
||||
nativeType = CGTemplatedType("Nullable", nativeType)
|
||||
elif type.isDOMString():
|
||||
elif type.isDOMString() or type.isScalarValueString():
|
||||
nativeType = CGGeneric("nsString")
|
||||
elif type.isByteString():
|
||||
nativeType = CGGeneric("nsCString")
|
||||
|
Loading…
Reference in New Issue
Block a user