mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Auto merge of #14994 - jdm:callback_rooting, r=Manishearth,Ms2ger
Make WebIDL callbacks permanently rooted This replicates the same model that Promise uses right now, because it requires less thinking than coming up with something else. - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14447 - [ ] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14994) <!-- Reviewable:end -->
This commit is contained in:
commit
e891277dd5
4 changed files with 75 additions and 28 deletions
|
@ -769,7 +769,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
if descriptor.interface.isCallback():
|
||||
name = descriptor.nativeType
|
||||
declType = CGWrapper(CGGeneric(name), pre="Rc<", post=">")
|
||||
template = "%s::new(${val}.get().to_object())" % name
|
||||
template = "%s::new(cx, ${val}.get().to_object())" % name
|
||||
if type.nullable():
|
||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||
template = wrapObjectTemplate("Some(%s)" % template, "None",
|
||||
|
@ -2188,7 +2188,7 @@ class CGGeneric(CGThing):
|
|||
|
||||
class CGCallbackTempRoot(CGGeneric):
|
||||
def __init__(self, name):
|
||||
CGGeneric.__init__(self, "%s::new(${val}.get().to_object())" % name)
|
||||
CGGeneric.__init__(self, "%s::new(cx, ${val}.get().to_object())" % name)
|
||||
|
||||
|
||||
def getAllTypes(descriptors, dictionaries, callbacks, typedefs):
|
||||
|
@ -4437,10 +4437,11 @@ class ClassConstructor(ClassItem):
|
|||
"});\n"
|
||||
"// Note: callback cannot be moved after calling init.\n"
|
||||
"match Rc::get_mut(&mut ret) {\n"
|
||||
" Some(ref mut callback) => callback.parent.init(%s),\n"
|
||||
" Some(ref mut callback) => unsafe { callback.parent.init(%s, %s) },\n"
|
||||
" None => unreachable!(),\n"
|
||||
"};\n"
|
||||
"ret") % (cgClass.name, '\n'.join(initializers), self.args[0].name))
|
||||
"ret") % (cgClass.name, '\n'.join(initializers),
|
||||
self.args[0].name, self.args[1].name))
|
||||
|
||||
def declare(self, cgClass):
|
||||
args = ', '.join([a.declare() for a in self.args])
|
||||
|
@ -6229,11 +6230,11 @@ class CGCallback(CGClass):
|
|||
bases=[ClassBase(baseName)],
|
||||
constructors=self.getConstructors(),
|
||||
methods=realMethods + getters + setters,
|
||||
decorators="#[derive(JSTraceable, PartialEq)]")
|
||||
decorators="#[derive(JSTraceable, PartialEq)]\n#[allow_unrooted_interior]")
|
||||
|
||||
def getConstructors(self):
|
||||
return [ClassConstructor(
|
||||
[Argument("*mut JSObject", "aCallback")],
|
||||
[Argument("*mut JSContext", "aCx"), Argument("*mut JSObject", "aCallback")],
|
||||
bodyInHeader=True,
|
||||
visibility="pub",
|
||||
explicit=False,
|
||||
|
@ -6329,8 +6330,8 @@ class CGCallbackFunctionImpl(CGGeneric):
|
|||
def __init__(self, callback):
|
||||
impl = string.Template("""\
|
||||
impl CallbackContainer for ${type} {
|
||||
fn new(callback: *mut JSObject) -> Rc<${type}> {
|
||||
${type}::new(callback)
|
||||
unsafe fn new(cx: *mut JSContext, callback: *mut JSObject) -> Rc<${type}> {
|
||||
${type}::new(cx, callback)
|
||||
}
|
||||
|
||||
fn callback_holder(&self) -> &CallbackObject {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue