Skip to content
This repository was archived by the owner on Nov 12, 2022. It is now read-only.

Commit d5aabe3

Browse files
author
bors-servo
authored
Auto merge of #390 - servo:nonnull, r=jdm
Add a conversion from the newly-#[stable] `ptr::NonNull` type This will allow removing the `NonNullJSObjectPtr` hack in Servo, but raises the minimum Rust version to 1.25 (currently Nigthly) <!-- 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/390) <!-- Reviewable:end -->
2 parents d829b21 + 5a68234 commit d5aabe3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs"
33
description = "Rust bindings to the Mozilla SpiderMonkey JavaScript engine."
44
repository = "https://github.com/servo/rust-mozjs"
5-
version = "0.1.10"
5+
version = "0.1.11"
66
authors = ["The Servo Project Developers"]
77
build = "build.rs"
88
license = "MPL-2.0"

src/conversions.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use jsapi::{JSContext, JSObject, JSString, MutableHandleValue, RootedObject};
3838
use jsval::{BooleanValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
3939
use jsval::{JSVal, ObjectValue, ObjectOrNullValue, StringValue};
4040
use rust::{ToBoolean, ToInt32, ToInt64, ToNumber, ToUint16, ToUint32, ToUint64};
41-
use rust::{ToString, maybe_wrap_object_or_null_value};
41+
use rust::{ToString, maybe_wrap_object_or_null_value, maybe_wrap_object_value};
4242
use rust::maybe_wrap_value;
4343
use libc;
4444
use num_traits::{Bounded, Zero};
@@ -646,6 +646,15 @@ impl ToJSValConvertible for *mut JSObject {
646646
}
647647
}
648648

649+
// https://heycam.github.io/webidl/#es-object
650+
impl ToJSValConvertible for ptr::NonNull<JSObject> {
651+
#[inline]
652+
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
653+
rval.set(ObjectValue(self.as_ptr()));
654+
maybe_wrap_object_value(cx, rval);
655+
}
656+
}
657+
649658
// https://heycam.github.io/webidl/#es-object
650659
impl ToJSValConvertible for Heap<*mut JSObject> {
651660
#[inline]

0 commit comments

Comments
 (0)