-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Use higher level handles from JS bindings #20246
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
Conversation
The build appears unbroken, which honestly makes me extremely skeptical! |
Cargo.lock contains this modification:
which means the updated rust-mozjs wasn't used. |
Thanks! Why was explicit |
The modification showed up in TravisCI because we have a job that checks if Cargo.lock was modified during the build. The explicit update was necessary because the version in the Cargo.toml that was used by the patch did not match the version that was included in Cargo.lock already. |
☔ The latest upstream changes (presumably #20216) made this pull request unmergeable. Please resolve the merge conflicts. |
1b872a1
to
4946b19
Compare
4946b19
to
91398cf
Compare
525e924
to
9f5ecd5
Compare
@@ -166,7 +178,7 @@ pub unsafe fn get_expando_object(obj: HandleObject, expando: MutableHandleObject | |||
|
|||
/// Get the expando object, or create it if it doesn't exist yet. | |||
/// Fails on JSAPI failure. | |||
pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: HandleObject, expando: MutableHandleObject) { | |||
pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: RawHandleObject, mut expando: MutableHandleObject) { |
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.
Why is this a raw handle?
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.
Because using lifetimed handles would require 2 Handle::from_raw's (get_expando_object
and some extern "C"
function) instead of one into() in the codegen.
Is it ok then or should I switch to Handle
?
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.
This is ok.
-> bool { | ||
*is_ordinary = true; | ||
proto.set(GetStaticPrototype(proxy.get())); | ||
true | ||
} | ||
|
||
/// Get the expando object, or null if there is none. | ||
pub unsafe fn get_expando_object(obj: HandleObject, expando: MutableHandleObject) { | ||
pub unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandleObject) { |
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.
Let's take a non-raw handle here.
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.
get_expando_object
is always called from extern C functions, which need to have raw handles. With one exception of ensure_expando_handle.
I see no benefit here.
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.
That is a fair argument.
-> DOMProxyShadowsResult { | ||
// TODO: support OverrideBuiltins when #12978 is fixed. | ||
|
||
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>()); | ||
get_expando_object(object, expando.handle_mut()); | ||
if !expando.get().is_null() { | ||
let mut has_own = false; | ||
if !JS_AlreadyHasOwnPropertyById(cx, expando.handle(), id, &mut has_own) { | ||
if !JS_AlreadyHasOwnPropertyById( |
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.
Let's use a separate local variable for this rather than spread the if condition over multiple lines.
@@ -96,10 +96,10 @@ impl<T: ToJSValConvertible> ToJSValConvertible for MozMap<T> { | |||
value.to_jsval(cx, js_value.handle_mut()); | |||
|
|||
assert!(JS_DefineUCProperty2(cx, |
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.
What if we call the wrapper function here instead?
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.
Good catch! :)
@@ -443,7 +455,7 @@ unsafe fn define_name(cx: *mut JSContext, obj: HandleObject, name: &[u8]) { | |||
assert!(JS_DefineProperty2(cx, |
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.
What if we call the wrapper function here instead?
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.
but we're using the wrapper:
use js::rust::wrappers::{JS_DefineProperty, JS_DefineProperty1, JS_DefineProperty2};
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.
Then how are we passing a raw handle as an argument?
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.
The fourth argument is a HandleString, which is defined in js::jsapi but was never a part of js::rust, so I didn't add it either.
Should I introduce a Rusty equivalent of
typedef Handle<JSString*> HandleString
into rust-mozjs/js::rust?
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.
Yes please. We can do it in a followup PR though.
rval.set(JS_NewObjectWithUniqueType(cx, class, proto)); | ||
assert!(!rval.ptr.is_null()); |
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.
!rval.get().is_null()
assert!(!constants.is_empty()); | ||
rval.set(JS_NewObject(cx, ptr::null())); | ||
assert!(!rval.ptr.is_null()); |
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.
!rval.get().is_null()
@@ -144,8 +153,8 @@ pub unsafe fn get_property_on_prototype(cx: *mut JSContext, | |||
return false; | |||
} | |||
*found = has_property; | |||
let no_output = vp.ptr.is_null(); | |||
if !has_property || no_output { | |||
// let no_output = vp.ptr.is_null(); // TODO can we remove? |
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.
Yes, we can remove this one.
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 think we can still check
!rval.get().is_null()
.
Why do we remove checks in one place but leave them in the other?
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.
Because this check was wrong to begin with (we should have been checking vp.get.is_null()
), and it was removed from the equivalent upstream code two years ago.
@@ -453,7 +454,7 @@ impl EventTarget { | |||
args.as_ptr(), | |||
body.as_ptr(), | |||
body.len() as size_t, | |||
handler.handle_mut()) | |||
handler.handle_mut().into()) |
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.
What about calling the wrapper function?
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.
handler
is a MutableHandleFunction, a type which has never been a part of js::rust
.
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.
This can be improved along with the HandleString in a followup PR.
components/script/timers.rs
Outdated
@@ -520,7 +521,7 @@ impl JsTimerTask { | |||
// Returning Handles directly from Heap values is inherently unsafe, but here it's | |||
// always done via rooted JsTimers, which is safe. | |||
#[allow(unsafe_code)] | |||
fn collect_heap_args(&self, args: &[Heap<JSVal>]) -> Vec<HandleValue> { | |||
fn collect_heap_args<'b>(&self, args: &'b[Heap<JSVal>]) -> Vec<HandleValue<'b>> { |
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.
nit: space before [
@bors-servo try |
Use higher level handles from JS bindings …reak servo <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix servo/rust-mozjs#153 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because this is just migration to a lifetimed API <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/20246) <!-- Reviewable:end -->
💔 Test failed - linux-rel-wpt |
☔ The latest upstream changes (presumably #20430) made this pull request unmergeable. Please resolve the merge conflicts. |
💔 Test failed - linux-rel-css |
3bd097f
to
356c57e
Compare
@jdm squashed and ready to merge. |
@bors-servo r+ |
📌 Commit 356c57e has been approved by |
Use higher level handles from JS bindings …reak servo <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix servo/rust-mozjs#153 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because this is just migration to a lifetimed API <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/20246) <!-- Reviewable:end -->
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
Exciting! Thanks for pushing through all the problems @marmistrz! |
Lifetime all the type aliases for Handle and MutableHandle That's a follow-up to servo/servo#20246 Especially: * servo/servo#20246 (comment) * servo/servo#20246 (comment) <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/420) <!-- Reviewable:end -->
…reak servo
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsThis change is