script: propagate &mut JSContext in GlobalScope::report_an_error#44658
script: propagate &mut JSContext in GlobalScope::report_an_error#44658elomscansio wants to merge 2 commits into
Conversation
Signed-off-by: Emmanuel Paul Elom <elomemmanuel007@gmail.com>
| value.handle(), | ||
| can_gc, | ||
| ); | ||
| pub(crate) fn report_pending_exception(cx: &mut js::context::JSContext) { |
There was a problem hiding this comment.
This function took cx and InRealm so now it should take &mut https://doc.servo.org/mozjs/realm/struct.CurrentRealm.html
| let mut realm = enter_auto_realm(cx, &*global); | ||
| let cx = &mut realm.current_realm(); |
There was a problem hiding this comment.
because we now get realm we do not need to enter it anymore and we can also move global obtaining down
|
|
||
| 'Console': { | ||
| 'cx': ['Log', 'Clear', 'Debug', 'Info', 'Warn', 'Error', 'Trace'] | ||
| }, | ||
|
|
There was a problem hiding this comment.
@sagudev Do you know why i'm having this error.
Compiling servo-script-bindings v0.2.0 (/home/elomscansio/Desktop/PROJECTS/SERVO_SETUP/servo/components/script_bindings)
Compiling servo-script v0.2.0 (/home/elomscansio/Desktop/PROJECTS/SERVO_SETUP/servo/components/script)
error[E0053]: method `Log` has an incompatible type for trait
--> components/script/dom/console.rs:716:16
|
716 | fn Log(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleVa...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `JSContext`, found `&mut js::context::JSContext`
|
= note: expected signature `fn(script_bindings::script_runtime::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
found signature `fn(&mut js::context::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
help: change the parameter type to match the trait
|
716 - fn Log(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
716 + fn Log(cx: script_bindings::script_runtime::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
error[E0053]: method `Debug` has an incompatible type for trait
--> components/script/dom/console.rs:741:18
|
741 | fn Debug(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<Handle...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `JSContext`, found `&mut js::context::JSContext`
|
= note: expected signature `fn(script_bindings::script_runtime::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
found signature `fn(&mut js::context::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
help: change the parameter type to match the trait
|
741 - fn Debug(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
741 + fn Debug(cx: script_bindings::script_runtime::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
error[E0053]: method `Info` has an incompatible type for trait
--> components/script/dom/console.rs:752:17
|
752 | fn Info(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleV...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `JSContext`, found `&mut js::context::JSContext`
|
= note: expected signature `fn(script_bindings::script_runtime::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
found signature `fn(&mut js::context::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
help: change the parameter type to match the trait
|
752 - fn Info(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
752 + fn Info(cx: script_bindings::script_runtime::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
error[E0053]: method `Warn` has an incompatible type for trait
--> components/script/dom/console.rs:763:17
|
763 | fn Warn(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleV...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `JSContext`, found `&mut js::context::JSContext`
|
= note: expected signature `fn(script_bindings::script_runtime::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
found signature `fn(&mut js::context::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
help: change the parameter type to match the trait
|
763 - fn Warn(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
763 + fn Warn(cx: script_bindings::script_runtime::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
error[E0053]: method `Error` has an incompatible type for trait
--> components/script/dom/console.rs:774:18
|
774 | fn Error(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<Handle...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `JSContext`, found `&mut js::context::JSContext`
|
= note: expected signature `fn(script_bindings::script_runtime::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
found signature `fn(&mut js::context::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
help: change the parameter type to match the trait
|
774 - fn Error(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
774 + fn Error(cx: script_bindings::script_runtime::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
error[E0053]: method `Trace` has an incompatible type for trait
--> components/script/dom/console.rs:785:18
|
785 | fn Trace(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<Handle...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `JSContext`, found `&mut js::context::JSContext`
|
= note: expected signature `fn(script_bindings::script_runtime::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
found signature `fn(&mut js::context::JSContext, &globalscope::GlobalScope, Vec<js::rust::Handle<'_, _>>)`
help: change the parameter type to match the trait
|
785 - fn Trace(cx: &mut js::context::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
785 + fn Trace(cx: script_bindings::script_runtime::JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
For more information about this error, try `rustc --explain E0053`.
error: could not compile `servo-script` (lib) due to 6 previous errors
Timing report saved to /home/elomscansio/Desktop/PROJECTS/SERVO_SETUP/servo/target/cargo-timings/cargo-timing-20260501T155032.617163731Z.html
Failed in 0:01:36There was a problem hiding this comment.
Hm, this will might be a problem in codegen, I will check what is wrong tomorrow.
There was a problem hiding this comment.
Aha, you need to write lowercase console:
| 'Console': { | |
| 'cx': ['Log', 'Clear', 'Debug', 'Info', 'Warn', 'Error', 'Trace'] | |
| }, | |
| 'console': { | |
| 'cx': ['Log', 'Clear', 'Debug', 'Info', 'Warn', 'Error', 'Trace'] | |
| }, | |
because the trait is consoleMethods. This is one of the rarest cases where trait is lowercased.
…m instead of JSContext Signed-off-by: Emmanuel Paul Elom <elomemmanuel007@gmail.com>
38052f4 to
2fcc799
Compare
| @@ -429,9 +432,9 @@ pub(crate) fn take_and_report_pending_exception_for_api( | |||
|
|
|||
| let return_value = javascript_error_info_from_error_info(cx, &error_info, value.handle()); | |||
| GlobalScope::from_safe_context(cx.into(), in_realm).report_an_error( | |||
There was a problem hiding this comment.
Unrelated, but we should used GlobalScope::from_current_realm here, so we can avoid in realm proof.
| let window = &mut document.window(); | ||
| let global = window.global(); | ||
|
|
||
| let mut realm = enter_auto_realm(cx, &*global); |
There was a problem hiding this comment.
before we entered realm of window so we should keep doing this:
| let window = &mut document.window(); | |
| let global = window.global(); | |
| let mut realm = enter_auto_realm(cx, &*global); | |
| let window = document.window(); | |
| let mut realm = enter_auto_realm(cx, window); |
| let url = cformat!("{}", handler.url); | ||
| let options = unsafe { CompileOptionsWrapper::new_raw(*cx, url, handler.line as u32) }; | ||
| let options = | ||
| unsafe { CompileOptionsWrapper::new_raw(cx.raw_cx(), url, handler.line as u32) }; |
There was a problem hiding this comment.
| unsafe { CompileOptionsWrapper::new_raw(cx.raw_cx(), url, handler.line as u32) }; | |
| CompileOptionsWrapper::new(cx, url, handler.line as u32); |
| let mut ids = unsafe { IdVector::new(*cx) }; | ||
| let mut ids = unsafe { IdVector::new(cx.raw_cx()) }; | ||
| if !unsafe { | ||
| GetPropertyKeys( |
There was a problem hiding this comment.
In such cases we should use functions from wrappers2 if possible: https://doc.servo.org/mozjs/rust/wrappers2/fn.GetPropertyKeys.html
This goes for many methods in this file that need cx.raw_cx().
| let mut cx = unsafe { script_bindings::script_runtime::temp_cx() }; | ||
| let cx = &mut cx; |
There was a problem hiding this comment.
NOTE-TO-SELF: This will likely need to be perma cx, tho I think we should get it from SM.
|
@elomscansio what's the ststus of this PR? The migration was going along nicely and we would love to continue going. Is there anything we can help you with or is life busy in general that you want to revisit this later? |
Propagate
&mut JSContextinGlobalScope::report_an_errorand related call sites.Testing: Successful build is enough
Fixes: Part of #42638