mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
auto merge of #4882 : chmanchester/servo/stringifiers, r=Ms2ger
This commit is contained in:
commit
172db80703
6 changed files with 69 additions and 52 deletions
|
@ -68,6 +68,13 @@ def stripTrailingWhitespace(text):
|
||||||
return '\n'.join(lines) + tail
|
return '\n'.join(lines) + tail
|
||||||
|
|
||||||
def MakeNativeName(name):
|
def MakeNativeName(name):
|
||||||
|
# The gecko counterpart to this file uses the BinaryName machinery
|
||||||
|
# for this purpose (#4435 is the servo issue for BinaryName).
|
||||||
|
replacements = {
|
||||||
|
"__stringifier": "Stringify",
|
||||||
|
}
|
||||||
|
if name in replacements:
|
||||||
|
return replacements[name]
|
||||||
return name[0].upper() + name[1:]
|
return name[0].upper() + name[1:]
|
||||||
|
|
||||||
builtinNames = {
|
builtinNames = {
|
||||||
|
@ -1218,13 +1225,25 @@ class MethodDefiner(PropertyDefiner):
|
||||||
"length": 0,
|
"length": 0,
|
||||||
"flags": "JSPROP_ENUMERATE" })
|
"flags": "JSPROP_ENUMERATE" })
|
||||||
|
|
||||||
|
if not static:
|
||||||
|
stringifier = descriptor.operations['Stringifier']
|
||||||
|
if stringifier:
|
||||||
|
self.regular.append({
|
||||||
|
"name": "toString",
|
||||||
|
"nativeName": stringifier.identifier.name,
|
||||||
|
"length": 0,
|
||||||
|
"flags": "JSPROP_ENUMERATE"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def generateArray(self, array, name):
|
def generateArray(self, array, name):
|
||||||
if len(array) == 0:
|
if len(array) == 0:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def specData(m):
|
def specData(m):
|
||||||
if m.get("methodInfo", True):
|
if m.get("methodInfo", True):
|
||||||
jitinfo = ("&%s_methodinfo" % m["name"])
|
identifier = m.get("nativeName", m["name"])
|
||||||
|
jitinfo = "&%s_methodinfo" % identifier
|
||||||
accessor = "genericMethod as NonNullJSNative"
|
accessor = "genericMethod as NonNullJSNative"
|
||||||
else:
|
else:
|
||||||
jitinfo = "0 as *const JSJitInfo"
|
jitinfo = "0 as *const JSJitInfo"
|
||||||
|
@ -4100,8 +4119,8 @@ class CGInterfaceTrait(CGThing):
|
||||||
|
|
||||||
def members():
|
def members():
|
||||||
for m in descriptor.interface.members:
|
for m in descriptor.interface.members:
|
||||||
if m.isMethod() and not m.isStatic() \
|
if (m.isMethod() and not m.isStatic() and
|
||||||
and not m.isIdentifierLess():
|
(not m.isIdentifierLess() or m.isStringifier())):
|
||||||
name = CGSpecializedMethod.makeNativeName(descriptor, m)
|
name = CGSpecializedMethod.makeNativeName(descriptor, m)
|
||||||
infallible = 'infallible' in descriptor.getExtendedAttributes(m)
|
infallible = 'infallible' in descriptor.getExtendedAttributes(m)
|
||||||
for idx, (rettype, arguments) in enumerate(m.signatures()):
|
for idx, (rettype, arguments) in enumerate(m.signatures()):
|
||||||
|
@ -4169,7 +4188,8 @@ class CGDescriptor(CGThing):
|
||||||
(hasMethod, hasGetter, hasLenientGetter,
|
(hasMethod, hasGetter, hasLenientGetter,
|
||||||
hasSetter, hasLenientSetter) = False, False, False, False, False
|
hasSetter, hasLenientSetter) = False, False, False, False, False
|
||||||
for m in descriptor.interface.members:
|
for m in descriptor.interface.members:
|
||||||
if m.isMethod() and not m.isIdentifierLess():
|
if (m.isMethod() and
|
||||||
|
(not m.isIdentifierLess() or m == descriptor.operations["Stringifier"])):
|
||||||
if m.isStatic():
|
if m.isStatic():
|
||||||
assert descriptor.interface.hasInterfaceObject()
|
assert descriptor.interface.hasInterfaceObject()
|
||||||
cgThings.append(CGStaticMethod(descriptor, m))
|
cgThings.append(CGStaticMethod(descriptor, m))
|
||||||
|
@ -4178,6 +4198,11 @@ class CGDescriptor(CGThing):
|
||||||
cgThings.append(CGMemberJITInfo(descriptor, m))
|
cgThings.append(CGMemberJITInfo(descriptor, m))
|
||||||
hasMethod = True
|
hasMethod = True
|
||||||
elif m.isAttr():
|
elif m.isAttr():
|
||||||
|
if m.stringifier:
|
||||||
|
raise TypeError("Stringifier attributes not supported yet. "
|
||||||
|
"See bug 824857.\n"
|
||||||
|
"%s" % m.location)
|
||||||
|
|
||||||
if m.isStatic():
|
if m.isStatic():
|
||||||
assert descriptor.interface.hasInterfaceObject()
|
assert descriptor.interface.hasInterfaceObject()
|
||||||
cgThings.append(CGStaticGetter(descriptor, m))
|
cgThings.append(CGStaticGetter(descriptor, m))
|
||||||
|
|
|
@ -166,28 +166,37 @@ class Descriptor(DescriptorProvider):
|
||||||
# If we're concrete, we need to crawl our ancestor interfaces and mark
|
# If we're concrete, we need to crawl our ancestor interfaces and mark
|
||||||
# them as having a concrete descendant.
|
# them as having a concrete descendant.
|
||||||
self.concrete = desc.get('concrete', True)
|
self.concrete = desc.get('concrete', True)
|
||||||
|
|
||||||
|
self.operations = {
|
||||||
|
'IndexedGetter': None,
|
||||||
|
'IndexedSetter': None,
|
||||||
|
'IndexedCreator': None,
|
||||||
|
'IndexedDeleter': None,
|
||||||
|
'NamedGetter': None,
|
||||||
|
'NamedSetter': None,
|
||||||
|
'NamedCreator': None,
|
||||||
|
'NamedDeleter': None,
|
||||||
|
'Stringifier': None,
|
||||||
|
}
|
||||||
|
|
||||||
|
def addOperation(operation, m):
|
||||||
|
if not self.operations[operation]:
|
||||||
|
self.operations[operation] = m
|
||||||
|
|
||||||
|
# Since stringifiers go on the prototype, we only need to worry
|
||||||
|
# about our own stringifier, not those of our ancestor interfaces.
|
||||||
|
for m in self.interface.members:
|
||||||
|
if m.isMethod() and m.isStringifier():
|
||||||
|
addOperation('Stringifier', m)
|
||||||
|
|
||||||
if self.concrete:
|
if self.concrete:
|
||||||
self.proxy = False
|
self.proxy = False
|
||||||
operations = {
|
|
||||||
'IndexedGetter': None,
|
|
||||||
'IndexedSetter': None,
|
|
||||||
'IndexedCreator': None,
|
|
||||||
'IndexedDeleter': None,
|
|
||||||
'NamedGetter': None,
|
|
||||||
'NamedSetter': None,
|
|
||||||
'NamedCreator': None,
|
|
||||||
'NamedDeleter': None,
|
|
||||||
'Stringifier': None
|
|
||||||
}
|
|
||||||
iface = self.interface
|
iface = self.interface
|
||||||
while iface:
|
while iface:
|
||||||
for m in iface.members:
|
for m in iface.members:
|
||||||
if not m.isMethod():
|
if not m.isMethod():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def addOperation(operation, m):
|
|
||||||
if not operations[operation]:
|
|
||||||
operations[operation] = m
|
|
||||||
def addIndexedOrNamedOperation(operation, m):
|
def addIndexedOrNamedOperation(operation, m):
|
||||||
self.proxy = True
|
self.proxy = True
|
||||||
if m.isIndexed():
|
if m.isIndexed():
|
||||||
|
@ -197,23 +206,19 @@ class Descriptor(DescriptorProvider):
|
||||||
operation = 'Named' + operation
|
operation = 'Named' + operation
|
||||||
addOperation(operation, m)
|
addOperation(operation, m)
|
||||||
|
|
||||||
if m.isStringifier():
|
if m.isGetter():
|
||||||
addOperation('Stringifier', m)
|
addIndexedOrNamedOperation('Getter', m)
|
||||||
else:
|
if m.isSetter():
|
||||||
if m.isGetter():
|
addIndexedOrNamedOperation('Setter', m)
|
||||||
addIndexedOrNamedOperation('Getter', m)
|
if m.isCreator():
|
||||||
if m.isSetter():
|
addIndexedOrNamedOperation('Creator', m)
|
||||||
addIndexedOrNamedOperation('Setter', m)
|
if m.isDeleter():
|
||||||
if m.isCreator():
|
addIndexedOrNamedOperation('Deleter', m)
|
||||||
addIndexedOrNamedOperation('Creator', m)
|
|
||||||
if m.isDeleter():
|
|
||||||
addIndexedOrNamedOperation('Deleter', m)
|
|
||||||
|
|
||||||
iface.setUserData('hasConcreteDescendant', True)
|
iface.setUserData('hasConcreteDescendant', True)
|
||||||
iface = iface.parent
|
iface = iface.parent
|
||||||
|
|
||||||
if self.proxy:
|
if self.proxy:
|
||||||
self.operations = operations
|
|
||||||
iface = self.interface
|
iface = self.interface
|
||||||
while iface:
|
while iface:
|
||||||
iface.setUserData('hasProxyDescendant', True)
|
iface.setUserData('hasProxyDescendant', True)
|
||||||
|
|
|
@ -47,6 +47,10 @@ impl<'a> LocationMethods for JSRef<'a, Location> {
|
||||||
UrlHelper::Href(&self.page.get_url())
|
UrlHelper::Href(&self.page.get_url())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn Stringify(self) -> DOMString {
|
||||||
|
self.Href()
|
||||||
|
}
|
||||||
|
|
||||||
fn Search(self) -> DOMString {
|
fn Search(self) -> DOMString {
|
||||||
UrlHelper::Search(&self.page.get_url())
|
UrlHelper::Search(&self.page.get_url())
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ interface URLUtils {
|
||||||
//stringifier attribute ScalarValueString href;
|
//stringifier attribute ScalarValueString href;
|
||||||
readonly attribute DOMString href;
|
readonly attribute DOMString href;
|
||||||
//readonly attribute ScalarValueString origin;
|
//readonly attribute ScalarValueString origin;
|
||||||
|
|
||||||
// attribute ScalarValueString protocol;
|
// attribute ScalarValueString protocol;
|
||||||
// attribute ScalarValueString username;
|
// attribute ScalarValueString username;
|
||||||
// attribute ScalarValueString password;
|
// attribute ScalarValueString password;
|
||||||
|
@ -22,4 +21,8 @@ interface URLUtils {
|
||||||
// attribute URLSearchParams searchParams;
|
// attribute URLSearchParams searchParams;
|
||||||
// attribute ScalarValueString hash;
|
// attribute ScalarValueString hash;
|
||||||
readonly attribute DOMString hash;
|
readonly attribute DOMString hash;
|
||||||
|
|
||||||
|
// This is only doing as well as gecko right now, bug 824857 is on file for
|
||||||
|
// adding attribute stringifier support.
|
||||||
|
stringifier;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,12 +57,6 @@
|
||||||
[detachedPara2.firstElementChild]
|
[detachedPara2.firstElementChild]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[document.URL]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[document.documentURI]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[foreignPara1.previousElementSibling]
|
[foreignPara1.previousElementSibling]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
[location-stringifier.html]
|
|
||||||
type: testharness
|
|
||||||
[Location stringifier]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Location stringifier 1]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Location stringifier 3]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Location stringifier 4]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue