mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
fix: codegen on callback (#32537)
* Fix codegen on callback * Add test callbacks to testbinding.rs
This commit is contained in:
parent
d4db08113d
commit
63889b732f
3 changed files with 24 additions and 8 deletions
|
@ -2258,6 +2258,10 @@ class CGImports(CGWrapper):
|
||||||
descriptorProvider = config.getDescriptorProvider()
|
descriptorProvider = config.getDescriptorProvider()
|
||||||
extras = []
|
extras = []
|
||||||
for t in types:
|
for t in types:
|
||||||
|
# Importing these callbacks in the same module that defines them is an error.
|
||||||
|
if t.isCallback():
|
||||||
|
if getIdentifier(t) in [c.identifier for c in callbacks]:
|
||||||
|
continue
|
||||||
# Importing these types in the same module that defines them is an error.
|
# Importing these types in the same module that defines them is an error.
|
||||||
if t in dictionaries or t in enums:
|
if t in dictionaries or t in enums:
|
||||||
continue
|
continue
|
||||||
|
@ -7327,7 +7331,7 @@ class CallbackMember(CGNativeMember):
|
||||||
visibility=visibility)
|
visibility=visibility)
|
||||||
# We have to do all the generation of our body now, because
|
# We have to do all the generation of our body now, because
|
||||||
# the caller relies on us throwing if we can't manage it.
|
# the caller relies on us throwing if we can't manage it.
|
||||||
self.exceptionCode = "return Err(JSFailed);"
|
self.exceptionCode = "return Err(JSFailed);\n"
|
||||||
self.body = self.getImpl()
|
self.body = self.getImpl()
|
||||||
|
|
||||||
def getImpl(self):
|
def getImpl(self):
|
||||||
|
@ -7390,14 +7394,19 @@ class CallbackMember(CGNativeMember):
|
||||||
# Just reget the arglist from self.originalSig, because our superclasses
|
# Just reget the arglist from self.originalSig, because our superclasses
|
||||||
# just have way to many members they like to clobber, so I can't find a
|
# just have way to many members they like to clobber, so I can't find a
|
||||||
# safe member name to store it in.
|
# safe member name to store it in.
|
||||||
|
arglist = self.originalSig[1]
|
||||||
argConversions = [self.getArgConversion(i, arg) for (i, arg)
|
argConversions = [self.getArgConversion(i, arg) for (i, arg)
|
||||||
in enumerate(self.originalSig[1])]
|
in enumerate(arglist)]
|
||||||
# Do them back to front, so our argc modifications will work
|
# Do them back to front, so our argc modifications will work
|
||||||
# correctly, because we examine trailing arguments first.
|
# correctly, because we examine trailing arguments first.
|
||||||
argConversions.reverse()
|
argConversions.reverse()
|
||||||
argConversions = [CGGeneric(c) for c in argConversions]
|
argConversions = [CGGeneric(c) for c in argConversions]
|
||||||
if self.argCount > 0:
|
# If arg count is only 1 but it's optional and not default value,
|
||||||
argConversions.insert(0, self.getArgcDecl())
|
# argc should be mutable.
|
||||||
|
if self.argCount == 1 and not (arglist[0].optional and not arglist[0].defaultValue):
|
||||||
|
argConversions.insert(0, self.getArgcDecl(True))
|
||||||
|
elif self.argCount > 0:
|
||||||
|
argConversions.insert(0, self.getArgcDecl(False))
|
||||||
# And slap them together.
|
# And slap them together.
|
||||||
return CGList(argConversions, "\n\n").define() + "\n\n"
|
return CGList(argConversions, "\n\n").define() + "\n\n"
|
||||||
|
|
||||||
|
@ -7462,8 +7471,8 @@ class CallbackMember(CGNativeMember):
|
||||||
" return Err(JSFailed);\n"
|
" return Err(JSFailed);\n"
|
||||||
"}\n")
|
"}\n")
|
||||||
|
|
||||||
def getArgcDecl(self):
|
def getArgcDecl(self, immutable):
|
||||||
if self.argCount <= 1:
|
if immutable:
|
||||||
return CGGeneric("let argc = %s;" % self.argCountStr)
|
return CGGeneric("let argc = %s;" % self.argCountStr)
|
||||||
return CGGeneric("let mut argc = %s;" % self.argCountStr)
|
return CGGeneric("let mut argc = %s;" % self.argCountStr)
|
||||||
|
|
||||||
|
|
|
@ -612,14 +612,18 @@ impl TestBindingMethods for TestBinding {
|
||||||
unsignedShortValue: None,
|
unsignedShortValue: None,
|
||||||
usvstringValue: None,
|
usvstringValue: None,
|
||||||
nonRequiredNullable: None,
|
nonRequiredNullable: None,
|
||||||
nonRequiredNullable2: Some(None), // null
|
nonRequiredNullable2: Some(None),
|
||||||
|
noCallbackImport: None,
|
||||||
|
noCallbackImport2: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn DictMatchesPassedValues(&self, arg: RootedTraceableBox<TestDictionary>) -> bool {
|
fn DictMatchesPassedValues(&self, arg: RootedTraceableBox<TestDictionary>) -> bool {
|
||||||
arg.type_.as_ref().map(|s| s == "success").unwrap_or(false) &&
|
arg.type_.as_ref().map(|s| s == "success").unwrap_or(false) &&
|
||||||
arg.nonRequiredNullable.is_none() &&
|
arg.nonRequiredNullable.is_none() &&
|
||||||
arg.nonRequiredNullable2 == Some(None)
|
arg.nonRequiredNullable2 == Some(None) &&
|
||||||
|
arg.noCallbackImport == None &&
|
||||||
|
arg.noCallbackImport2 == None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn PassBoolean(&self, _: bool) {}
|
fn PassBoolean(&self, _: bool) {}
|
||||||
|
|
|
@ -43,6 +43,8 @@ dictionary TestDictionary {
|
||||||
// in dictionaries.
|
// in dictionaries.
|
||||||
DOMString? nonRequiredNullable;
|
DOMString? nonRequiredNullable;
|
||||||
DOMString? nonRequiredNullable2;
|
DOMString? nonRequiredNullable2;
|
||||||
|
SimpleCallback noCallbackImport;
|
||||||
|
callbackWithOnlyOneOptionalArg noCallbackImport2;
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary TestDictionaryParent {
|
dictionary TestDictionaryParent {
|
||||||
|
@ -594,6 +596,7 @@ partial interface TestBinding {
|
||||||
};
|
};
|
||||||
|
|
||||||
callback SimpleCallback = undefined(any value);
|
callback SimpleCallback = undefined(any value);
|
||||||
|
callback callbackWithOnlyOneOptionalArg = Promise<undefined> (optional any reason);
|
||||||
|
|
||||||
partial interface TestBinding {
|
partial interface TestBinding {
|
||||||
[Pref="dom.testable_crash.enabled"]
|
[Pref="dom.testable_crash.enabled"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue