mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Auto merge of #12954 - GuillaumeGomez:dictionary_error, r=nox
Update rust-mozjs <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12954) <!-- Reviewable:end -->
This commit is contained in:
commit
3c4a08c016
9 changed files with 137 additions and 65 deletions
|
@ -12,7 +12,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
|||
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
||||
use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::conversions::{FromJSValConvertible, jsstring_to_str};
|
||||
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, jsstring_to_str};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::Root;
|
||||
|
@ -45,8 +45,11 @@ pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<Eva
|
|||
} 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())
|
||||
EvaluateJSReply::NumberValue(
|
||||
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
|
||||
Ok(ConversionResult::Success(v)) => v,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
} else if rval.is_string() {
|
||||
EvaluateJSReply::StringValue(String::from(jsstring_to_str(cx, rval.to_string())))
|
||||
} else if rval.is_null() {
|
||||
|
|
|
@ -727,9 +727,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||
|
||||
templateBody = ("match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
||||
" Ok(value) => value,\n"
|
||||
" Err(()) => { %s },\n"
|
||||
"}" % (config, exceptionCode))
|
||||
" Ok(ConversionResult::Success(value)) => value,\n"
|
||||
" Ok(ConversionResult::Failure(error)) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" %s\n"
|
||||
" }\n"
|
||||
" _ => { %s },\n"
|
||||
"}" % (config, exceptionCode, exceptionCode))
|
||||
|
||||
return handleOptional(templateBody, declType, handleDefaultNull("None"))
|
||||
|
||||
|
@ -739,9 +743,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||
|
||||
templateBody = ("match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||
" Ok(value) => value,\n"
|
||||
" Err(()) => { %s },\n"
|
||||
"}" % exceptionCode)
|
||||
" Ok(ConversionResult::Success(value)) => value,\n"
|
||||
" Ok(ConversionResult::Failure(error)) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" %s\n"
|
||||
" }\n"
|
||||
" _ => { %s },\n"
|
||||
"}" % (exceptionCode, exceptionCode))
|
||||
|
||||
return handleOptional(templateBody, declType, handleDefaultNull("None"))
|
||||
|
||||
|
@ -810,9 +818,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
|
||||
conversionCode = (
|
||||
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
||||
" Ok(strval) => strval,\n"
|
||||
" Err(_) => { %s },\n"
|
||||
"}" % (nullBehavior, exceptionCode))
|
||||
" Ok(ConversionResult::Success(strval)) => strval,\n"
|
||||
" Ok(ConversionResult::Failure(error)) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" %s\n"
|
||||
" }\n"
|
||||
" _ => { %s },\n"
|
||||
"}" % (nullBehavior, exceptionCode, exceptionCode))
|
||||
|
||||
if defaultValue is None:
|
||||
default = None
|
||||
|
@ -836,9 +848,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
|
||||
conversionCode = (
|
||||
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||
" Ok(strval) => strval,\n"
|
||||
" Err(_) => { %s },\n"
|
||||
"}" % exceptionCode)
|
||||
" Ok(ConversionResult::Success(strval)) => strval,\n"
|
||||
" Ok(ConversionResult::Failure(error)) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" %s\n"
|
||||
" }\n"
|
||||
" _ => { %s },\n"
|
||||
"}" % (exceptionCode, exceptionCode))
|
||||
|
||||
if defaultValue is None:
|
||||
default = None
|
||||
|
@ -862,9 +878,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
|
||||
conversionCode = (
|
||||
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||
" Ok(strval) => strval,\n"
|
||||
" Err(_) => { %s },\n"
|
||||
"}" % exceptionCode)
|
||||
" Ok(ConversionResult::Success(strval)) => strval,\n"
|
||||
" Ok(ConversionResult::Failure(error)) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" %s\n"
|
||||
" }\n"
|
||||
" _ => { %s },\n"
|
||||
"}" % (exceptionCode, exceptionCode))
|
||||
|
||||
if defaultValue is None:
|
||||
default = None
|
||||
|
@ -1017,9 +1037,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
CGDictionary.makeDictionaryName(type.inner))
|
||||
declType = CGGeneric(typeName)
|
||||
template = ("match %s::new(cx, ${val}) {\n"
|
||||
" Ok(dictionary) => dictionary,\n"
|
||||
" Err(_) => { %s },\n"
|
||||
"}" % (typeName, exceptionCode))
|
||||
" Ok(ConversionResult::Success(dictionary)) => dictionary,\n"
|
||||
" Ok(ConversionResult::Failure(error)) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" %s\n"
|
||||
" }\n"
|
||||
" _ => { %s },\n"
|
||||
"}" % (typeName, exceptionCode, exceptionCode))
|
||||
|
||||
return handleOptional(template, declType, handleDefaultNull("%s::empty(cx)" % typeName))
|
||||
|
||||
|
@ -1042,9 +1066,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
|
||||
template = (
|
||||
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
||||
" Ok(v) => v,\n"
|
||||
" Err(_) => { %s }\n"
|
||||
"}" % (conversionBehavior, exceptionCode))
|
||||
" Ok(ConversionResult::Success(v)) => v,\n"
|
||||
" Ok(ConversionResult::Failure(error)) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" %s\n"
|
||||
" }\n"
|
||||
" _ => { %s }\n"
|
||||
"}" % (conversionBehavior, exceptionCode, exceptionCode))
|
||||
|
||||
if defaultValue is not None:
|
||||
if isinstance(defaultValue, IDLNullValue):
|
||||
|
@ -2048,6 +2076,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
|
|||
|
||||
imports = [
|
||||
'dom::bindings::codegen::PrototypeList',
|
||||
'dom::bindings::conversions::ConversionResult',
|
||||
'dom::bindings::conversions::FromJSValConvertible',
|
||||
'dom::bindings::conversions::ToJSValConvertible',
|
||||
'dom::bindings::conversions::ConversionBehavior',
|
||||
|
@ -2057,6 +2086,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
|
|||
'dom::bindings::js::Root',
|
||||
'dom::bindings::str::{ByteString, DOMString, USVString}',
|
||||
'dom::types::*',
|
||||
'js::error::throw_type_error',
|
||||
'js::jsapi::JSContext',
|
||||
'js::jsapi::{HandleValue, MutableHandleValue}',
|
||||
'js::jsval::JSVal',
|
||||
|
@ -3826,7 +3856,7 @@ class CGUnionConversionStruct(CGThing):
|
|||
return (
|
||||
"match %s::TryConvertTo%s(cx, value) {\n"
|
||||
" Err(_) => return Err(()),\n"
|
||||
" Ok(Some(value)) => return Ok(%s::%s(value)),\n"
|
||||
" Ok(Some(value)) => return Ok(ConversionResult::Success(%s::%s(value))),\n"
|
||||
" Ok(None) => (),\n"
|
||||
"}\n") % (self.type, name, self.type, name)
|
||||
|
||||
|
@ -3923,7 +3953,8 @@ class CGUnionConversionStruct(CGThing):
|
|||
method = CGWrapper(
|
||||
CGIndenter(CGList(conversions, "\n\n")),
|
||||
pre="unsafe fn from_jsval(cx: *mut JSContext,\n"
|
||||
" value: HandleValue, _option: ()) -> Result<%s, ()> {\n" % self.type,
|
||||
" value: HandleValue, _option: ())"
|
||||
" -> Result<ConversionResult<%s>, ()> {\n" % self.type,
|
||||
post="\n}")
|
||||
return CGWrapper(
|
||||
CGIndenter(CGList([
|
||||
|
@ -5271,9 +5302,14 @@ class CGDictionary(CGThing):
|
|||
def impl(self):
|
||||
d = self.dictionary
|
||||
if d.parent:
|
||||
initParent = "parent: try!(%s::%s::new(cx, val)),\n" % (
|
||||
self.makeModuleName(d.parent),
|
||||
self.makeClassName(d.parent))
|
||||
initParent = ("parent: match try!(%s::%s::new(cx, val)) {\n"
|
||||
" ConversionResult::Success(v) => v,\n"
|
||||
" ConversionResult::Failure(error) => {\n"
|
||||
" throw_type_error(cx, &error);\n"
|
||||
" return Err(());\n"
|
||||
" }\n"
|
||||
" },\n" % (self.makeModuleName(d.parent),
|
||||
self.makeClassName(d.parent)))
|
||||
else:
|
||||
initParent = ""
|
||||
|
||||
|
@ -5307,9 +5343,13 @@ class CGDictionary(CGThing):
|
|||
return string.Template(
|
||||
"impl ${selfName} {\n"
|
||||
" pub unsafe fn empty(cx: *mut JSContext) -> ${selfName} {\n"
|
||||
" ${selfName}::new(cx, HandleValue::null()).unwrap()\n"
|
||||
" match ${selfName}::new(cx, HandleValue::null()) {\n"
|
||||
" Ok(ConversionResult::Success(v)) => v,\n"
|
||||
" _ => unreachable!(),\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" pub unsafe fn new(cx: *mut JSContext, val: HandleValue) -> Result<${selfName}, ()> {\n"
|
||||
" pub unsafe fn new(cx: *mut JSContext, val: HandleValue) \n"
|
||||
" -> Result<ConversionResult<${selfName}>, ()> {\n"
|
||||
" let object = if val.get().is_null_or_undefined() {\n"
|
||||
" ptr::null_mut()\n"
|
||||
" } else if val.get().is_object() {\n"
|
||||
|
@ -5319,17 +5359,17 @@ class CGDictionary(CGThing):
|
|||
" return Err(());\n"
|
||||
" };\n"
|
||||
" rooted!(in(cx) let object = object);\n"
|
||||
" Ok(${selfName} {\n"
|
||||
" Ok(ConversionResult::Success(${selfName} {\n"
|
||||
"${initParent}"
|
||||
"${initMembers}"
|
||||
" })\n"
|
||||
" }))\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"impl FromJSValConvertible for ${selfName} {\n"
|
||||
" type Config = ();\n"
|
||||
" unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _option: ())\n"
|
||||
" -> Result<${selfName}, ()> {\n"
|
||||
" -> Result<ConversionResult<${selfName}>, ()> {\n"
|
||||
" ${selfName}::new(cx, value)\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
|
@ -5572,7 +5612,7 @@ class CGBindingRoot(CGThing):
|
|||
'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}',
|
||||
'dom::bindings::callback::{CallSetup,ExceptionHandling}',
|
||||
'dom::bindings::callback::wrap_call_this_object',
|
||||
'dom::bindings::conversions::{ConversionBehavior, DOM_OBJECT_SLOT}',
|
||||
'dom::bindings::conversions::{ConversionBehavior, ConversionResult, DOM_OBJECT_SLOT}',
|
||||
'dom::bindings::conversions::{IDLInterface, is_array_like}',
|
||||
'dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior}',
|
||||
'dom::bindings::conversions::{ToJSValConvertible, jsid_to_str, native_from_handlevalue}',
|
||||
|
|
|
@ -39,7 +39,8 @@ use dom::bindings::reflector::{Reflectable, Reflector};
|
|||
use dom::bindings::str::{ByteString, DOMString, USVString};
|
||||
use dom::bindings::utils::DOMClass;
|
||||
use js;
|
||||
pub use js::conversions::{FromJSValConvertible, ToJSValConvertible, ConversionBehavior};
|
||||
pub use js::conversions::{FromJSValConvertible, ToJSValConvertible, ConversionResult};
|
||||
pub use js::conversions::ConversionBehavior;
|
||||
use js::conversions::latin1_to_string;
|
||||
use js::error::throw_type_error;
|
||||
use js::glue::{GetProxyPrivate, IsWrapper};
|
||||
|
@ -81,10 +82,17 @@ impl<T: Float + FromJSValConvertible<Config=()>> FromJSValConvertible for Finite
|
|||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
option: ())
|
||||
-> Result<Finite<T>, ()> {
|
||||
let result = try!(FromJSValConvertible::from_jsval(cx, value, option));
|
||||
-> Result<ConversionResult<Finite<T>>, ()> {
|
||||
let result = match FromJSValConvertible::from_jsval(cx, value, option) {
|
||||
Ok(ConversionResult::Success(v)) => v,
|
||||
Ok(ConversionResult::Failure(error)) => {
|
||||
throw_type_error(cx, &error);
|
||||
return Err(());
|
||||
}
|
||||
_ => return Err(()),
|
||||
};
|
||||
match Finite::new(result) {
|
||||
Some(v) => Ok(v),
|
||||
Some(v) => Ok(ConversionResult::Success(v)),
|
||||
None => {
|
||||
throw_type_error(cx, "this argument is not a finite floating-point value");
|
||||
Err(())
|
||||
|
@ -99,12 +107,12 @@ impl <T: Reflectable + IDLInterface> FromJSValConvertible for Root<T> {
|
|||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
_config: Self::Config)
|
||||
-> Result<Root<T>, ()> {
|
||||
-> Result<ConversionResult<Root<T>>, ()> {
|
||||
let result = root_from_handlevalue(value);
|
||||
if let Err(()) = result {
|
||||
throw_type_error(cx, "value is not an object");
|
||||
}
|
||||
result
|
||||
result.map(ConversionResult::Success)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,17 +154,17 @@ impl FromJSValConvertible for DOMString {
|
|||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
null_behavior: StringificationBehavior)
|
||||
-> Result<DOMString, ()> {
|
||||
-> Result<ConversionResult<DOMString>, ()> {
|
||||
if null_behavior == StringificationBehavior::Empty &&
|
||||
value.get().is_null() {
|
||||
Ok(DOMString::new())
|
||||
Ok(ConversionResult::Success(DOMString::new()))
|
||||
} else {
|
||||
let jsstr = ToString(cx, value);
|
||||
if jsstr.is_null() {
|
||||
debug!("ToString failed");
|
||||
Err(())
|
||||
} else {
|
||||
Ok(jsstring_to_str(cx, jsstr))
|
||||
Ok(ConversionResult::Success(jsstring_to_str(cx, jsstr)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +211,8 @@ pub unsafe fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString
|
|||
// http://heycam.github.io/webidl/#es-USVString
|
||||
impl FromJSValConvertible for USVString {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _: ()) -> Result<USVString, ()> {
|
||||
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _: ())
|
||||
-> Result<ConversionResult<USVString>, ()> {
|
||||
let jsstr = ToString(cx, value);
|
||||
if jsstr.is_null() {
|
||||
debug!("ToString failed");
|
||||
|
@ -212,13 +221,14 @@ impl FromJSValConvertible for USVString {
|
|||
let latin1 = JS_StringHasLatin1Chars(jsstr);
|
||||
if latin1 {
|
||||
// FIXME(ajeffrey): Convert directly from DOMString to USVString
|
||||
return Ok(USVString(String::from(jsstring_to_str(cx, jsstr))));
|
||||
return Ok(ConversionResult::Success(
|
||||
USVString(String::from(jsstring_to_str(cx, jsstr)))));
|
||||
}
|
||||
let mut length = 0;
|
||||
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), jsstr, &mut length);
|
||||
assert!(!chars.is_null());
|
||||
let char_vec = slice::from_raw_parts(chars as *const u16, length as usize);
|
||||
Ok(USVString(String::from_utf16_lossy(char_vec)))
|
||||
Ok(ConversionResult::Success(USVString(String::from_utf16_lossy(char_vec))))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,7 +251,7 @@ impl FromJSValConvertible for ByteString {
|
|||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
_option: ())
|
||||
-> Result<ByteString, ()> {
|
||||
-> Result<ConversionResult<ByteString>, ()> {
|
||||
let string = ToString(cx, value);
|
||||
if string.is_null() {
|
||||
debug!("ToString failed");
|
||||
|
@ -255,7 +265,7 @@ impl FromJSValConvertible for ByteString {
|
|||
assert!(!chars.is_null());
|
||||
|
||||
let char_slice = slice::from_raw_parts(chars as *mut u8, length as usize);
|
||||
return Ok(ByteString::new(char_slice.to_vec()));
|
||||
return Ok(ConversionResult::Success(ByteString::new(char_slice.to_vec())));
|
||||
}
|
||||
|
||||
let mut length = 0;
|
||||
|
@ -266,7 +276,8 @@ impl FromJSValConvertible for ByteString {
|
|||
throw_type_error(cx, "Invalid ByteString");
|
||||
Err(())
|
||||
} else {
|
||||
Ok(ByteString::new(char_vec.iter().map(|&c| c as u8).collect()))
|
||||
Ok(ConversionResult::Success(
|
||||
ByteString::new(char_vec.iter().map(|&c| c as u8).collect())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionMethods;
|
||||
use dom::bindings::codegen::PrototypeList::proto_id_to_name;
|
||||
use dom::bindings::conversions::root_from_object;
|
||||
use dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible};
|
||||
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::str::USVString;
|
||||
use dom::domexception::{DOMErrorName, DOMException};
|
||||
|
@ -207,8 +207,8 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) {
|
|||
JS_ClearPendingException(cx);
|
||||
if !value.is_object() {
|
||||
match USVString::from_jsval(cx, value.handle(), ()) {
|
||||
Ok(USVString(string)) => error!("Uncaught exception: {}", string),
|
||||
Err(_) => error!("Uncaught exception: failed to stringify primitive"),
|
||||
Ok(ConversionResult::Success(USVString(string))) => error!("Uncaught exception: {}", string),
|
||||
_ => error!("Uncaught exception: failed to stringify primitive"),
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding;
|
|||
use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods;
|
||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes;
|
||||
use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext;
|
||||
use dom::bindings::conversions::ConversionResult;
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
|
@ -27,6 +28,7 @@ use euclid::size::Size2D;
|
|||
use image::ColorType;
|
||||
use image::png::PNGEncoder;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use js::error::throw_type_error;
|
||||
use js::jsapi::{HandleValue, JSContext};
|
||||
use offscreen_gl_context::GLContextAttributes;
|
||||
use rustc_serialize::base64::{STANDARD, ToBase64};
|
||||
|
@ -159,11 +161,17 @@ impl HTMLCanvasElement {
|
|||
let size = self.get_size();
|
||||
|
||||
let attrs = if let Some(webgl_attributes) = attrs {
|
||||
if let Ok(ref attrs) = unsafe { WebGLContextAttributes::new(cx, webgl_attributes) } {
|
||||
From::from(attrs)
|
||||
} else {
|
||||
debug!("Unexpected error on conversion of WebGLContextAttributes");
|
||||
return None;
|
||||
match unsafe {
|
||||
WebGLContextAttributes::new(cx, webgl_attributes) } {
|
||||
Ok(ConversionResult::Success(ref attrs)) => From::from(attrs),
|
||||
Ok(ConversionResult::Failure(ref error)) => {
|
||||
unsafe { throw_type_error(cx, &error); }
|
||||
return None;
|
||||
}
|
||||
_ => {
|
||||
debug!("Unexpected error on conversion of WebGLContextAttributes");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GLContextAttributes::default()
|
||||
|
|
|
@ -26,7 +26,7 @@ use dom::bindings::cell::DOMRefCell;
|
|||
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
||||
use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior};
|
||||
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root, RootCollection};
|
||||
|
@ -1789,7 +1789,10 @@ impl ScriptThread {
|
|||
let strval = DOMString::from_jsval(self.get_cx(),
|
||||
jsval.handle(),
|
||||
StringificationBehavior::Empty);
|
||||
strval.unwrap_or(DOMString::new())
|
||||
match strval {
|
||||
Ok(ConversionResult::Success(s)) => s,
|
||||
_ => DOMString::new(),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DOMString::new()
|
||||
|
|
|
@ -12,7 +12,7 @@ use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElemen
|
|||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior};
|
||||
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::str::DOMString;
|
||||
|
@ -59,10 +59,17 @@ pub unsafe fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDri
|
|||
} else if val.get().is_boolean() {
|
||||
Ok(WebDriverJSValue::Boolean(val.get().to_boolean()))
|
||||
} else if val.get().is_double() || val.get().is_int32() {
|
||||
Ok(WebDriverJSValue::Number(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
|
||||
Ok(WebDriverJSValue::Number(match FromJSValConvertible::from_jsval(cx, val, ()).unwrap() {
|
||||
ConversionResult::Success(c) => c,
|
||||
_ => unreachable!(),
|
||||
}))
|
||||
} else if val.get().is_string() {
|
||||
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
||||
let string: DOMString = FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap();
|
||||
let string: DOMString = match FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default)
|
||||
.unwrap() {
|
||||
ConversionResult::Success(c) => c,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
Ok(WebDriverJSValue::String(String::from(string)))
|
||||
} else if val.get().is_null() {
|
||||
Ok(WebDriverJSValue::Null)
|
||||
|
|
2
components/servo/Cargo.lock
generated
2
components/servo/Cargo.lock
generated
|
@ -1086,7 +1086,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "js"
|
||||
version = "0.1.3"
|
||||
source = "git+https://github.com/servo/rust-mozjs#755c8cc8cac7f6e51985c41507bac300d11e416e"
|
||||
source = "git+https://github.com/servo/rust-mozjs#daffcfb1e0568b3e67dda331b487cc9fd8a202cb"
|
||||
dependencies = [
|
||||
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
2
ports/cef/Cargo.lock
generated
2
ports/cef/Cargo.lock
generated
|
@ -994,7 +994,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "js"
|
||||
version = "0.1.3"
|
||||
source = "git+https://github.com/servo/rust-mozjs#755c8cc8cac7f6e51985c41507bac300d11e416e"
|
||||
source = "git+https://github.com/servo/rust-mozjs#daffcfb1e0568b3e67dda331b487cc9fd8a202cb"
|
||||
dependencies = [
|
||||
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue