diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-07-04 11:03:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-04 11:03:35 -0700 |
commit | 80cb0cf8214fd52d2884724614c40cb278ee7575 (patch) | |
tree | d5d98004a84375aea65a74d594dead5a27fc2392 /components/script/devtools.rs | |
parent | 36974f0746261b971c93ed7dfb9bd726675ccf69 (diff) | |
parent | b79a7d468e99f335dce49cc48342f0cd447eb855 (diff) | |
download | servo-80cb0cf8214fd52d2884724614c40cb278ee7575.tar.gz servo-80cb0cf8214fd52d2884724614c40cb278ee7575.zip |
Auto merge of #11872 - eddyb:back-to-roots, r=Ms2ger
Replace return_address usage for rooting with stack guards and convenience macros.
The existing `Rooted` and `RootedVec` users were migrated the the following two macros:
```rust
let x = Rooted::new(cx, value);
// Was changed to:
rooted!(in(cx) let x = value);
// Which expands to:
let mut __root = Rooted::new_unrooted(value);
let x = RootedGuard::new(cx, &mut __root);
```
```rust
let mut v = RootedVec::new();
v.extend(iterator);
// Was changed to:
rooted_vec!(let v <- iterator);
// Which expands to:
let mut __root = RootableVec::new();
let v = RootedVec::new(&mut __root, iterator);
```
The `rooted!` macro depends on servo/rust-mozjs#272.
These APIs based on two types, a container to be rooted and a rooting guard, allow implementing both `Rooted`-style rooting and `Traceable`-based rooting in stable Rust, without abusing `return_address`.
Such macros may have been tried before, but in 1.9 their hygiene is broken, they work only since 1.10.
Sadly, `Rooted` is a FFI type and completely exposed, so I cannot prevent anyone from creating their own, although all fields but the value get overwritten by `RootedGuard::new` anyway.
`RootableVec` OTOH is *guaranteed* to be empty when not rooted, which makes it harmless AFAICT.
By fixing rust-lang/rust#34227, this PR enables Servo to build with `-Zorbit`.
---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix rust-lang/rust#34227
- [x] These changes do not require tests because they are not functional changes
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11872)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/devtools.rs')
-rw-r--r-- | components/script/devtools.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/components/script/devtools.rs b/components/script/devtools.rs index 7533b159771..20394bf367a 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -22,7 +22,7 @@ use dom::element::Element; use dom::node::Node; use dom::window::Window; use ipc_channel::ipc::IpcSender; -use js::jsapi::{JSAutoCompartment, ObjectClassName, RootedObject, RootedValue}; +use js::jsapi::{JSAutoCompartment, ObjectClassName}; use js::jsval::UndefinedValue; use msg::constellation_msg::PipelineId; use script_thread::get_browsing_context; @@ -38,24 +38,24 @@ pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<Eva let cx = global.get_cx(); let globalhandle = global.reflector().get_jsobject(); let _ac = JSAutoCompartment::new(cx, globalhandle.get()); - let mut rval = RootedValue::new(cx, UndefinedValue()); + rooted!(in(cx) let mut rval = UndefinedValue()); global.evaluate_js_on_global_with_result(&eval, rval.handle_mut()); - if rval.ptr.is_undefined() { + if rval.is_undefined() { EvaluateJSReply::VoidValue - } else if rval.ptr.is_boolean() { - EvaluateJSReply::BooleanValue(rval.ptr.to_boolean()) - } else if rval.ptr.is_double() || rval.ptr.is_int32() { + } else if rval.is_boolean() { + EvaluateJSReply::BooleanValue(rval.to_boolean()) + } else if rval.is_double() || rval.is_int32() { EvaluateJSReply::NumberValue(FromJSValConvertible::from_jsval(cx, rval.handle(), ()) .unwrap()) - } else if rval.ptr.is_string() { - EvaluateJSReply::StringValue(String::from(jsstring_to_str(cx, rval.ptr.to_string()))) - } else if rval.ptr.is_null() { + } else if rval.is_string() { + EvaluateJSReply::StringValue(String::from(jsstring_to_str(cx, rval.to_string()))) + } else if rval.is_null() { EvaluateJSReply::NullValue } else { - assert!(rval.ptr.is_object()); + assert!(rval.is_object()); - let obj = RootedObject::new(cx, rval.ptr.to_object()); + rooted!(in(cx) let obj = rval.to_object()); let class_name = CStr::from_ptr(ObjectClassName(cx, obj.handle())); let class_name = str::from_utf8(class_name.to_bytes()).unwrap(); |