Bug 1515319 - Allow record<DOMString, object> member in dictionary. r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D14968

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Peter Van der Beken 2018-12-19 19:29:48 +00:00
parent 86f403e126
commit 9ae4291779
5 changed files with 17 additions and 10 deletions

View File

@ -13368,7 +13368,8 @@ class CGDictionary(CGThing):
trace = CGGeneric('JS::UnsafeTraceRoot(trc, %s, "%s");\n' %
("&"+memberData, memberName))
elif (type.isSequence() or type.isDictionary() or
type.isSpiderMonkeyInterface() or type.isUnion()):
type.isSpiderMonkeyInterface() or type.isUnion() or
type.isRecord()):
if type.nullable():
memberNullable = memberData
memberData = "%s.Value()" % memberData
@ -13378,16 +13379,13 @@ class CGDictionary(CGThing):
trace = CGGeneric('%s.TraceDictionary(trc);\n' % memberData)
elif type.isUnion():
trace = CGGeneric('%s.TraceUnion(trc);\n' % memberData)
elif type.isRecord():
trace = CGGeneric('TraceRecord(trc, %s);\n' % memberData)
else:
assert type.isSpiderMonkeyInterface()
trace = CGGeneric('%s.TraceSelf(trc);\n' % memberData)
if type.nullable():
trace = CGIfWrapper(trace, "!%s.IsNull()" % memberNullable)
elif type.isRecord():
# If you implement this, add a record<DOMString, object> to
# TestInterfaceJSDictionary and test it in test_bug1036214.html
# to make sure we end up with the correct security properties.
assert False
else:
assert False # unknown type

View File

@ -39,7 +39,7 @@ TestInterfaceJS.prototype = {
pingPongObjectOrString: function(objectOrString) { return objectOrString; },
pingPongDictionary: function(dict) { return dict; },
pingPongDictionaryOrLong: function(dictOrLong) { return dictOrLong.anyMember || dictOrLong; },
pingPongMap: function(map) { return JSON.stringify(map); },
pingPongRecord: function(rec) { return JSON.stringify(rec); },
objectSequenceLength: function(seq) { return seq.length; },
anySequenceLength: function(seq) { return seq.length; },

View File

@ -43,6 +43,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
var obj2 = { foo: "baz" };
var myDict = { anyMember: 42, objectMember: { answer: 42 }, objectOrStringMember: { answer: "anobject" },
anySequenceMember: [{}, 1, "thirdinsequence"],
objectRecordMember: { key: { answer: "fortytwo" } },
innerDictionary: { innerObject: { answer: "rabbithole" } } };
var t = new TestInterfaceJS(any, obj, myDict);
is(Object.getPrototypeOf(t), TestInterfaceJS.prototype, "Prototype setup works correctly");
@ -50,6 +51,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
is(t.objectArg, obj, "objectArg is correct");
is(t.getDictionaryArg().anyMember, 42, "dictionaryArg looks correct");
is(t.getDictionaryArg().objectMember.answer, 42, "dictionaryArg looks correct");
is(t.getDictionaryArg().objectRecordMember["key"].answer, "fortytwo", "dictionaryArg looks correct");
is(t.getDictionaryArg().objectRecordMember.key.answer, "fortytwo", "dictionaryArg looks correct");
t.anyAttr = 2;
is(t.anyAttr, 2, "ping-pong any attribute works");
t.objAttr = obj2;
@ -57,6 +60,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
t.setDictionaryAttr(myDict);
is(t.getDictionaryAttr().anyMember, 42, "ping-pong dictionary works");
is(t.getDictionaryAttr().objectMember.answer, 42, "ping-pong dictionary works");
is(t.getDictionaryAttr().objectRecordMember["key"].answer, "fortytwo", "ping-pong dictionary works");
is(t.getDictionaryAttr().objectRecordMember.key.answer, "fortytwo", "ping-pong dictionary works");
is(any, t.pingPongAny(any), "ping-pong works with any");
is(obj, t.pingPongObject(obj), "ping-pong works with obj");
@ -66,10 +71,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
is(t.pingPongDictionary(myDict).objectMember.answer, 42, "ping pong works with dict");
is(t.pingPongDictionary(myDict).objectOrStringMember.answer, "anobject", "ping pong works with dict");
is(t.pingPongDictionary(myDict).anySequenceMember[2], "thirdinsequence", "ping pong works with dict");
is(t.pingPongDictionary(myDict).objectRecordMember["key"].answer, "fortytwo", "ping pong works with dict");
is(t.pingPongDictionary(myDict).objectRecordMember.key.answer, "fortytwo", "ping pong works with dict");
is(t.pingPongDictionary(myDict).innerDictionary.innerObject.answer, "rabbithole", "ping pong works with layered dicts");
is(t.pingPongDictionaryOrLong({anyMember: 42}), 42, "ping pong (dict or long) works with dict");
is(t.pingPongDictionaryOrLong(42), 42, "ping pong (dict or long) works with long");
ok(/canary/.test(t.pingPongMap({ someVal: 42, someOtherVal: "canary" })), "ping pong works with record");
ok(/canary/.test(t.pingPongRecord({ someVal: 42, someOtherVal: "canary" })), "ping pong works with record");
is(t.objectSequenceLength([{}, {}, {}]), 3, "ping pong works with object sequence");
is(t.anySequenceLength([42, 'string', {}, undefined]), 4, "ping pong works with any sequence");
@ -97,9 +104,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
checkThrows(() => t.pingPongDictionary({ objectMember: xoObj }), "dictionary pingpong object");
checkThrows(() => t.pingPongDictionary({ anyMember: xoObj, objectMember: xoObj }), "dictionary pingpong both");
checkThrows(() => t.pingPongDictionary({ objectOrStringMember: xoObj }), "dictionary pingpong objectorstring");
checkThrows(() => t.pingPongDictionary({ objectRecordMember: { key: xoObj } }), "dictionary pingpong record of object");
checkThrows(() => t.pingPongDictionaryOrLong({ objectMember: xoObj }), "unionable dictionary");
checkThrows(() => t.pingPongDictionaryOrLong({ anyMember: xoObj }), "unionable dictionary");
checkThrows(() => t.pingPongMap({ someMember: 42, someOtherMember: {}, crossOriginMember: xoObj }), "record");
checkThrows(() => t.pingPongRecord({ someMember: 42, someOtherMember: {}, crossOriginMember: xoObj }), "record");
checkThrows(() => t.objectSequenceLength([{}, {}, xoObj, {}]), "object sequence");
checkThrows(() => t.anySequenceLength([42, 'someString', xoObj, {}]), "any sequence");
});

View File

@ -25,7 +25,7 @@ interface TestInterfaceJS : EventTarget {
any pingPongObjectOrString((object or DOMString) objOrString);
TestInterfaceJSDictionary pingPongDictionary(optional TestInterfaceJSDictionary dict);
long pingPongDictionaryOrLong(optional (TestInterfaceJSUnionableDictionary or long) dictOrLong);
DOMString pingPongMap(record<DOMString, any> map);
DOMString pingPongRecord(record<DOMString, any> rec);
long objectSequenceLength(sequence<object> seq);
long anySequenceLength(sequence<any> seq);

View File

@ -23,5 +23,6 @@ dictionary TestInterfaceJSDictionary {
any anyMember;
(object or DOMString) objectOrStringMember;
sequence<any> anySequenceMember;
record<DOMString, object> objectRecordMember;
};