Skip to content

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

Merged
merged 1 commit into from
Mar 28, 2018

Conversation

marmistrz
Copy link
Contributor

@marmistrz marmistrz commented Mar 8, 2018

…reak servo


  • There are tests for these changes OR
  • These changes do not require tests because this is just migration to a lifetimed API

This change is Reviewable

@jdm
Copy link
Member

jdm commented Mar 8, 2018

The build appears unbroken, which honestly makes me extremely skeptical!

@jdm
Copy link
Member

jdm commented Mar 8, 2018

Cargo.lock contains this modification:

+[[patch.unused]]
+name = "mozjs"
+version = "0.1.13"
+source = "git+https://github.com/marmistrz/rust-mozjs#43316429560aecc3abdf807d56eb4ac1a0912e60"

which means the updated rust-mozjs wasn't used.

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 8, 2018
@marmistrz
Copy link
Contributor Author

marmistrz commented Mar 8, 2018

Thanks! Why was explicit cargo update needed? Where did you find this modification to Cargo.lock?

@jdm
Copy link
Member

jdm commented Mar 8, 2018

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.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #20216) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Mar 12, 2018
@marmistrz marmistrz force-pushed the test-lifetime-handles branch 3 times, most recently from 1b872a1 to 4946b19 Compare March 14, 2018 20:38
@marmistrz marmistrz closed this Mar 23, 2018
@marmistrz marmistrz force-pushed the test-lifetime-handles branch from 4946b19 to 91398cf Compare March 23, 2018 14:36
@marmistrz marmistrz reopened this Mar 27, 2018
@marmistrz marmistrz force-pushed the test-lifetime-handles branch from 525e924 to 9f5ecd5 Compare March 27, 2018 17:22
@marmistrz marmistrz changed the title [Do not merge] A dummy PR to track if servo/rust-mozjs#393 doesn't break servo Adapt servo for servo/rust-mozjs#393 changes Mar 27, 2018
@jdm jdm changed the title Adapt servo for servo/rust-mozjs#393 changes Use higher level handles from JS bindings Mar 27, 2018
@jdm jdm removed the S-needs-rebase There are merge conflict errors. label Mar 27, 2018
@@ -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) {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

@marmistrz marmistrz Mar 27, 2018

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.

Copy link
Member

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(
Copy link
Member

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,
Copy link
Member

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?

Copy link
Contributor Author

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,
Copy link
Member

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?

Copy link
Contributor Author

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};

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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());
Copy link
Member

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());
Copy link
Member

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?
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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())
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@@ -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>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space before [

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 27, 2018
@jdm
Copy link
Member

jdm commented Mar 27, 2018

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit 5dc2d25 with merge ce6a8b5...

bors-servo pushed a commit that referenced this pull request Mar 27, 2018
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 -->
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Mar 27, 2018
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #20430) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-tests-failed The changes caused existing tests to fail. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 28, 2018
@jdm jdm removed S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors. S-tests-failed The changes caused existing tests to fail. labels Mar 28, 2018
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-css

@highfive highfive added S-tests-failed The changes caused existing tests to fail. S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Mar 28, 2018
@jdm jdm added S-fails-tidy `./mach test-tidy` reported errors. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 28, 2018
@marmistrz marmistrz force-pushed the test-lifetime-handles branch from 3bd097f to 356c57e Compare March 28, 2018 19:28
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 28, 2018
@marmistrz
Copy link
Contributor Author

marmistrz commented Mar 28, 2018

@jdm squashed and ready to merge. ./mach test-tidy --all returns no issues on my local machine.

@jdm
Copy link
Member

jdm commented Mar 28, 2018

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 356c57e has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-squash Some (or all) of the commits in the PR should be combined. labels Mar 28, 2018
@bors-servo
Copy link
Contributor

⌛ Testing commit 356c57e with merge 9149524...

bors-servo pushed a commit that referenced this pull request Mar 28, 2018
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 -->
@bors-servo
Copy link
Contributor

☀️ 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
Approved by: jdm
Pushing 9149524 to master...

@bors-servo bors-servo merged commit 356c57e into servo:master Mar 28, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 28, 2018
@jdm
Copy link
Member

jdm commented Mar 28, 2018

Exciting! Thanks for pushing through all the problems @marmistrz!

bors-servo pushed a commit to servo/rust-mozjs that referenced this pull request Apr 5, 2018
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-fails-tidy `./mach test-tidy` reported errors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants