Bug 949682 part 1. Add a [Frozen] annotation on WebIDL attributes that have sequence types. r=peterv

This commit is contained in:
Boris Zbarsky 2013-12-16 13:06:35 -05:00
parent b4c8b829b5
commit 45faf1e000
6 changed files with 33 additions and 1 deletions

View File

@ -5134,11 +5134,25 @@ if (!${obj}) {
preserveWrapper = "PreserveWrapper(self);\n"
else:
preserveWrapper = ""
if self.idlNode.getExtendedAttribute("Frozen"):
assert self.idlNode.type.isSequence()
freezeValue = CGGeneric(
"if (!JS_FreezeObject(cx, &args.rval().toObject())) {\n"
" return false;\n"
"}")
if self.idlNode.type.nullable():
freezeValue = CGIfWrapper(freezeValue,
"args.rval().isObject()")
freezeValue = freezeValue.define() + "\n"
else:
freezeValue = ""
successCode = (
"%s"
"js::SetReservedSlot(reflector, %s, args.rval());\n"
"%s"
"break;" %
(memberReservedSlot(self.idlNode), preserveWrapper))
(freezeValue, memberReservedSlot(self.idlNode), preserveWrapper))
else:
successCode = None

View File

@ -2795,6 +2795,10 @@ class IDLAttribute(IDLInterfaceMember):
raise WebIDLError("[LenientThis] is not allowed in combination "
"with [%s]" % identifier,
[attr.location, self.location])
elif identifier == "Frozen":
if not self.type.isSequence():
raise WebIDLError("[Frozen] is only allowed on sequence-valued "
"attributes", [attr.location, self.location])
elif (identifier == "Pref" or
identifier == "SetterThrows" or
identifier == "Pure" or

View File

@ -346,6 +346,8 @@ public:
void GetReadonlySequence(nsTArray<int32_t>&);
void GetReadonlySequenceOfDictionaries(JSContext*, nsTArray<Dict>&);
void GetReadonlyNullableSequenceOfDictionaries(JSContext*, Nullable<nsTArray<Dict> >&);
void GetReadonlyFrozenSequence(JSContext*, nsTArray<Dict>&);
void GetReadonlyFrozenNullableSequence(JSContext*, Nullable<nsTArray<Dict>>&);
void ReceiveSequence(nsTArray<int32_t>&);
void ReceiveNullableSequence(Nullable< nsTArray<int32_t> >&);
void ReceiveSequenceOfNullableInts(nsTArray< Nullable<int32_t> >&);

View File

@ -305,6 +305,10 @@ interface TestInterface {
readonly attribute sequence<Dict> readonlySequenceOfDictionaries;
[Cached, Pure]
readonly attribute sequence<Dict>? readonlyNullableSequenceOfDictionaries;
[Cached, Pure, Frozen]
readonly attribute sequence<Dict> readonlyFrozenSequence;
[Cached, Pure, Frozen]
readonly attribute sequence<Dict>? readonlyFrozenNullableSequence;
sequence<long> receiveSequence();
sequence<long>? receiveNullableSequence();
sequence<long?> receiveSequenceOfNullableInts();

View File

@ -201,6 +201,10 @@ interface TestExampleInterface {
readonly attribute sequence<Dict> readonlySequenceOfDictionaries;
[Cached, Pure]
readonly attribute sequence<Dict>? readonlyNullableSequenceOfDictionaries;
[Cached, Pure, Frozen]
readonly attribute sequence<long> readonlyFrozenSequence;
[Cached, Pure, Frozen]
readonly attribute sequence<long>? readonlyFrozenNullableSequence;
sequence<long> receiveSequence();
sequence<long>? receiveNullableSequence();
sequence<long?> receiveSequenceOfNullableInts();

View File

@ -222,6 +222,10 @@ interface TestJSImplInterface {
readonly attribute sequence<Dict> readonlySequenceOfDictionaries;
[Cached, Pure]
readonly attribute sequence<Dict>? readonlyNullableSequenceOfDictionaries;
[Cached, Pure, Frozen]
readonly attribute sequence<long> readonlyFrozenSequence;
[Cached, Pure, Frozen]
readonly attribute sequence<long>? readonlyFrozenNullableSequence;
sequence<long> receiveSequence();
sequence<long>? receiveNullableSequence();
sequence<long?> receiveSequenceOfNullableInts();