Bug 1474369 - Part 8: Rename from Sequence to Array in xpidl, r=mccr8

Summary:
This more closely matches the C++ names, and reflects the fact that the
reflected type is not WebIDL's mozilla::dom::Sequence. The reasoning behind this
type difference is for ergonomics, due to xpidl only being exposed to internal
JS code.

Depends On D2335

Reviewers: mccr8!

Tags: #secure-revision

Bug #: 1474369

Differential Revision: https://phabricator.services.mozilla.com/D2337
This commit is contained in:
Nika Layzell 2018-07-24 16:31:09 -04:00
parent 28fd912fa1
commit 72ed07e711
8 changed files with 60 additions and 60 deletions

View File

@ -389,11 +389,11 @@ XPCConvert::NativeData2JS(MutableHandleValue d, const void* s,
return NativeArray2JS(d, *static_cast<const void* const*>(s),
type.ArrayElementType(), iid, arrlen, pErr);
case nsXPTType::T_SEQUENCE:
case nsXPTType::T_ARRAY:
{
auto* sequence = static_cast<const xpt::detail::UntypedSequence*>(s);
return NativeArray2JS(d, sequence->Elements(), type.ArrayElementType(),
iid, sequence->Length(), pErr);
auto* array = static_cast<const xpt::detail::UntypedTArray*>(s);
return NativeArray2JS(d, array->Elements(), type.ArrayElementType(),
iid, array->Length(), pErr);
}
default:
@ -885,9 +885,9 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
return ok;
}
case nsXPTType::T_SEQUENCE:
case nsXPTType::T_ARRAY:
{
auto* dest = (xpt::detail::UntypedSequence*)d;
auto* dest = (xpt::detail::UntypedTArray*)d;
const nsXPTType& elty = type.ArrayElementType();
bool ok = JSArray2Native(s, elty, iid, pErr, [&] (uint32_t* aLength) -> void* {
@ -1598,7 +1598,7 @@ xpc::InnerCleanupValue(const nsXPTType& aType, void* aValue, uint32_t aArrayLen)
free(*(void**)aValue);
break;
// Array Types
// Legacy Array Type
case nsXPTType::T_LEGACY_ARRAY:
{
const nsXPTType& elty = aType.ArrayElementType();
@ -1611,16 +1611,16 @@ xpc::InnerCleanupValue(const nsXPTType& aType, void* aValue, uint32_t aArrayLen)
break;
}
// Sequence Type
case nsXPTType::T_SEQUENCE:
// Array Type
case nsXPTType::T_ARRAY:
{
const nsXPTType& elty = aType.ArrayElementType();
auto* sequence = (xpt::detail::UntypedSequence*)aValue;
auto* array = (xpt::detail::UntypedTArray*)aValue;
for (uint32_t i = 0; i < sequence->Length(); ++i) {
CleanupValue(elty, elty.ElementPtr(sequence->Elements(), i));
for (uint32_t i = 0; i < array->Length(); ++i) {
CleanupValue(elty, elty.ElementPtr(array->Elements(), i));
}
sequence->Clear();
array->Clear();
break;
}
@ -1666,8 +1666,8 @@ xpc::InitializeValue(const nsXPTType& aType, void* aValue)
new (aValue) nsCString();
break;
case nsXPTType::T_SEQUENCE:
new (aValue) xpt::detail::UntypedSequence();
case nsXPTType::T_ARRAY:
new (aValue) xpt::detail::UntypedTArray();
break;
// The remaining types all have valid states where all bytes are '0'.

View File

@ -1680,12 +1680,12 @@ TraceParam(JSTracer* aTrc, void* aVal, const nsXPTType& aType,
if (aType.Tag() == nsXPTType::T_JSVAL) {
JS::UnsafeTraceRoot(aTrc, (JS::Value*)aVal,
"XPCWrappedNative::CallMethod param");
} else if (aType.Tag() == nsXPTType::T_SEQUENCE) {
auto* sequence = (xpt::detail::UntypedSequence*)aVal;
} else if (aType.Tag() == nsXPTType::T_ARRAY) {
auto* array = (xpt::detail::UntypedTArray*)aVal;
const nsXPTType& elty = aType.ArrayElementType();
for (uint32_t i = 0; i < sequence->Length(); ++i) {
TraceParam(aTrc, elty.ElementPtr(sequence->Elements(), i), elty);
for (uint32_t i = 0; i < array->Length(); ++i) {
TraceParam(aTrc, elty.ElementPtr(array->Elements(), i), elty);
}
} else if (aType.Tag() == nsXPTType::T_LEGACY_ARRAY && *(void**)aVal) {
const nsXPTType& elty = aType.ArrayElementType();

View File

@ -39,18 +39,18 @@ interface nsIXPCTestParams : nsISupports {
ACString testACString(in ACString a, inout ACString b);
jsval testJsval(in jsval a, inout jsval b);
// Test various forms of the Sequence<T> type.
Sequence<short> testShortSequence(in Sequence<short> a, inout Sequence<short> b);
Sequence<double> testDoubleSequence(in Sequence<double> a, inout Sequence<double> b);
Sequence<nsIXPCTestInterfaceA> testInterfaceSequence(in Sequence<nsIXPCTestInterfaceA> a, inout Sequence<nsIXPCTestInterfaceA> b);
Sequence<AString> testAStringSequence(in Sequence<AString> a, inout Sequence<AString> b);
Sequence<ACString> testACStringSequence(in Sequence<ACString> a, inout Sequence<ACString> b);
Sequence<jsval> testJsvalSequence(in Sequence<jsval> a, inout Sequence<jsval> b);
Sequence<Sequence<short> > testSequenceSequence(in Sequence<Sequence<short> > a, inout Sequence<Sequence<short> > b);
// Test various forms of the Array<T> type.
Array<short> testShortSequence(in Array<short> a, inout Array<short> b);
Array<double> testDoubleSequence(in Array<double> a, inout Array<double> b);
Array<nsIXPCTestInterfaceA> testInterfaceSequence(in Array<nsIXPCTestInterfaceA> a, inout Array<nsIXPCTestInterfaceA> b);
Array<AString> testAStringSequence(in Array<AString> a, inout Array<AString> b);
Array<ACString> testACStringSequence(in Array<ACString> a, inout Array<ACString> b);
Array<jsval> testJsvalSequence(in Array<jsval> a, inout Array<jsval> b);
Array<Array<short> > testSequenceSequence(in Array<Array<short> > a, inout Array<Array<short> > b);
void testInterfaceIsSequence(in nsIIDPtr aIID, [iid_is(aIID)] in Sequence<nsQIResult> a,
inout nsIIDPtr bIID, [iid_is(bIID)] inout Sequence<nsQIResult> b,
out nsIIDPtr rvIID, [retval, iid_is(rvIID)] out Sequence<nsQIResult> rv);
void testInterfaceIsSequence(in nsIIDPtr aIID, [iid_is(aIID)] in Array<nsQIResult> a,
inout nsIIDPtr bIID, [iid_is(bIID)] inout Array<nsQIResult> b,
out nsIIDPtr rvIID, [retval, iid_is(rvIID)] out Array<nsQIResult> rv);
//
// Dependent parameters use the same types as above, but are handled much differently.

View File

@ -62,11 +62,11 @@ def get_type(type, calltype, iid_is=None, size_is=None):
ret['size_is'] = size_is
return ret
if isinstance(type, xpidl.Sequence):
# NB: For a Sequence<T> we pass down the iid_is to get the type of T.
if isinstance(type, xpidl.Array):
# NB: For a Array<T> we pass down the iid_is to get the type of T.
# This allows Arrays of InterfaceIs types to work.
return {
'tag': 'TD_SEQUENCE',
'tag': 'TD_ARRAY',
'element': get_type(type.type, calltype, iid_is),
}

View File

@ -133,7 +133,7 @@ class Builtin(object):
def nativeType(self, calltype, shared=False, const=False):
if self.name in ["string", "wstring"] and calltype == 'element':
raise IDLError("Use string class types for string Sequence elements", self.location)
raise IDLError("Use string class types for string Array elements", self.location)
if const:
print >>sys.stderr, IDLError(
@ -333,11 +333,11 @@ class IDL(object):
self.namemap.set(object)
def getName(self, id, location):
if id.name == 'Sequence':
if id.name == 'Array':
if id.params is None or len(id.params) != 1:
raise IDLError("Sequence takes exactly 1 parameter", location)
raise IDLError("Array takes exactly 1 parameter", location)
self.hasSequence = True
return Sequence(self.getName(id.params[0], location), location)
return Array(self.getName(id.params[0], location), location)
if id.params is not None:
raise IDLError("Generic type '%s' unrecognized" % id.name, location)
@ -559,17 +559,17 @@ class Native(object):
if calltype == 'element':
if self.isRef(calltype):
raise IDLError("[ref] qualified type unsupported in Sequence<T>", self.location)
raise IDLError("[ref] qualified type unsupported in Array<T>", self.location)
# Promises should be held in RefPtr<T> in Sequence<T>s
# Promises should be held in RefPtr<T> in Array<T>s
if self.specialtype == 'promise':
return 'RefPtr<mozilla::dom::Promise>'
# We don't support nsIDPtr, in Sequence<T> currently, although
# this or support for Sequence<nsID> will be needed to replace
# We don't support nsIDPtr, in Array<T> currently, although
# this or support for Array<nsID> will be needed to replace
# [array] completely.
if self.specialtype == 'nsid':
raise IDLError("Sequence<nsIDPtr> not yet supported. "
raise IDLError("Array<nsIDPtr> not yet supported. "
"File an XPConnect bug if you need it.", self.location)
if self.isRef(calltype):
@ -1278,8 +1278,8 @@ class LegacyArray(object):
self.type.rustType('legacyelement'))
class Sequence(object):
kind = 'sequence'
class Array(object):
kind = 'array'
def __init__(self, type, location):
self.type = type
@ -1287,7 +1287,7 @@ class Sequence(object):
@property
def name(self):
return "Sequence<%s>" % self.type.name
return "Array<%s>" % self.type.name
def resolve(self, idl):
idl.getName(self.type, self.location)
@ -1297,7 +1297,7 @@ class Sequence(object):
def nativeType(self, calltype):
if calltype == 'legacyelement':
raise IDLError("[array] Sequence<T> is unsupported", self.location)
raise IDLError("[array] Array<T> is unsupported", self.location)
base = 'nsTArray<%s>' % self.type.nativeType('element')
if 'out' in calltype:
@ -1310,7 +1310,7 @@ class Sequence(object):
def rustType(self, calltype):
# NOTE: To add Rust support, ensure 'element' is handled correctly in
# all rustType callees.
raise RustNoncompat("Sequence<...> types")
raise RustNoncompat("Array<...> types")
TypeId = namedtuple('TypeId', 'name params')

View File

@ -58,7 +58,7 @@ struct nsXPTCVariant
nsCString nscstr;
nsString nsstr;
JS::Value jsval;
xpt::detail::UntypedSequence sequence;
xpt::detail::UntypedTArray array;
// This type contains non-standard-layout types, so needs an explicit
// Ctor/Dtor - we'll just delete them.

View File

@ -265,7 +265,7 @@ def link_to_cpp(interfaces, fd):
def describe_type(type): # Create the type's documentation comment.
tag = type['tag'][3:].lower()
if tag == 'array':
if tag == 'legacy_array':
return '%s[size_is=%d]' % (
describe_type(type['element']), type['size_is'])
elif tag == 'interface_type' or tag == 'domobject':
@ -284,8 +284,8 @@ def link_to_cpp(interfaces, fd):
d1 = type['size_is']
d2 = lower_extra_type(type['element'])
elif tag == 'TD_SEQUENCE':
# NOTE: TD_SEQUENCE can hold 16 bits of type index, while
elif tag == 'TD_ARRAY':
# NOTE: TD_ARRAY can hold 16 bits of type index, while
# TD_LEGACY_ARRAY can only hold 8.
d1, d2 = splitint(lower_extra_type(type['element']))

View File

@ -204,8 +204,8 @@ enum nsXPTTypeTag : uint8_t
TD_CSTRING = 26,
TD_ASTRING = 27,
TD_JSVAL = 28,
TD_SEQUENCE = 29,
_TD_LAST_COMPLEX = TD_SEQUENCE
TD_ARRAY = 29,
_TD_LAST_COMPLEX = TD_ARRAY
};
static_assert(_TD_LAST_COMPLEX < 32, "nsXPTTypeTag must fit in 5 bits");
@ -244,7 +244,7 @@ public:
if (Tag() == TD_LEGACY_ARRAY) {
return xpt::detail::GetType(mData2);
}
MOZ_ASSERT(Tag() == TD_SEQUENCE);
MOZ_ASSERT(Tag() == TD_ARRAY);
return xpt::detail::GetType(Data16());
}
@ -272,14 +272,14 @@ public:
}
bool IsDependent() const {
return (Tag() == TD_SEQUENCE && InnermostType().IsDependent()) ||
return (Tag() == TD_ARRAY && InnermostType().IsDependent()) ||
Tag() == TD_INTERFACE_IS_TYPE || Tag() == TD_LEGACY_ARRAY ||
Tag() == TD_PSTRING_SIZE_IS || Tag() == TD_PWSTRING_SIZE_IS;
}
// Unwrap a nested type to its innermost value (e.g. through arrays).
const nsXPTType& InnermostType() const {
if (Tag() == TD_LEGACY_ARRAY || Tag() == TD_SEQUENCE) {
if (Tag() == TD_LEGACY_ARRAY || Tag() == TD_ARRAY) {
return ArrayElementType().InnermostType();
}
return *this;
@ -368,7 +368,7 @@ public:
TD_ALIAS_(T_JSVAL , TD_JSVAL );
TD_ALIAS_(T_DOMOBJECT , TD_DOMOBJECT );
TD_ALIAS_(T_PROMISE , TD_PROMISE );
TD_ALIAS_(T_SEQUENCE , TD_SEQUENCE );
TD_ALIAS_(T_ARRAY , TD_ARRAY );
#undef TD_ALIAS_
////////////////////////////////////////////////////////////////
@ -531,9 +531,9 @@ struct nsXPTDOMObjectInfo
namespace xpt {
namespace detail {
// The UntypedSequence type allows low-level access from XPConnect to nsTArray
// The UntypedTArray type allows low-level access from XPConnect to nsTArray
// internals without static knowledge of the array element type in question.
class UntypedSequence
class UntypedTArray
: public nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>
{
public:
@ -686,7 +686,7 @@ nsXPTType::Stride() const
case TD_CSTRING: return sizeof(nsCString);
case TD_ASTRING: return sizeof(nsString);
case TD_JSVAL: return sizeof(JS::Value);
case TD_SEQUENCE: return sizeof(xpt::detail::UntypedSequence);
case TD_ARRAY: return sizeof(xpt::detail::UntypedTArray);
}
MOZ_CRASH("Unknown type");