mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
refactor(script): squash CGDOMJSProxyHandler_set
The implementation in `crate::dom::bindings::proxyhandler:: maybe_cross_origin_set_rawcx` is now directly assigned to `ProxyTraps:: set`.
This commit is contained in:
parent
66a4ea0727
commit
c28e98ec40
2 changed files with 49 additions and 51 deletions
|
@ -3556,7 +3556,11 @@ class CGDefineProxyHandler(CGAbstractMethod):
|
||||||
|
|
||||||
customSet = 'None'
|
customSet = 'None'
|
||||||
if self.descriptor.isMaybeCrossOriginObject():
|
if self.descriptor.isMaybeCrossOriginObject():
|
||||||
customSet = 'Some(set)'
|
# `maybe_cross_origin_set_rawcx` doesn't support legacy platform objects'
|
||||||
|
# `[[Set]]` (https://heycam.github.io/webidl/#legacy-platform-object-set) (yet).
|
||||||
|
assert not self.descriptor.operations['IndexedGetter']
|
||||||
|
assert not self.descriptor.operations['NamedGetter']
|
||||||
|
customSet = 'Some(proxyhandler::maybe_cross_origin_set_rawcx)'
|
||||||
|
|
||||||
getOwnEnumerablePropertyKeys = "own_property_keys"
|
getOwnEnumerablePropertyKeys = "own_property_keys"
|
||||||
if self.descriptor.interface.getExtendedAttribute("LegacyUnenumerableNamedProperties") or \
|
if self.descriptor.interface.getExtendedAttribute("LegacyUnenumerableNamedProperties") or \
|
||||||
|
@ -5958,55 +5962,6 @@ return true;""" % (maybeCrossOriginGet, getIndexedOrExpando, getNamed)
|
||||||
return CGGeneric(self.getBody())
|
return CGGeneric(self.getBody())
|
||||||
|
|
||||||
|
|
||||||
class CGDOMJSProxyHandler_set(CGAbstractExternMethod):
|
|
||||||
def __init__(self, descriptor):
|
|
||||||
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
|
|
||||||
Argument('RawHandleId', 'id'), Argument('RawHandleValue', 'v'),
|
|
||||||
Argument('RawHandleValue', 'receiver'),
|
|
||||||
Argument('*mut ObjectOpResult', 'opresult')]
|
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, "set", "bool", args)
|
|
||||||
self.descriptor = descriptor
|
|
||||||
|
|
||||||
def getBody(self):
|
|
||||||
descriptor = self.descriptor
|
|
||||||
|
|
||||||
# `CGDOMJSProxyHandler_set` doesn't support legacy platform objects'
|
|
||||||
# `[[Set]]` (https://heycam.github.io/webidl/#legacy-platform-object-set) yet.
|
|
||||||
#
|
|
||||||
assert descriptor.isMaybeCrossOriginObject()
|
|
||||||
assert not descriptor.operations['IndexedGetter']
|
|
||||||
assert not descriptor.operations['NamedGetter']
|
|
||||||
|
|
||||||
maybeCrossOriginSet = dedent(
|
|
||||||
"""
|
|
||||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
|
||||||
return proxyhandler::cross_origin_set(cx, proxy, id, v, receiver, opresult);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Safe to enter the Realm of proxy now.
|
|
||||||
let _ac = JSAutoRealm::new(*cx, proxy.get());
|
|
||||||
""")
|
|
||||||
|
|
||||||
return dedent(
|
|
||||||
"""
|
|
||||||
let cx = SafeJSContext::from_ptr(cx);
|
|
||||||
%(maybeCrossOriginSet)s
|
|
||||||
|
|
||||||
// OrdinarySet
|
|
||||||
// <https://tc39.es/ecma262/#sec-ordinaryset>
|
|
||||||
rooted!(in(*cx) let mut own_desc = PropertyDescriptor::default());
|
|
||||||
if !getOwnPropertyDescriptor(*cx, proxy, id, own_desc.handle_mut().into()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
js::jsapi::SetPropertyIgnoringNamedGetter(
|
|
||||||
*cx, proxy, id, v, receiver, own_desc.handle().into(), opresult)
|
|
||||||
""") % {"maybeCrossOriginSet": maybeCrossOriginSet}
|
|
||||||
|
|
||||||
def definition_body(self):
|
|
||||||
return CGGeneric(self.getBody())
|
|
||||||
|
|
||||||
|
|
||||||
class CGDOMJSProxyHandler_getPrototype(CGAbstractExternMethod):
|
class CGDOMJSProxyHandler_getPrototype(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
|
||||||
|
@ -6693,7 +6648,6 @@ class CGDescriptor(CGThing):
|
||||||
|
|
||||||
if descriptor.isMaybeCrossOriginObject():
|
if descriptor.isMaybeCrossOriginObject():
|
||||||
cgThings.append(CGDOMJSProxyHandler_getPrototype(descriptor))
|
cgThings.append(CGDOMJSProxyHandler_getPrototype(descriptor))
|
||||||
cgThings.append(CGDOMJSProxyHandler_set(descriptor))
|
|
||||||
|
|
||||||
# cgThings.append(CGDOMJSProxyHandler(descriptor))
|
# cgThings.append(CGDOMJSProxyHandler(descriptor))
|
||||||
# cgThings.append(CGIsMethod(descriptor))
|
# cgThings.append(CGIsMethod(descriptor))
|
||||||
|
|
|
@ -310,6 +310,50 @@ pub unsafe fn cross_origin_own_property_keys(
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implementation of `[[Set]]` for [`Location`].
|
||||||
|
///
|
||||||
|
/// [`Location`]: https://html.spec.whatwg.org/multipage/#location-set
|
||||||
|
pub unsafe extern "C" fn maybe_cross_origin_set_rawcx(
|
||||||
|
cx: *mut JSContext,
|
||||||
|
proxy: RawHandleObject,
|
||||||
|
id: RawHandleId,
|
||||||
|
v: RawHandleValue,
|
||||||
|
receiver: RawHandleValue,
|
||||||
|
result: *mut ObjectOpResult,
|
||||||
|
) -> bool {
|
||||||
|
let cx = SafeJSContext::from_ptr(cx);
|
||||||
|
|
||||||
|
if !is_platform_object_same_origin(cx, proxy) {
|
||||||
|
return cross_origin_set(cx, proxy, id, v, receiver, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safe to enter the Realm of proxy now.
|
||||||
|
let _ac = JSAutoRealm::new(*cx, proxy.get());
|
||||||
|
|
||||||
|
// OrdinarySet
|
||||||
|
// <https://tc39.es/ecma262/#sec-ordinaryset>
|
||||||
|
rooted!(in(*cx) let mut own_desc = PropertyDescriptor::default());
|
||||||
|
if !InvokeGetOwnPropertyDescriptor(
|
||||||
|
GetProxyHandler(*proxy),
|
||||||
|
*cx,
|
||||||
|
proxy,
|
||||||
|
id,
|
||||||
|
own_desc.handle_mut().into(),
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
js::jsapi::SetPropertyIgnoringNamedGetter(
|
||||||
|
*cx,
|
||||||
|
proxy,
|
||||||
|
id,
|
||||||
|
v,
|
||||||
|
receiver,
|
||||||
|
own_desc.handle().into(),
|
||||||
|
result,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub unsafe extern "C" fn maybe_cross_origin_get_prototype_if_ordinary_rawcx(
|
pub unsafe extern "C" fn maybe_cross_origin_get_prototype_if_ordinary_rawcx(
|
||||||
_: *mut JSContext,
|
_: *mut JSContext,
|
||||||
_proxy: RawHandleObject,
|
_proxy: RawHandleObject,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue