mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Implement toStringTag symbol for DOM objects.
This symbol is now required for the expected stringification behaviour in WPT.
This commit is contained in:
parent
5c4939599e
commit
397b9b2601
1 changed files with 69 additions and 22 deletions
|
@ -1616,9 +1616,12 @@ class PropertyDefiner:
|
||||||
specs = []
|
specs = []
|
||||||
prefableSpecs = []
|
prefableSpecs = []
|
||||||
prefableTemplate = ' Guard::new(%s, %s[%d])'
|
prefableTemplate = ' Guard::new(%s, %s[%d])'
|
||||||
|
origTemplate = specTemplate
|
||||||
|
if isinstance(specTemplate, str):
|
||||||
|
specTemplate = lambda _: origTemplate # noqa
|
||||||
|
|
||||||
for cond, members in groupby(array, lambda m: getCondition(m, self.descriptor)):
|
for cond, members in groupby(array, lambda m: getCondition(m, self.descriptor)):
|
||||||
currentSpecs = [specTemplate % getDataTuple(m) for m in members]
|
currentSpecs = [specTemplate(m) % getDataTuple(m) for m in members]
|
||||||
if specTerminator:
|
if specTerminator:
|
||||||
currentSpecs.append(specTerminator)
|
currentSpecs.append(specTerminator)
|
||||||
specs.append("&[\n" + ",\n".join(currentSpecs) + "]\n")
|
specs.append("&[\n" + ",\n".join(currentSpecs) + "]\n")
|
||||||
|
@ -1826,7 +1829,11 @@ class AttrDefiner(PropertyDefiner):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
self.regular = [
|
self.regular = [
|
||||||
m
|
{
|
||||||
|
"name": m.identifier.name,
|
||||||
|
"attr": m,
|
||||||
|
"flags": "JSPROP_ENUMERATE",
|
||||||
|
}
|
||||||
for m in descriptor.interface.members if
|
for m in descriptor.interface.members if
|
||||||
m.isAttr() and m.isStatic() == static
|
m.isAttr() and m.isStatic() == static
|
||||||
and MemberIsUnforgeable(m, descriptor) == unforgeable
|
and MemberIsUnforgeable(m, descriptor) == unforgeable
|
||||||
|
@ -1834,15 +1841,21 @@ class AttrDefiner(PropertyDefiner):
|
||||||
self.static = static
|
self.static = static
|
||||||
self.unforgeable = unforgeable
|
self.unforgeable = unforgeable
|
||||||
|
|
||||||
|
if not static and not unforgeable and not (
|
||||||
|
descriptor.interface.isNamespace() or descriptor.interface.isCallback()
|
||||||
|
):
|
||||||
|
self.regular.append({
|
||||||
|
"name": "@@toStringTag",
|
||||||
|
"attr": None,
|
||||||
|
"flags": "JSPROP_READONLY | JSPROP_INTERNAL_USE_BIT"
|
||||||
|
})
|
||||||
|
|
||||||
def generateArray(self, array, name):
|
def generateArray(self, array, name):
|
||||||
if len(array) == 0:
|
if len(array) == 0:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
flags = "JSPROP_ENUMERATE"
|
|
||||||
if self.unforgeable:
|
|
||||||
flags += " | JSPROP_PERMANENT"
|
|
||||||
|
|
||||||
def getter(attr):
|
def getter(attr):
|
||||||
|
attr = attr['attr']
|
||||||
if self.static:
|
if self.static:
|
||||||
accessor = 'get_' + self.descriptor.internalNameFor(attr.identifier.name)
|
accessor = 'get_' + self.descriptor.internalNameFor(attr.identifier.name)
|
||||||
jitinfo = "0 as *const JSJitInfo"
|
jitinfo = "0 as *const JSJitInfo"
|
||||||
|
@ -1858,6 +1871,7 @@ class AttrDefiner(PropertyDefiner):
|
||||||
"native": accessor})
|
"native": accessor})
|
||||||
|
|
||||||
def setter(attr):
|
def setter(attr):
|
||||||
|
attr = attr['attr']
|
||||||
if (attr.readonly and not attr.getExtendedAttribute("PutForwards")
|
if (attr.readonly and not attr.getExtendedAttribute("PutForwards")
|
||||||
and not attr.getExtendedAttribute("Replaceable")):
|
and not attr.getExtendedAttribute("Replaceable")):
|
||||||
return "JSNativeWrapper { op: None, info: 0 as *const JSJitInfo }"
|
return "JSNativeWrapper { op: None, info: 0 as *const JSJitInfo }"
|
||||||
|
@ -1876,29 +1890,59 @@ class AttrDefiner(PropertyDefiner):
|
||||||
% {"info": jitinfo,
|
% {"info": jitinfo,
|
||||||
"native": accessor})
|
"native": accessor})
|
||||||
|
|
||||||
|
def condition(m, d):
|
||||||
|
if m["name"] == "@@toStringTag":
|
||||||
|
return MemberCondition(pref=None, func=None, exposed=None, secure=None)
|
||||||
|
return PropertyDefiner.getControllingCondition(m["attr"], d)
|
||||||
|
|
||||||
def specData(attr):
|
def specData(attr):
|
||||||
return (str_to_const_array(attr.identifier.name), flags, getter(attr),
|
if attr["name"] == "@@toStringTag":
|
||||||
|
return (attr["name"][2:], attr["flags"],
|
||||||
|
str_to_const_array(self.descriptor.interface.getClassName()))
|
||||||
|
|
||||||
|
flags = attr["flags"]
|
||||||
|
if self.unforgeable:
|
||||||
|
flags += " | JSPROP_PERMANENT"
|
||||||
|
return (str_to_const_array(attr["attr"].identifier.name), flags, getter(attr),
|
||||||
setter(attr))
|
setter(attr))
|
||||||
|
|
||||||
|
def template(m):
|
||||||
|
if m["name"] == "@@toStringTag":
|
||||||
|
return """ JSPropertySpec {
|
||||||
|
name: JSPropertySpec_Name { symbol_: SymbolCode::%s as usize + 1 },
|
||||||
|
flags_: (%s) as u8,
|
||||||
|
u: JSPropertySpec_AccessorsOrValue {
|
||||||
|
value: JSPropertySpec_ValueWrapper {
|
||||||
|
type_: JSValueType::JSVAL_TYPE_STRING as _,
|
||||||
|
__bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
|
||||||
|
string: %s as *const u8 as *const libc::c_char,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
return """ JSPropertySpec {
|
||||||
|
name: JSPropertySpec_Name { string_: %s as *const u8 as *const libc::c_char },
|
||||||
|
flags_: (%s) as u8,
|
||||||
|
u: JSPropertySpec_AccessorsOrValue {
|
||||||
|
accessors: JSPropertySpec_AccessorsOrValue_Accessors {
|
||||||
|
getter: JSPropertySpec_Accessor {
|
||||||
|
native: %s,
|
||||||
|
},
|
||||||
|
setter: JSPropertySpec_Accessor {
|
||||||
|
native: %s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
return self.generateGuardedArray(
|
return self.generateGuardedArray(
|
||||||
array, name,
|
array, name,
|
||||||
' JSPropertySpec {\n'
|
template,
|
||||||
' name: JSPropertySpec_Name { string_: %s as *const u8 as *const libc::c_char },\n'
|
|
||||||
' flags_: (%s) as u8,\n'
|
|
||||||
' u: JSPropertySpec_AccessorsOrValue {\n'
|
|
||||||
' accessors: JSPropertySpec_AccessorsOrValue_Accessors {\n'
|
|
||||||
' getter: JSPropertySpec_Accessor {\n'
|
|
||||||
' native: %s,\n'
|
|
||||||
' },\n'
|
|
||||||
' setter: JSPropertySpec_Accessor {\n'
|
|
||||||
' native: %s,\n'
|
|
||||||
' }\n'
|
|
||||||
' }\n'
|
|
||||||
' }\n'
|
|
||||||
' }',
|
|
||||||
' JSPropertySpec::ZERO',
|
' JSPropertySpec::ZERO',
|
||||||
'JSPropertySpec',
|
'JSPropertySpec',
|
||||||
PropertyDefiner.getControllingCondition, specData)
|
condition, specData)
|
||||||
|
|
||||||
|
|
||||||
class ConstDefiner(PropertyDefiner):
|
class ConstDefiner(PropertyDefiner):
|
||||||
|
@ -6046,11 +6090,14 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
||||||
'js::jsapi::JSPROP_ENUMERATE',
|
'js::jsapi::JSPROP_ENUMERATE',
|
||||||
'js::jsapi::JSPROP_PERMANENT',
|
'js::jsapi::JSPROP_PERMANENT',
|
||||||
'js::jsapi::JSPROP_READONLY',
|
'js::jsapi::JSPROP_READONLY',
|
||||||
|
'js::jsapi::JSPROP_INTERNAL_USE_BIT',
|
||||||
'js::jsapi::JSPropertySpec',
|
'js::jsapi::JSPropertySpec',
|
||||||
'js::jsapi::JSPropertySpec_Accessor',
|
'js::jsapi::JSPropertySpec_Accessor',
|
||||||
'js::jsapi::JSPropertySpec_AccessorsOrValue',
|
'js::jsapi::JSPropertySpec_AccessorsOrValue',
|
||||||
'js::jsapi::JSPropertySpec_AccessorsOrValue_Accessors',
|
'js::jsapi::JSPropertySpec_AccessorsOrValue_Accessors',
|
||||||
'js::jsapi::JSPropertySpec_Name',
|
'js::jsapi::JSPropertySpec_Name',
|
||||||
|
'js::jsapi::JSPropertySpec_ValueWrapper',
|
||||||
|
'js::jsapi::JSPropertySpec_ValueWrapper__bindgen_ty_1',
|
||||||
'js::jsapi::JSString',
|
'js::jsapi::JSString',
|
||||||
'js::jsapi::JSTracer',
|
'js::jsapi::JSTracer',
|
||||||
'js::jsapi::JSType',
|
'js::jsapi::JSType',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue