mirror of
https://github.com/servo/servo.git
synced 2025-06-13 02:44:29 +00:00
Use throw_type_error and throw_range_error from js.
This commit is contained in:
parent
ddaa1a1960
commit
acb24e80b8
5 changed files with 24 additions and 92 deletions
|
@ -888,21 +888,16 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
else:
|
||||
handleInvalidEnumValueCode = "return true;"
|
||||
|
||||
transmute = "mem::transmute(index)"
|
||||
if isMember == 'Dictionary':
|
||||
transmute = 'unsafe { ' + transmute + ' }'
|
||||
|
||||
template = (
|
||||
"match find_enum_string_index(cx, ${val}, %(values)s) {\n"
|
||||
" Err(_) => { %(exceptionCode)s },\n"
|
||||
" Ok(None) => { %(handleInvalidEnumValueCode)s },\n"
|
||||
" Ok(Some(index)) => {\n"
|
||||
" //XXXjdm need some range checks up in here.\n"
|
||||
" %(transmute)s\n"
|
||||
" mem::transmute(index)\n"
|
||||
" },\n"
|
||||
"}" % {"values": enum + "Values::strings",
|
||||
"exceptionCode": exceptionCode,
|
||||
"transmute": transmute,
|
||||
"handleInvalidEnumValueCode": handleInvalidEnumValueCode})
|
||||
|
||||
if defaultValue is not None:
|
||||
|
@ -3649,7 +3644,7 @@ class CGUnionConversionStruct(CGThing):
|
|||
names.append(name)
|
||||
|
||||
conversions.append(CGGeneric(
|
||||
"throw_not_in_union(cx, \"%s\");\n"
|
||||
"unsafe { throw_not_in_union(cx, \"%s\"); }\n"
|
||||
"Err(())" % ", ".join(names)))
|
||||
method = CGWrapper(
|
||||
CGIndenter(CGList(conversions, "\n\n")),
|
||||
|
@ -4952,10 +4947,10 @@ class CGDictionary(CGThing):
|
|||
|
||||
return string.Template(
|
||||
"impl ${selfName} {\n"
|
||||
" pub fn empty(cx: *mut JSContext) -> ${selfName} {\n"
|
||||
" pub unsafe fn empty(cx: *mut JSContext) -> ${selfName} {\n"
|
||||
" ${selfName}::new(cx, HandleValue::null()).unwrap()\n"
|
||||
" }\n"
|
||||
" pub fn new(cx: *mut JSContext, val: HandleValue) -> Result<${selfName}, ()> {\n"
|
||||
" pub unsafe fn new(cx: *mut JSContext, val: HandleValue) -> Result<${selfName}, ()> {\n"
|
||||
" let object = if val.get().is_null_or_undefined() {\n"
|
||||
" RootedObject::new(cx, ptr::null_mut())\n"
|
||||
" } else if val.get().is_object() {\n"
|
||||
|
@ -5159,6 +5154,7 @@ class CGBindingRoot(CGThing):
|
|||
'js::{JSCLASS_RESERVED_SLOTS_MASK}',
|
||||
'js::{JSPROP_ENUMERATE, JSPROP_SHARED}',
|
||||
'js::{JSITER_OWNONLY, JSITER_HIDDEN, JSITER_SYMBOLS}',
|
||||
'js::error::throw_type_error',
|
||||
'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}',
|
||||
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
|
||||
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
|
||||
|
@ -5222,7 +5218,6 @@ class CGBindingRoot(CGThing):
|
|||
'dom::bindings::error::{Fallible, Error, ErrorResult}',
|
||||
'dom::bindings::error::Error::JSFailed',
|
||||
'dom::bindings::error::throw_dom_exception',
|
||||
'dom::bindings::error::throw_type_error',
|
||||
'dom::bindings::proxyhandler',
|
||||
'dom::bindings::proxyhandler::{fill_property_descriptor, get_expando_object}',
|
||||
'dom::bindings::proxyhandler::{get_property_descriptor}',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue