mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Make the private callback methods taking a raw this pointer unsafe
This commit is contained in:
parent
74dabbdc62
commit
de426baecc
1 changed files with 12 additions and 10 deletions
|
@ -4417,7 +4417,7 @@ class ClassMethod(ClassItem):
|
||||||
def __init__(self, name, returnType, args, inline=False, static=False,
|
def __init__(self, name, returnType, args, inline=False, static=False,
|
||||||
virtual=False, const=False, bodyInHeader=False,
|
virtual=False, const=False, bodyInHeader=False,
|
||||||
templateArgs=None, visibility='public', body=None,
|
templateArgs=None, visibility='public', body=None,
|
||||||
breakAfterReturnDecl="\n",
|
breakAfterReturnDecl="\n", unsafe=False,
|
||||||
breakAfterSelf="\n", override=False):
|
breakAfterSelf="\n", override=False):
|
||||||
"""
|
"""
|
||||||
override indicates whether to flag the method as MOZ_OVERRIDE
|
override indicates whether to flag the method as MOZ_OVERRIDE
|
||||||
|
@ -4436,6 +4436,7 @@ class ClassMethod(ClassItem):
|
||||||
self.breakAfterReturnDecl = breakAfterReturnDecl
|
self.breakAfterReturnDecl = breakAfterReturnDecl
|
||||||
self.breakAfterSelf = breakAfterSelf
|
self.breakAfterSelf = breakAfterSelf
|
||||||
self.override = override
|
self.override = override
|
||||||
|
self.unsafe = unsafe
|
||||||
ClassItem.__init__(self, name, visibility)
|
ClassItem.__init__(self, name, visibility)
|
||||||
|
|
||||||
def getDecorators(self, declaring):
|
def getDecorators(self, declaring):
|
||||||
|
@ -4468,7 +4469,7 @@ class ClassMethod(ClassItem):
|
||||||
|
|
||||||
return string.Template(
|
return string.Template(
|
||||||
"${decorators}%s"
|
"${decorators}%s"
|
||||||
"${visibility}fn ${name}${templateClause}(${args})${returnType}${const}${override}${body}%s" %
|
"${visibility}${unsafe}fn ${name}${templateClause}(${args})${returnType}${const}${override}${body}%s" %
|
||||||
(self.breakAfterReturnDecl, self.breakAfterSelf)
|
(self.breakAfterReturnDecl, self.breakAfterSelf)
|
||||||
).substitute({
|
).substitute({
|
||||||
'templateClause': templateClause,
|
'templateClause': templateClause,
|
||||||
|
@ -4479,7 +4480,8 @@ class ClassMethod(ClassItem):
|
||||||
'override': ' MOZ_OVERRIDE' if self.override else '',
|
'override': ' MOZ_OVERRIDE' if self.override else '',
|
||||||
'args': args,
|
'args': args,
|
||||||
'body': body,
|
'body': body,
|
||||||
'visibility': self.visibility + ' ' if self.visibility != 'priv' else ''
|
'visibility': self.visibility + ' ' if self.visibility != 'priv' else '',
|
||||||
|
'unsafe': "unsafe " if self.unsafe else "",
|
||||||
})
|
})
|
||||||
|
|
||||||
def define(self, cgClass):
|
def define(self, cgClass):
|
||||||
|
@ -6495,7 +6497,8 @@ def return_type(descriptorProvider, rettype, infallible):
|
||||||
|
|
||||||
class CGNativeMember(ClassMethod):
|
class CGNativeMember(ClassMethod):
|
||||||
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
|
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
|
||||||
breakAfter=True, passJSBitsAsNeeded=True, visibility="public"):
|
breakAfter=True, passJSBitsAsNeeded=True, visibility="public",
|
||||||
|
unsafe=False):
|
||||||
"""
|
"""
|
||||||
If passJSBitsAsNeeded is false, we don't automatically pass in a
|
If passJSBitsAsNeeded is false, we don't automatically pass in a
|
||||||
JSContext* or a JSObject* based on the return and argument types.
|
JSContext* or a JSObject* based on the return and argument types.
|
||||||
|
@ -6514,6 +6517,7 @@ class CGNativeMember(ClassMethod):
|
||||||
const=(not member.isStatic() and member.isAttr() and
|
const=(not member.isStatic() and member.isAttr() and
|
||||||
not signature[0].isVoid()),
|
not signature[0].isVoid()),
|
||||||
breakAfterSelf=breakAfterSelf,
|
breakAfterSelf=breakAfterSelf,
|
||||||
|
unsafe=unsafe,
|
||||||
visibility=visibility)
|
visibility=visibility)
|
||||||
|
|
||||||
def getReturnType(self, type):
|
def getReturnType(self, type):
|
||||||
|
@ -6598,14 +6602,14 @@ class CGCallback(CGClass):
|
||||||
"if thisObjJS.is_null() {\n"
|
"if thisObjJS.is_null() {\n"
|
||||||
" return Err(JSFailed);\n"
|
" return Err(JSFailed);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"return ${methodName}(${callArgs});").substitute({
|
"unsafe { ${methodName}(${callArgs}) }").substitute({
|
||||||
"callArgs": ", ".join(argnamesWithThis),
|
"callArgs": ", ".join(argnamesWithThis),
|
||||||
"methodName": 'self.' + method.name,
|
"methodName": 'self.' + method.name,
|
||||||
})
|
})
|
||||||
bodyWithoutThis = string.Template(
|
bodyWithoutThis = string.Template(
|
||||||
setupCall +
|
setupCall +
|
||||||
"rooted!(in(s.get_context()) let thisObjJS = ptr::null_mut::<JSObject>());\n"
|
"rooted!(in(s.get_context()) let thisObjJS = ptr::null_mut::<JSObject>());\n"
|
||||||
"return ${methodName}(${callArgs});").substitute({
|
"unsafe { ${methodName}(${callArgs}) }").substitute({
|
||||||
"callArgs": ", ".join(argnamesWithoutThis),
|
"callArgs": ", ".join(argnamesWithoutThis),
|
||||||
"methodName": 'self.' + method.name,
|
"methodName": 'self.' + method.name,
|
||||||
})
|
})
|
||||||
|
@ -6728,6 +6732,7 @@ class CallbackMember(CGNativeMember):
|
||||||
name, (self.retvalType, args),
|
name, (self.retvalType, args),
|
||||||
extendedAttrs={},
|
extendedAttrs={},
|
||||||
passJSBitsAsNeeded=False,
|
passJSBitsAsNeeded=False,
|
||||||
|
unsafe=needThisHandling,
|
||||||
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.
|
||||||
|
@ -6761,10 +6766,7 @@ class CallbackMember(CGNativeMember):
|
||||||
"${convertArgs}"
|
"${convertArgs}"
|
||||||
"${doCall}"
|
"${doCall}"
|
||||||
"${returnResult}").substitute(replacements)
|
"${returnResult}").substitute(replacements)
|
||||||
return CGWrapper(CGIndenter(CGList([
|
return pre + "\n" + body
|
||||||
CGGeneric(pre),
|
|
||||||
CGGeneric(body),
|
|
||||||
], "\n"), 4), pre="unsafe {\n", post="\n}").define()
|
|
||||||
|
|
||||||
def getResultConversion(self):
|
def getResultConversion(self):
|
||||||
replacements = {
|
replacements = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue