-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: CGClassConstructHook into Handwritten Helpers #31949
base: main
Are you sure you want to change the base?
Changes from 5 commits
a42fa02
0596fb8
3ee74d7
79fe50c
5c7972c
8af1386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// construct_hook.rs | ||
|
||
use std::ptr; | ||
use crate::dom::bindings::htmlconstructor; | ||
use crate::dom::bindings::utils::{GetConstructorNameForReporting, MakeNativeName}; | ||
use crate::dom::bindings::root::DomRoot; | ||
use crate::jsapi::{JSContext, JSObject, CallArgs, GlobalScope, SafeJSContext}; | ||
use crate::dom::bindings::import::module::callargs_is_constructing; | ||
use crate::dom::bindings::import::module::throw_constructor_without_new; | ||
use crate::dom::bindings::codegen::PrototypeList::ID; | ||
// Function for HTML constructor case | ||
pub unsafe fn construct_html_custom(global: &GlobalScope, cx: *mut JSContext, args: &CallArgs, descriptor_name: &str) -> bool { | ||
let global = DomRoot::downcast::<dom::types::Global>(global).unwrap(); // Adjust type as needed | ||
let prototype_id = match descriptor_name { | ||
"HTMLDivElement" => PrototypeList::ID::HTMLDivElement, | ||
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of taking string argument, we should take a PrototypeList::ID argument that we can use directly. The python code can construct the required value. |
||
"HTMLSpanElement" => PrototypeList::ID::HTMLSpanElement, | ||
// Add cases for other descriptor names as needed | ||
_ => panic!("Unsupported descriptor name: {}", descriptor_name), | ||
}; | ||
htmlconstructor::call_html_constructor::<dom::types::Global>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using |
||
cx, | ||
args, | ||
&global, | ||
prototype_id, // Adjust as needed | ||
descriptor_name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're missing the creator argument here. We should accept that as an argument in |
||
) | ||
} | ||
|
||
// Function for non-HTML constructor case | ||
pub unsafe fn construct_default_custom(global: &GlobalScope, cx: *mut JSContext, args: &CallArgs, descriptor_name: &str, ctor_name: &str) -> bool { | ||
let prototype_id = match descriptor_name { | ||
"HTMLDivElement" => PrototypeList::ID::HTMLDivElement, | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about using a PrototypeList::ID argument instead of a string. |
||
"HTMLSpanElement" => PrototypeList::ID::HTMLSpanElement, | ||
// Add cases for other descriptor names as needed | ||
_ => panic!("Unsupported descriptor name: {}", descriptor_name), | ||
}; | ||
if !callargs_is_constructing(args) { | ||
throw_constructor_without_new(cx, ctor_name); | ||
return false; | ||
} | ||
|
||
rooted!(in(cx) let mut desired_proto = ptr::null_mut::<JSObject>()); | ||
let proto_result = get_desired_proto( | ||
cx, | ||
args, | ||
prototype_id, // Adjust as needed | ||
descriptor_name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the creator argument here as earlier. This should be passed in by the python code. |
||
desired_proto.handle_mut(), | ||
); | ||
assert!(proto_result.is_ok()); | ||
if proto_result.is_err() { | ||
return false; | ||
} | ||
|
||
let nativeName = MakeNativeName(ctor_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MakeNativeName is a python function. This is going to be a bit tricky; I think we're going to need to leave the actual constructor call in the generated python code, because there's a lot of unique logic in there. What we can do is something like this: pub unsafe fn construct_default_custom(..., constructor: impl FnOnce(*mut JSContext, &CallArgs, &GlobalScope) -> bool) -> bool {
...
constructor(cx, args, global)
} Then modify the python code to call |
||
let args = vec![&global, Some(desired_proto.handle())]; | ||
// Placeholder for actual constructor method call | ||
true // Return true to indicate success, adjust as per actual logic | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this needs to be a downcast to Window, not Global, for the call to call_html_constructor to succeed.