mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Replace str_to_jsval and domstring_to_jsval by a ToJSValConvertible implementation.
This commit is contained in:
parent
476699a114
commit
17411db8ca
3 changed files with 23 additions and 25 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue