aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py9
-rw-r--r--src/components/script/dom/bindings/conversions.rs19
-rw-r--r--src/components/script/dom/bindings/utils.rs20
3 files changed, 23 insertions, 25 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index 28ef759a70f..6b377dae22a 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1535,10 +1535,7 @@ for (uint32_t i = 0; i < length; ++i) {
return (wrappingCode, False)
if type.isString():
- if type.nullable():
- return (wrapAndSetPtr("*${jsvalPtr} = domstring_to_jsval(cx, %s)" % result), False)
- else:
- return (wrapAndSetPtr("*${jsvalPtr} = str_to_jsval(cx, %s)" % result), False)
+ return (setValue("(%s).to_jsval(cx)" % result), True)
if type.isEnum():
if type.nullable():
@@ -5258,7 +5255,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}',
- 'dom::bindings::utils::{DOMJSClass, domstring_to_jsval, Empty}',
+ 'dom::bindings::utils::{DOMJSClass, Empty}',
'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}',
'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}',
'dom::bindings::utils::{GetReflector, HasPropertyOnPrototype, IntVal}',
@@ -5266,7 +5263,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{NativePropertyHooks}',
'dom::bindings::utils::global_object_for_js_object',
'dom::bindings::utils::{Reflectable}',
- 'dom::bindings::utils::{squirrel_away_unique, str_to_jsval}',
+ 'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}',
'dom::bindings::utils::{with_gc_enabled, XrayResolveProperty}',
diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs
index acceed4c6bb..faf7d1c852e 100644
--- a/src/components/script/dom/bindings/conversions.rs
+++ b/src/components/script/dom/bindings/conversions.rs
@@ -2,13 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use servo_util::str::DOMString;
+
use js::jsapi::{JSBool, JSContext};
use js::jsapi::{JS_ValueToUint64, JS_ValueToInt64};
use js::jsapi::{JS_ValueToECMAUint32, JS_ValueToECMAInt32};
use js::jsapi::{JS_ValueToUint16, JS_ValueToNumber, JS_ValueToBoolean};
+use js::jsapi::{JS_NewUCStringCopyN};
use js::jsval::JSVal;
-use js::jsval::{NullValue, BooleanValue, Int32Value, UInt32Value};
+use js::jsval::{NullValue, BooleanValue, Int32Value, UInt32Value, StringValue};
use js::glue::RUST_JS_NumberValue;
+use std::libc;
pub trait ToJSValConvertible {
fn to_jsval(&self, cx: *JSContext) -> JSVal;
@@ -176,6 +180,19 @@ impl FromJSValConvertible<()> for f64 {
}
}
+impl ToJSValConvertible for DOMString {
+ fn to_jsval(&self, cx: *JSContext) -> JSVal {
+ unsafe {
+ let string_utf16 = self.to_utf16();
+ let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t);
+ if jsstr.is_null() {
+ fail!("JS_NewUCStringCopyN failed");
+ }
+ StringValue(&*jsstr)
+ }
+ }
+}
+
impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
fn to_jsval(&self, cx: *JSContext) -> JSVal {
match self {
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs
index c4506f96855..24bd910ff00 100644
--- a/src/components/script/dom/bindings/utils.rs
+++ b/src/components/script/dom/bindings/utils.rs
@@ -26,7 +26,7 @@ use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAn
use js::jsapi::{JS_ObjectIsRegExp, JS_ObjectIsDate};
use js::jsapi::{JS_InternString, JS_GetFunctionObject};
use js::jsapi::{JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject};
-use js::jsapi::{JS_NewUCStringCopyN, JS_DefineFunctions, JS_DefineProperty};
+use js::jsapi::{JS_DefineFunctions, JS_DefineProperty};
use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative};
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSPropertyDescriptor};
@@ -35,7 +35,7 @@ use js::jsapi::{JSString};
use js::jsapi::{JS_AllowGC, JS_InhibitGC};
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
use js::jsval::JSVal;
-use js::jsval::{StringValue, PrivateValue, ObjectValue, NullValue, Int32Value};
+use js::jsval::{PrivateValue, ObjectValue, NullValue, Int32Value};
use js::jsval::{UInt32Value, DoubleValue, BooleanValue, UndefinedValue};
use js::{JSPROP_ENUMERATE, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
@@ -196,22 +196,6 @@ pub fn jsval_to_domstring(cx: *JSContext, v: JSVal) -> Result<Option<DOMString>,
}
}
-pub unsafe fn str_to_jsval(cx: *JSContext, string: DOMString) -> JSVal {
- let string_utf16 = string.to_utf16();
- let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t);
- if jsstr.is_null() {
- fail!("JS_NewUCStringCopyN failed");
- }
- StringValue(&*jsstr)
-}
-
-pub unsafe fn domstring_to_jsval(cx: *JSContext, string: Option<DOMString>) -> JSVal {
- match string {
- None => NullValue(),
- Some(s) => str_to_jsval(cx, s),
- }
-}
-
// We use slot 0 for holding the raw object. This is safe for both
// globals and non-globals.
pub static DOM_OBJECT_SLOT: uint = 0;