summaryrefslogtreecommitdiffstats
path: root/dom/bindings
diff options
context:
space:
mode:
authorJustOff <Off.Just.Off@gmail.com>2019-03-13 20:17:36 +0200
committerJustOff <Off.Just.Off@gmail.com>2019-03-13 20:17:36 +0200
commite7c9fa3e1505aeb90385e0a4e90fe5e0b137d4ab (patch)
tree62f23530cf7a928849c736a19250f5c4ddc3575d /dom/bindings
parent66ee6fdde46bb9c246f7912fcc38d0883f66f961 (diff)
downloadUXP-e7c9fa3e1505aeb90385e0a4e90fe5e0b137d4ab.tar
UXP-e7c9fa3e1505aeb90385e0a4e90fe5e0b137d4ab.tar.gz
UXP-e7c9fa3e1505aeb90385e0a4e90fe5e0b137d4ab.tar.lz
UXP-e7c9fa3e1505aeb90385e0a4e90fe5e0b137d4ab.tar.xz
UXP-e7c9fa3e1505aeb90385e0a4e90fe5e0b137d4ab.zip
Actually change the key type of a record, and its corresponding conversion behavior, depending on what the IDL says
Diffstat (limited to 'dom/bindings')
-rw-r--r--dom/bindings/Codegen.py48
-rw-r--r--dom/bindings/Record.h2
2 files changed, 40 insertions, 10 deletions
diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py
index 915d7d431..4e6248e49 100644
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -4372,11 +4372,15 @@ def handleDefaultStringValue(defaultValue, method):
}
-def recordKeyDeclType(recordType):
+def recordKeyType(recordType):
assert recordType.keyType.isString()
if recordType.keyType.isByteString():
- return CGGeneric("nsCString")
- return CGGeneric("nsString")
+ return "nsCString"
+ return "nsString"
+
+
+def recordKeyDeclType(recordType):
+ return CGGeneric(recordKeyType(recordType))
# If this function is modified, modify CGNativeMember.getArg and
@@ -4786,6 +4790,15 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
"passedToJSImpl": "${passedToJSImpl}"
})
+ keyType = recordKeyType(recordType)
+ if recordType.keyType.isDOMString():
+ keyConversionFunction = "ConvertJSValueToString"
+ elif recordType.keyType.isUSVString():
+ keyConversionFunction = "ConvertJSValueToUSVString"
+ else:
+ assert recordType.keyType.isByteString()
+ keyConversionFunction = "ConvertJSValueToByteString"
+
templateBody = fill(
"""
auto& recordEntries = ${recordRef}.Entries();
@@ -4805,6 +4818,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
JS::Rooted<JS::Value> propNameValue(cx);
JS::Rooted<JS::Value> temp(cx);
JS::Rooted<jsid> curId(cx);
+ JS::Rooted<JS::Value> idVal(cx);
for (size_t i = 0; i < ids.length(); ++i) {
curId = ids[i];
@@ -4821,12 +4835,11 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
continue;
}
- binding_detail::FakeString propName;
- bool isSymbol;
- if (!ConvertIdToString(cx, curId, propName, isSymbol)) {
+ idVal = js::IdToValue(curId);
+ ${keyType} propName;
+ if (!${keyConversionFunction}(cx, idVal, propName)) {
$*{exceptionCode}
}
- MOZ_ASSERT(!isSymbol, "We said, no symbols!");
if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
$*{exceptionCode}
@@ -4842,6 +4855,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
""",
exceptionCode=exceptionCode,
recordRef=recordRef,
+ keyType=keyType,
+ keyConversionFunction=keyConversionFunction,
typeName=typeName,
valueType=valueInfo.declType.define(),
valueConversion=valueConversion)
@@ -6491,6 +6506,18 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
'typedArraysAreStructs': typedArraysAreStructs
})
recordWrapLevel -= 1
+ if type.keyType.isByteString():
+ # There is no length-taking JS_DefineProperty. So to keep
+ # things sane with embedded nulls, we want to byte-inflate
+ # to an nsAString. The only byte-inflation function we
+ # have around is AppendASCIItoUTF16, which luckily doesn't
+ # assert anything about the input being ASCII.
+ expandedKeyDecl = "NS_ConvertASCIItoUTF16 expandedKey(entry.mKey);\n"
+ keyName = "expandedKey"
+ else:
+ expandedKeyDecl = ""
+ keyName = "entry.mKey"
+
code = fill(
"""
@@ -6508,9 +6535,10 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
do {
$*{innerTemplate}
} while (0);
+ $*{expandedKeyDecl}
if (!JS_DefineUCProperty(cx, returnObj,
- entry.mKey.BeginReading(),
- entry.mKey.Length(), tmp,
+ ${keyName}.BeginReading(),
+ ${keyName}.Length(), tmp,
JSPROP_ENUMERATE)) {
$*{exceptionCode}
}
@@ -6522,6 +6550,8 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
exceptionCode=exceptionCode,
valueName=valueName,
innerTemplate=innerTemplate,
+ expandedKeyDecl=expandedKeyDecl,
+ keyName=keyName,
set=setObject("*returnObj"))
return (code, False)
diff --git a/dom/bindings/Record.h b/dom/bindings/Record.h
index 2fe18be2b..b7f7b01b0 100644
--- a/dom/bindings/Record.h
+++ b/dom/bindings/Record.h
@@ -47,7 +47,7 @@ template<typename KeyType, typename ValueType>
class Record
{
public:
- typedef typename binding_detail::RecordEntry<nsString, ValueType> EntryType;
+ typedef typename binding_detail::RecordEntry<KeyType, ValueType> EntryType;
typedef Record<KeyType, ValueType> SelfType;
Record()