Implement [Replaceable] (fixes #13033)

This commit is contained in:
Anthony Ramine 2015-10-14 00:19:13 +02:00
parent 9b4713f536
commit dccf771e25
6 changed files with 31 additions and 33 deletions

View file

@ -1670,7 +1670,8 @@ class AttrDefiner(PropertyDefiner):
"native": accessor}) "native": accessor})
def setter(attr): def setter(attr):
if attr.readonly and not attr.getExtendedAttribute("PutForwards"): if (attr.readonly and not attr.getExtendedAttribute("PutForwards")
and not attr.getExtendedAttribute("Replaceable")):
return "JSNativeWrapper { op: None, info: 0 as *const JSJitInfo }" return "JSNativeWrapper { op: None, info: 0 as *const JSJitInfo }"
if self.static: if self.static:
@ -3496,6 +3497,23 @@ JS_SetProperty(cx, target_obj.handle(), %s as *const u8 as *const libc::c_char,
""" % (str_to_const_array(attrName), attrName, str_to_const_array(forwardToAttrName))) """ % (str_to_const_array(attrName), attrName, str_to_const_array(forwardToAttrName)))
class CGSpecializedReplaceableSetter(CGSpecializedSetter):
"""
A class for generating the code for an IDL replaceable attribute setter.
"""
def __init__(self, descriptor, attr):
CGSpecializedSetter.__init__(self, descriptor, attr)
def definition_body(self):
assert self.attr.readonly
name = str_to_const_array(self.attr.identifier.name)
# JS_DefineProperty can only deal with ASCII.
assert all(ord(c) < 128 for c in name)
return CGGeneric("""\
JS_DefineProperty(cx, obj, %s as *const u8 as *const libc::c_char,
args.get(0), JSPROP_ENUMERATE, None, None)""" % name)
class CGMemberJITInfo(CGThing): class CGMemberJITInfo(CGThing):
""" """
A class for generating the JITInfo for a property that points to A class for generating the JITInfo for a property that points to
@ -3608,7 +3626,8 @@ class CGMemberJITInfo(CGThing):
isAlwaysInSlot, isLazilyCachedInSlot, isAlwaysInSlot, isLazilyCachedInSlot,
slotIndex, slotIndex,
[self.member.type], None) [self.member.type], None)
if (not self.member.readonly or self.member.getExtendedAttribute("PutForwards")): if (not self.member.readonly or self.member.getExtendedAttribute("PutForwards")
or self.member.getExtendedAttribute("Replaceable")):
setterinfo = ("%s_setterinfo" % internalMemberName) setterinfo = ("%s_setterinfo" % internalMemberName)
setter = ("set_%s" % internalMemberName) setter = ("set_%s" % internalMemberName)
# Setters are always fallible, since they have to do a typed unwrap. # Setters are always fallible, since they have to do a typed unwrap.
@ -5307,12 +5326,13 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::{JS_CALLEE, JSCLASS_GLOBAL_SLOT_COUNT}', 'js::{JS_CALLEE, JSCLASS_GLOBAL_SLOT_COUNT}',
'js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_MASK}', 'js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_MASK}',
'js::error::throw_type_error', 'js::error::throw_type_error',
'js::jsapi::{AutoIdVector, Call, CallArgs, FreeOp, GetPropertyKeys, GetWellKnownSymbol}', 'js::jsapi::{AutoIdVector, Call, CallArgs, FreeOp, GetPropertyKeys}',
'js::jsapi::{Handle, HandleId, HandleObject, HandleValue, HandleValueArray}', 'js::jsapi::{GetWellKnownSymbol, Handle, HandleId, HandleObject, HandleValue}',
'js::jsapi::{INTERNED_STRING_TO_JSID, IsCallable, JS_AtomizeAndPinString}', 'js::jsapi::{HandleValueArray, INTERNED_STRING_TO_JSID, IsCallable}',
'js::jsapi::{JS_CallFunctionValue, JS_CopyPropertiesFrom, JS_DefinePropertyById2}', 'js::jsapi::{JS_AtomizeAndPinString, JS_CallFunctionValue, JS_CopyPropertiesFrom}',
'js::jsapi::{JS_ForwardGetPropertyTo, JS_GetClass, JS_GetErrorPrototype}', 'js::jsapi::{JS_DefineProperty, JS_DefinePropertyById2, JS_ForwardGetPropertyTo}',
'js::jsapi::{JS_GetFunctionPrototype, JS_GetGlobalForObject, JS_GetIteratorPrototype}', 'js::jsapi::{JS_GetClass, JS_GetErrorPrototype, JS_GetFunctionPrototype}',
'js::jsapi::{JS_GetGlobalForObject, JS_GetIteratorPrototype}',
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}', 'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot, JS_HasProperty}', 'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot, JS_HasProperty}',
'js::jsapi::{JS_HasPropertyById, JS_InitializePropertiesFromCompatibleNativeObject}', 'js::jsapi::{JS_HasPropertyById, JS_InitializePropertiesFromCompatibleNativeObject}',
@ -5460,6 +5480,8 @@ class CGDescriptor(CGThing):
cgThings.append(CGSpecializedSetter(descriptor, m)) cgThings.append(CGSpecializedSetter(descriptor, m))
elif m.getExtendedAttribute("PutForwards"): elif m.getExtendedAttribute("PutForwards"):
cgThings.append(CGSpecializedForwardingSetter(descriptor, m)) cgThings.append(CGSpecializedForwardingSetter(descriptor, m))
elif m.getExtendedAttribute("Replaceable"):
cgThings.append(CGSpecializedReplaceableSetter(descriptor, m))
if (not m.isStatic() and not descriptor.interface.isCallback()): if (not m.isStatic() and not descriptor.interface.isCallback()):
cgThings.append(CGMemberJITInfo(descriptor, m)) cgThings.append(CGMemberJITInfo(descriptor, m))

View file

@ -89,7 +89,7 @@ Window implements WindowBase64;
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#sec-window.performance-attribute // https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#sec-window.performance-attribute
partial interface Window { partial interface Window {
/*[Replaceable]*/ readonly attribute Performance performance; [Replaceable] readonly attribute Performance performance;
}; };
// https://html.spec.whatwg.org/multipage/#Window-partial // https://html.spec.whatwg.org/multipage/#Window-partial

View file

@ -42,9 +42,6 @@
[Window unforgeable attribute: location] [Window unforgeable attribute: location]
expected: FAIL expected: FAIL
[Window replaceable attribute: self]
expected: FAIL
[Window replaceable attribute: locationbar] [Window replaceable attribute: locationbar]
expected: FAIL expected: FAIL
@ -63,9 +60,6 @@
[Window replaceable attribute: toolbar] [Window replaceable attribute: toolbar]
expected: FAIL expected: FAIL
[Window replaceable attribute: frames]
expected: FAIL
[Window replaceable attribute: length] [Window replaceable attribute: length]
expected: FAIL expected: FAIL

View file

@ -4902,9 +4902,6 @@
[Window interface: existence and properties of interface prototype object] [Window interface: existence and properties of interface prototype object]
expected: FAIL expected: FAIL
[Window interface: attribute self]
expected: FAIL
[Window interface: attribute name] [Window interface: attribute name]
expected: FAIL expected: FAIL
@ -4938,9 +4935,6 @@
[Window interface: operation blur()] [Window interface: operation blur()]
expected: FAIL expected: FAIL
[Window interface: attribute frames]
expected: FAIL
[Window interface: attribute length] [Window interface: attribute length]
expected: FAIL expected: FAIL

View file

@ -1,8 +1,5 @@
[idlharness.html] [idlharness.html]
type: testharness type: testharness
[Window interface: attribute performance]
expected: FAIL
[PerformanceTiming interface: attribute unloadEventStart] [PerformanceTiming interface: attribute unloadEventStart]
expected: FAIL expected: FAIL

View file

@ -1,9 +0,0 @@
[test_readwrite.html]
type: testharness
bug: https://github.com/servo/servo/issues/13033
[window.performance is read/write]
expected: FAIL
[var performance is read/write]
expected: FAIL