Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the improved JSVal interfaces. #1868

Merged
merged 4 commits into from Mar 10, 2014
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use FooValue() functions.

  • Loading branch information
Ms2ger committed Mar 9, 2014
commit 84b0f45ed5d1e6fdff24c195699218c8743b561e
@@ -1152,7 +1152,7 @@ def getConversionCode(varName, isOptional=False):

templateBody = "${declName} = %s;" % value.define()
templateBody = handleDefaultNull(templateBody,
"${declName} = JSVAL_NULL")
"${declName} = NullValue()")

return (templateBody, declType, None, isOptional, "None" if isOptional else None)

@@ -1196,7 +1196,7 @@ def getConversionCode(varName, isOptional=False):
# actually do want a jsval, and we only handle null anyway
if defaultValue is not None:
assert(isinstance(defaultValue, IDLNullValue))
val = "if ${haveValue} { ${val} } else { JSVAL_NULL }"
val = "if ${haveValue} { ${val} } else { NullValue() }"
else:
val = "${val}"

@@ -1467,7 +1467,7 @@ def wrapAndSetPtr(wrapCall, failureCode=None):
return str

if type is None or type.isVoid():
return (setValue("JSVAL_VOID"), True)
return (setValue("UndefinedValue()"), True)

if type.isArray():
raise TypeError("Can't handle array return values yet")
@@ -1482,7 +1482,7 @@ def wrapAndSetPtr(wrapCall, failureCode=None):
if (%s.IsNull()) {
%s
}
%s""" % (result, CGIndenter(CGGeneric(setValue("JSVAL_NULL"))).define(), recTemplate), recInfall)
%s""" % (result, CGIndenter(CGGeneric(setValue("NullValue()"))).define(), recTemplate), recInfall)

# Now do non-nullable sequences. We use setting the element
# in the array as our succcess code because when we succeed in
@@ -1516,7 +1516,7 @@ def wrapAndSetPtr(wrapCall, failureCode=None):
descriptor = descriptorProvider.getDescriptor(type.unroll().inner.identifier.name)
if type.nullable():
wrappingCode = ("if %s.is_none() {\n" % (result) +
CGIndenter(CGGeneric(setValue("JSVAL_NULL"))).define() + "\n" +
CGIndenter(CGGeneric(setValue("NullValue()"))).define() + "\n" +
"}\n" +
"let mut %s = %s.unwrap();\n" % (result, result))
else:
@@ -1552,7 +1552,7 @@ def wrapAndSetPtr(wrapCall, failureCode=None):
""" % { "result" : result,
"resultStr" : result + "_str",
"strings" : type.inner.identifier.name + "Values::strings" } +
setValue("RUST_STRING_TO_JSVAL(%s_str)" % result), False)
setValue("StringValue(&*(%s_str))" % result), False)

if type.isCallback():
assert not type.isInterface()
@@ -1573,9 +1573,9 @@ def wrapAndSetPtr(wrapCall, failureCode=None):
# See comments in WrapNewBindingObject explaining why we need
# to wrap here.
if type.nullable():
toValue = "RUST_OBJECT_TO_JSVAL(%s)"
toValue = "ObjectOrNullValue(%s)"
else:
toValue = "RUST_OBJECT_TO_JSVAL(%s)"
toValue = "ObjectValue(&*(%s))"
# NB: setValue(..., True) calls JS_WrapValue(), so is fallible
return (setValue(toValue % result, True), False)

@@ -2530,7 +2530,7 @@ def CreateBindingJSObject(descriptor, parent=None):
let handler = js_info.get().get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
""" % descriptor.name
create += handler + """ let obj = NewProxyObject(aCx, *handler,
ptr::to_unsafe_ptr(&RUST_PRIVATE_TO_JSVAL(squirrel_away_unique(aObject) as *libc::c_void)),
ptr::to_unsafe_ptr(&PrivateValue(squirrel_away_unique(aObject) as *libc::c_void)),
proto, %s,
ptr::null(), ptr::null());
if obj.is_null() {
@@ -2548,7 +2548,7 @@ def CreateBindingJSObject(descriptor, parent=None):
}
JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
RUST_PRIVATE_TO_JSVAL(squirrel_away_unique(aObject) as *libc::c_void));
PrivateValue(squirrel_away_unique(aObject) as *libc::c_void));
"""
return create

@@ -3310,7 +3310,7 @@ def __init__(self, descriptor, lenientThis=False):

def generate_code(self):
return CGIndenter(CGGeneric(
"let undef = JSVAL_VOID;\n"
"let undef = UndefinedValue();\n"
"let argv: *JSVal = if argc != 0 { JS_ARGV(cx, vp as *JSVal) } else { &undef as *JSVal };\n"
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp as *JSVal));\n"
"let ok = with_gc_disabled(cx, || {\n"
@@ -3319,7 +3319,7 @@ def generate_code(self):
"if ok == 0 {\n"
" return 0;\n"
"}\n"
"*vp = JSVAL_VOID;\n"
"*vp = UndefinedValue();\n"
"return 1;"))

class CGSpecializedSetter(CGAbstractExternMethod):
@@ -4621,7 +4621,7 @@ def getBody(self):
return 1;
}
%s
*vp = JSVAL_VOID;
*vp = UndefinedValue();
return 1;""" % (getIndexedOrExpando, getNamed)

def definition_body(self):
@@ -5011,7 +5011,7 @@ def defaultValue(ty):
" }\n"
"${initParent}"
" let mut found: JSBool = 0;\n"
" let temp: JSVal = JSVAL_NULL;\n"
" let temp: JSVal = NullValue();\n"
" let isNull = RUST_JSVAL_IS_NULL(val) != 0 || RUST_JSVAL_IS_VOID(val) != 0;\n"
" if !isNull && RUST_JSVAL_IS_PRIMITIVE(val) != 0 {\n"
" return 0; //XXXjdm throw properly here\n"
@@ -5235,8 +5235,8 @@ def makeEnumTypedef(e):
'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}',
'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}',
'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}',
'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED, JSVAL_NULL}',
'js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT, JSVAL_VOID}',
'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED}',
'js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT}',
'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}',
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
@@ -5248,14 +5248,15 @@ def makeEnumTypedef(e):
'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}',
'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer}',
'js::jsval::JSVal',
'js::jsval::{ObjectValue, ObjectOrNullValue, PrivateValue}',
'js::jsval::{NullValue, UndefinedValue}',
'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}',
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
'js::glue::{RUST_BOOLEAN_TO_JSVAL, RUST_FUNCTION_VALUE_TO_JITINFO}',
'js::glue::{RUST_INT_TO_JSVAL, RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}',
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'js::glue::{RUST_JSVAL_IS_NULL, RUST_JSVAL_IS_PRIMITIVE}',
'js::glue::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT}',
'js::glue::{RUST_JSVAL_TO_PRIVATE, RUST_OBJECT_TO_JSVAL}',
'js::glue::{RUST_PRIVATE_TO_JSVAL, RUST_UINT_TO_JSVAL}',
'js::glue::{RUST_JSVAL_TO_PRIVATE}',
'dom::types::*',
'dom::bindings::js::JS',
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
@@ -5696,7 +5697,7 @@ def getMethodImpls(self, method):
# the private method.
argnames = [arg.name for arg in args]
argnamesWithThis = ["s.GetContext()", "thisObjJS"] + argnames
argnamesWithoutThis = ["s.GetContext()", "JSVAL_TO_OBJECT(JSVAL_NULL)"] + argnames
argnamesWithoutThis = ["s.GetContext()", "ptr::null()"] + argnames
# Now that we've recorded the argnames for our call to our private
# method, insert our optional argument for deciding whether the
# CallSetup should re-throw exceptions on aRv.
@@ -5861,7 +5862,7 @@ def getImpl(self):
if self.argCount > 0:
replacements["argCount"] = self.argCountStr
replacements["argvDecl"] = string.Template(
"let mut argv = vec::from_elem(${argCount}, JSVAL_VOID);\n"
"let mut argv = vec::from_elem(${argCount}, UndefinedValue());\n"
).substitute(replacements)
else:
# Avoid weird 0-sized arrays
@@ -6045,7 +6046,7 @@ def __init__(self, sig, name, descriptorProvider, needThisHandling, rethrowConte
CallbackMember.__init__(self, sig, name, descriptorProvider,
needThisHandling, rethrowContentException)
def getRvalDecl(self):
return "let mut rval = JSVAL_VOID;\n"
return "let mut rval = UndefinedValue();\n"

def getCall(self):
replacements = {
@@ -6112,9 +6113,9 @@ def getCallableDecl(self):
return 'JS::Rooted<JS::Value> callable(cx);\n' + getCallableFromProp
return (
'let isCallable = unsafe { JS_ObjectIsCallable(cx, self.parent.callback) != 0 };\n'
'let mut callable = JSVAL_VOID;\n'
'let mut callable = UndefinedValue();\n'
'if isCallable {\n'
' callable = unsafe { RUST_OBJECT_TO_JSVAL(self.parent.callback) };\n'
' callable = unsafe { ObjectValue(&*self.parent.callback) };\n'
'} else {\n'
'%s'
'}\n' % CGIndenter(CGGeneric(getCallableFromProp)).define())
@@ -6433,8 +6434,8 @@ def UnionConversions(config):
'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}',
'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}',
'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}',
'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED, JSVAL_NULL}',
'js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT, JSVAL_VOID}',
'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED}',
'js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT}',
'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}',
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
@@ -6446,14 +6447,14 @@ def UnionConversions(config):
'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}',
'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer}',
'js::jsval::JSVal',
'js::jsval::PrivateValue',
'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}',
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
'js::glue::{RUST_BOOLEAN_TO_JSVAL, RUST_FUNCTION_VALUE_TO_JITINFO}',
'js::glue::{RUST_INT_TO_JSVAL, RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}',
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'js::glue::{RUST_JSVAL_IS_NULL, RUST_JSVAL_IS_PRIMITIVE}',
'js::glue::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT}',
'js::glue::{RUST_JSVAL_TO_PRIVATE, RUST_OBJECT_TO_JSVAL}',
'js::glue::{RUST_PRIVATE_TO_JSVAL, RUST_UINT_TO_JSVAL}',], [], curr)
'js::glue::{RUST_JSVAL_TO_PRIVATE}',], [], curr)

# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@@ -7,8 +7,8 @@ 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::jsval::JSVal;
use js::{JSVAL_FALSE, JSVAL_TRUE, JSVAL_NULL};
use js::glue::{RUST_INT_TO_JSVAL, RUST_UINT_TO_JSVAL, RUST_JS_NumberValue};
use js::jsval::{NullValue, BooleanValue, Int32Value, UInt32Value};
use js::glue::RUST_JS_NumberValue;
use js::glue::{RUST_JSVAL_IS_NULL, RUST_JSVAL_IS_VOID};

pub trait JSValConvertible {
@@ -31,11 +31,7 @@ unsafe fn convert_from_jsval<T: Default>(

impl JSValConvertible for bool {
fn to_jsval(&self) -> JSVal {
if *self {
JSVAL_TRUE
} else {
JSVAL_FALSE
}
BooleanValue(*self)
}

fn from_jsval(cx: *JSContext, val: JSVal) -> Result<bool, ()> {
@@ -46,9 +42,7 @@ impl JSValConvertible for bool {

impl JSValConvertible for i8 {
fn to_jsval(&self) -> JSVal {
unsafe {
RUST_INT_TO_JSVAL(*self as i32)
}
Int32Value(*self as i32)
}

fn from_jsval(cx: *JSContext, val: JSVal) -> Result<i8, ()> {
@@ -59,9 +53,7 @@ impl JSValConvertible for i8 {

impl JSValConvertible for u8 {
fn to_jsval(&self) -> JSVal {
unsafe {
RUST_INT_TO_JSVAL(*self as i32)
}
Int32Value(*self as i32)
}

fn from_jsval(cx: *JSContext, val: JSVal) -> Result<u8, ()> {
@@ -72,9 +64,7 @@ impl JSValConvertible for u8 {

impl JSValConvertible for i16 {
fn to_jsval(&self) -> JSVal {
unsafe {
RUST_INT_TO_JSVAL(*self as i32)
}
Int32Value(*self as i32)
}

fn from_jsval(cx: *JSContext, val: JSVal) -> Result<i16, ()> {
@@ -85,9 +75,7 @@ impl JSValConvertible for i16 {

impl JSValConvertible for u16 {
fn to_jsval(&self) -> JSVal {
unsafe {
RUST_UINT_TO_JSVAL(*self as u32)
}
Int32Value(*self as i32)
}

fn from_jsval(cx: *JSContext, val: JSVal) -> Result<u16, ()> {
@@ -97,9 +85,7 @@ impl JSValConvertible for u16 {

impl JSValConvertible for i32 {
fn to_jsval(&self) -> JSVal {
unsafe {
RUST_INT_TO_JSVAL(*self)
}
Int32Value(*self)
}

fn from_jsval(cx: *JSContext, val: JSVal) -> Result<i32, ()> {
@@ -109,9 +95,7 @@ impl JSValConvertible for i32 {

impl JSValConvertible for u32 {
fn to_jsval(&self) -> JSVal {
unsafe {
RUST_UINT_TO_JSVAL(*self)
}
UInt32Value(*self)
}

fn from_jsval(cx: *JSContext, val: JSVal) -> Result<u32, ()> {
@@ -172,7 +156,7 @@ impl<T: JSValConvertible> JSValConvertible for Option<T> {
fn to_jsval(&self) -> JSVal {
match self {
&Some(ref value) => value.to_jsval(),
&None => JSVAL_NULL,
&None => NullValue(),
}
}

@@ -6,7 +6,8 @@ use dom::bindings::utils::is_dom_proxy;
use js::jsapi::{JSContext, jsid, JSPropertyDescriptor, JSObject, JSString, jschar};
use js::jsapi::{JS_GetPropertyDescriptorById, JS_NewUCString, JS_malloc, JS_free};
use js::jsapi::{JSBool, JS_DefinePropertyById, JS_NewObjectWithGivenProto};
use js::glue::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT, GetProxyExtra, RUST_OBJECT_TO_JSVAL};
use js::jsval::ObjectValue;
use js::glue::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT, GetProxyExtra};
use js::glue::{GetObjectProto, GetObjectParent, SetProxyExtra, GetProxyHandler};
use js::glue::InvokeGetOwnPropertyDescriptor;
use js::crust::{JS_StrictPropertyStub};
@@ -116,7 +117,7 @@ pub fn EnsureExpandoObject(cx: *JSContext, obj: *JSObject) -> *JSObject {
return ptr::null();
}

SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, RUST_OBJECT_TO_JSVAL(expando));
SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, ObjectValue(&*expando));
}
return expando;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.