aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2014-10-16 08:45:19 -0600
committerbors-servo <metajack+bors@gmail.com>2014-10-16 08:45:19 -0600
commit5be4f40bef05c749bdb5353541abae21a826f6b6 (patch)
tree09484a87d55f4f5e622faeb0b1e92d7404c95312 /components/script
parentb80b18f1cb95966dabb7b1ce9fa8c643a798c4ba (diff)
parentb60a601f56b27afa4aeff47a082bd3bbaf2431c1 (diff)
downloadservo-5be4f40bef05c749bdb5353541abae21a826f6b6.tar.gz
servo-5be4f40bef05c749bdb5353541abae21a826f6b6.zip
auto merge of #3699 : Ms2ger/servo/jsstring_to_str, r=jdm
This appears to be a more sensible location for them. Relevant to #433.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py2
-rw-r--r--components/script/dom/bindings/conversions.rs28
-rw-r--r--components/script/dom/bindings/utils.rs27
3 files changed, 27 insertions, 30 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index bca334de6ea..a6e4fcd6ebc 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -4530,7 +4530,6 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}',
'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}',
'dom::bindings::utils::{HasPropertyOnPrototype, IntVal}',
- 'dom::bindings::utils::{jsid_to_str}',
'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
@@ -4544,6 +4543,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}',
'dom::bindings::conversions::IDLInterface',
'dom::bindings::conversions::{Default, Empty}',
+ 'dom::bindings::conversions::jsid_to_str',
'dom::bindings::codegen::{PrototypeList, RegisterBindings, UnionTypes}',
'dom::bindings::codegen::Bindings::*',
'dom::bindings::error::{FailureUnknown, Fallible, Error, ErrorResult}',
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 2afd91fd08b..30bc810e44f 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -7,11 +7,12 @@
use dom::bindings::js::{JS, JSRef, Root};
use dom::bindings::str::ByteString;
use dom::bindings::utils::{Reflectable, Reflector};
-use dom::bindings::utils::jsstring_to_str;
use dom::bindings::utils::unwrap_jsmanaged;
use servo_util::str::DOMString;
-use js::jsapi::{JSBool, JSContext, JSObject};
+use js::glue::{RUST_JSID_TO_STRING, RUST_JSID_IS_STRING};
+use js::glue::RUST_JS_NumberValue;
+use js::jsapi::{JSBool, JSContext, JSObject, JSString, jsid};
use js::jsapi::{JS_ValueToUint64, JS_ValueToInt64};
use js::jsapi::{JS_ValueToECMAUint32, JS_ValueToECMAInt32};
use js::jsapi::{JS_ValueToUint16, JS_ValueToNumber, JS_ValueToBoolean};
@@ -21,7 +22,7 @@ use js::jsapi::{JS_WrapValue};
use js::jsval::JSVal;
use js::jsval::{UndefinedValue, NullValue, BooleanValue, Int32Value, UInt32Value};
use js::jsval::{StringValue, ObjectValue, ObjectOrNullValue};
-use js::glue::RUST_JS_NumberValue;
+
use libc;
use std::default;
use std::slice;
@@ -252,6 +253,27 @@ impl default::Default for StringificationBehavior {
}
}
+/// Convert the given `JSString` to a `DOMString`. Fails if the string does not
+/// contain valid UTF-16.
+pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
+ unsafe {
+ let mut length = 0;
+ let chars = JS_GetStringCharsAndLength(cx, s, &mut length);
+ slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
+ String::from_utf16(char_vec).unwrap()
+ })
+ }
+}
+
+/// Convert the given `jsid` to a `DOMString`. Fails if the `jsid` is not a
+/// string, or if the string does not contain valid UTF-16.
+pub fn jsid_to_str(cx: *mut JSContext, id: jsid) -> DOMString {
+ unsafe {
+ assert!(RUST_JSID_IS_STRING(id) != 0);
+ jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
+ }
+}
+
impl FromJSValConvertible<StringificationBehavior> for DOMString {
fn from_jsval(cx: *mut JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result<DOMString, ()> {
if nullBehavior == Empty && value.is_null() {
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 082172a1f60..4d94410216f 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -12,7 +12,6 @@ use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, Temporary, Root};
use dom::browsercontext;
use dom::window;
-use servo_util::str::DOMString;
use libc;
use libc::c_uint;
@@ -20,11 +19,9 @@ use std::cell::Cell;
use std::mem;
use std::cmp::PartialEq;
use std::ptr;
-use std::slice;
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
use js::glue::{UnwrapObject, GetProxyHandlerExtra};
-use js::glue::{IsWrapper, RUST_JSID_TO_STRING, RUST_JSID_IS_INT};
-use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_INT};
+use js::glue::{IsWrapper, RUST_JSID_IS_INT, RUST_JSID_TO_INT};
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction};
use js::jsapi::{JS_DefineProperties, JS_ForwardGetPropertyTo};
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
@@ -37,7 +34,6 @@ use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass};
use js::jsapi::{JSFunctionSpec, JSPropertySpec};
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
-use js::jsapi::{JSString};
use js::jsapi::JS_DeletePropertyById2;
use js::jsfriendapi::JS_ObjectToOuterObject;
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
@@ -161,27 +157,6 @@ pub unsafe fn squirrel_away_unique<T>(x: Box<T>) -> *const T {
mem::transmute(x)
}
-/// Convert the given `JSString` to a `DOMString`. Fails if the string does not
-/// contain valid UTF-16.
-pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
- unsafe {
- let mut length = 0;
- let chars = JS_GetStringCharsAndLength(cx, s, &mut length);
- slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
- String::from_utf16(char_vec).unwrap()
- })
- }
-}
-
-/// Convert the given `jsid` to a `DOMString`. Fails if the `jsid` is not a
-/// string, or if the string does not contain valid UTF-16.
-pub fn jsid_to_str(cx: *mut JSContext, id: jsid) -> DOMString {
- unsafe {
- assert!(RUST_JSID_IS_STRING(id) != 0);
- jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
- }
-}
-
/// The index of the slot wherein a pointer to the reflected DOM object is
/// stored for non-proxy bindings.
// We use slot 0 for holding the raw object. This is safe for both