зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1025183
P1 Add ScalarValueString to webidl parser. r=bz
This commit is contained in:
Родитель
286271bc44
Коммит
687ee09c07
|
@ -1379,6 +1379,7 @@ class IDLType(IDLObject):
|
|||
'any',
|
||||
'domstring',
|
||||
'bytestring',
|
||||
'scalarvaluestring',
|
||||
'object',
|
||||
'date',
|
||||
'void',
|
||||
|
@ -1431,6 +1432,9 @@ class IDLType(IDLObject):
|
|||
def isDOMString(self):
|
||||
return False
|
||||
|
||||
def isScalarValueString(self):
|
||||
return False
|
||||
|
||||
def isVoid(self):
|
||||
return self.name == "Void"
|
||||
|
||||
|
@ -1608,6 +1612,9 @@ class IDLNullableType(IDLType):
|
|||
def isDOMString(self):
|
||||
return self.inner.isDOMString()
|
||||
|
||||
def isScalarValueString(self):
|
||||
return self.inner.isScalarValueString()
|
||||
|
||||
def isFloat(self):
|
||||
return self.inner.isFloat()
|
||||
|
||||
|
@ -1729,6 +1736,9 @@ class IDLSequenceType(IDLType):
|
|||
def isDOMString(self):
|
||||
return False
|
||||
|
||||
def isScalarValueString(self):
|
||||
return False
|
||||
|
||||
def isVoid(self):
|
||||
return False
|
||||
|
||||
|
@ -1983,6 +1993,9 @@ class IDLArrayType(IDLType):
|
|||
def isDOMString(self):
|
||||
return False
|
||||
|
||||
def isScalarValueString(self):
|
||||
return False
|
||||
|
||||
def isVoid(self):
|
||||
return False
|
||||
|
||||
|
@ -2078,6 +2091,9 @@ class IDLTypedefType(IDLType, IDLObjectWithIdentifier):
|
|||
def isDOMString(self):
|
||||
return self.inner.isDOMString()
|
||||
|
||||
def isScalarValueString(self):
|
||||
return self.inner.isScalarValueString()
|
||||
|
||||
def isVoid(self):
|
||||
return self.inner.isVoid()
|
||||
|
||||
|
@ -2176,6 +2192,9 @@ class IDLWrapperType(IDLType):
|
|||
def isDOMString(self):
|
||||
return False
|
||||
|
||||
def isScalarValueString(self):
|
||||
return False
|
||||
|
||||
def isVoid(self):
|
||||
return False
|
||||
|
||||
|
@ -2312,6 +2331,7 @@ class IDLBuiltinType(IDLType):
|
|||
'any',
|
||||
'domstring',
|
||||
'bytestring',
|
||||
'scalarvaluestring',
|
||||
'object',
|
||||
'date',
|
||||
'void',
|
||||
|
@ -2346,6 +2366,7 @@ class IDLBuiltinType(IDLType):
|
|||
Types.any: IDLType.Tags.any,
|
||||
Types.domstring: IDLType.Tags.domstring,
|
||||
Types.bytestring: IDLType.Tags.bytestring,
|
||||
Types.scalarvaluestring: IDLType.Tags.scalarvaluestring,
|
||||
Types.object: IDLType.Tags.object,
|
||||
Types.date: IDLType.Tags.date,
|
||||
Types.void: IDLType.Tags.void,
|
||||
|
@ -2378,7 +2399,8 @@ class IDLBuiltinType(IDLType):
|
|||
|
||||
def isString(self):
|
||||
return self._typeTag == IDLBuiltinType.Types.domstring or \
|
||||
self._typeTag == IDLBuiltinType.Types.bytestring
|
||||
self._typeTag == IDLBuiltinType.Types.bytestring or \
|
||||
self._typeTag == IDLBuiltinType.Types.scalarvaluestring
|
||||
|
||||
def isByteString(self):
|
||||
return self._typeTag == IDLBuiltinType.Types.bytestring
|
||||
|
@ -2386,6 +2408,9 @@ class IDLBuiltinType(IDLType):
|
|||
def isDOMString(self):
|
||||
return self._typeTag == IDLBuiltinType.Types.domstring
|
||||
|
||||
def isScalarValueString(self):
|
||||
return self._typeTag == IDLBuiltinType.Types.scalarvaluestring
|
||||
|
||||
def isInteger(self):
|
||||
return self._typeTag <= IDLBuiltinType.Types.unsigned_long_long
|
||||
|
||||
|
@ -2538,6 +2563,9 @@ BuiltinTypes = {
|
|||
IDLBuiltinType.Types.bytestring:
|
||||
IDLBuiltinType(BuiltinLocation("<builtin type>"), "ByteString",
|
||||
IDLBuiltinType.Types.bytestring),
|
||||
IDLBuiltinType.Types.scalarvaluestring:
|
||||
IDLBuiltinType(BuiltinLocation("<builtin type>"), "ScalarValueString",
|
||||
IDLBuiltinType.Types.scalarvaluestring),
|
||||
IDLBuiltinType.Types.object:
|
||||
IDLBuiltinType(BuiltinLocation("<builtin type>"), "Object",
|
||||
IDLBuiltinType.Types.object),
|
||||
|
@ -2672,6 +2700,13 @@ class IDLValue(IDLObject):
|
|||
raise WebIDLError("Trying to convert unrestricted value %s to non-unrestricted"
|
||||
% self.value, [location]);
|
||||
return self
|
||||
elif self.type.isString() and type.isScalarValueString():
|
||||
# Allow ScalarValueStrings to use default value just like
|
||||
# DOMString. No coercion is required in this case as Codegen.py
|
||||
# treats ScalarValueString just like DOMString, but with an
|
||||
# extra normalization step.
|
||||
assert self.type.isDOMString()
|
||||
return self
|
||||
raise WebIDLError("Cannot coerce type %s to type %s." %
|
||||
(self.type, type), [location])
|
||||
|
||||
|
@ -3834,6 +3869,7 @@ class Tokenizer(object):
|
|||
"Date": "DATE",
|
||||
"DOMString": "DOMSTRING",
|
||||
"ByteString": "BYTESTRING",
|
||||
"ScalarValueString": "SCALARVALUESTRING",
|
||||
"any": "ANY",
|
||||
"boolean": "BOOLEAN",
|
||||
"byte": "BYTE",
|
||||
|
@ -4730,6 +4766,7 @@ class Parser(Tokenizer):
|
|||
| DATE
|
||||
| DOMSTRING
|
||||
| BYTESTRING
|
||||
| SCALARVALUESTRING
|
||||
| ANY
|
||||
| ATTRIBUTE
|
||||
| BOOLEAN
|
||||
|
@ -5002,6 +5039,12 @@ class Parser(Tokenizer):
|
|||
"""
|
||||
p[0] = IDLBuiltinType.Types.bytestring
|
||||
|
||||
def p_PrimitiveOrStringTypeScalarValueString(self, p):
|
||||
"""
|
||||
PrimitiveOrStringType : SCALARVALUESTRING
|
||||
"""
|
||||
p[0] = IDLBuiltinType.Types.scalarvaluestring
|
||||
|
||||
def p_UnsignedIntegerTypeUnsigned(self, p):
|
||||
"""
|
||||
UnsignedIntegerType : UNSIGNED IntegerType
|
||||
|
|
|
@ -159,7 +159,8 @@ def WebIDLTest(parser, harness):
|
|||
"object", "Callback", "Callback2", "optional Dict",
|
||||
"optional Dict2", "sequence<long>", "sequence<short>",
|
||||
"MozMap<object>", "MozMap<Dict>", "MozMap<long>",
|
||||
"long[]", "short[]", "Date", "Date?", "any" ]
|
||||
"long[]", "short[]", "Date", "Date?", "any",
|
||||
"ScalarValueString" ]
|
||||
# When we can parse Date and RegExp, we need to add them here.
|
||||
|
||||
# Try to categorize things a bit to keep list lengths down
|
||||
|
@ -170,7 +171,7 @@ def WebIDLTest(parser, harness):
|
|||
primitives = numerics + booleans
|
||||
nonNumerics = allBut(argTypes, numerics)
|
||||
nonBooleans = allBut(argTypes, booleans)
|
||||
strings = [ "DOMString", "ByteString", "Enum", "Enum2" ]
|
||||
strings = [ "DOMString", "ByteString", "Enum", "Enum2", "ScalarValueString" ]
|
||||
nonStrings = allBut(argTypes, strings)
|
||||
nonObjects = primitives + strings
|
||||
objects = allBut(argTypes, nonObjects )
|
||||
|
@ -204,6 +205,7 @@ def WebIDLTest(parser, harness):
|
|||
setDistinguishable("boolean?", allBut(nonBooleans, nullables))
|
||||
setDistinguishable("DOMString", nonStrings)
|
||||
setDistinguishable("ByteString", nonStrings)
|
||||
setDistinguishable("ScalarValueString", nonStrings)
|
||||
setDistinguishable("Enum", nonStrings)
|
||||
setDistinguishable("Enum2", nonStrings)
|
||||
setDistinguishable("Interface", notRelatedInterfaces)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import WebIDL
|
||||
|
||||
def WebIDLTest(parser, harness):
|
||||
parser.parse("""
|
||||
interface TestScalarValueString {
|
||||
attribute ScalarValueString svs;
|
||||
};
|
||||
""")
|
||||
|
||||
results = parser.finish();
|
||||
|
||||
harness.check(len(results), 1, "Should be one production")
|
||||
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
|
||||
"Should be an IDLInterface")
|
||||
iface = results[0]
|
||||
harness.check(iface.identifier.QName(), "::TestScalarValueString",
|
||||
"Interface has the right QName")
|
||||
harness.check(iface.identifier.name, "TestScalarValueString",
|
||||
"Interface has the right name")
|
||||
harness.check(iface.parent, None, "Interface has no parent")
|
||||
|
||||
members = iface.members
|
||||
harness.check(len(members), 1, "Should be one member")
|
||||
|
||||
attr = members[0]
|
||||
harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
|
||||
harness.check(attr.identifier.QName(), "::TestScalarValueString::svs",
|
||||
"Attr has correct QName")
|
||||
harness.check(attr.identifier.name, "svs", "Attr has correct name")
|
||||
harness.check(str(attr.type), "ScalarValueString",
|
||||
"Attr type is the correct name")
|
||||
harness.ok(attr.type.isScalarValueString(), "Should be ScalarValueString type")
|
||||
harness.ok(attr.type.isString(), "Should be String collective type")
|
||||
harness.ok(not attr.type.isDOMString(), "Should be not be DOMString type")
|
|
@ -63,6 +63,7 @@ def WebIDLTest(parser, harness):
|
|||
"octet",
|
||||
"DOMString",
|
||||
"ByteString",
|
||||
"ScalarValueString",
|
||||
#"sequence<float>",
|
||||
"object",
|
||||
"ArrayBuffer",
|
||||
|
|
Загрузка…
Ссылка в новой задаче