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 the JSVal member functions to replace JSVAL_IS_* and JSVAL_TO_*.

  • Loading branch information
Ms2ger committed Mar 9, 2014
commit 9709dce07a56029edf2b812f371e7e07a69ef4ed
@@ -6,7 +6,7 @@ use dom::bindings::utils::Reflectable;
use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable};
use js::jsapi::{JS_GetProperty, JSTracer, JS_CallTracer};
use js::jsval::JSVal;
use js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT, JSTRACE_OBJECT};
use js::JSTRACE_OBJECT;

use std::cast;
use std::libc;
@@ -67,8 +67,8 @@ impl CallbackInterface {
return false;
}

if !JSVAL_IS_OBJECT(*callable) ||
JS_ObjectIsCallable(cx, JSVAL_TO_OBJECT(*callable)) == 0 {
if !callable.is_object() ||
JS_ObjectIsCallable(cx, callable.to_object()) == 0 {
//ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get());
return false;
}
@@ -290,7 +290,7 @@ def pickFirstSignature(condition, filterLambda):
# also allow the unwrapping test to skip having to do codegen
# for the null-or-undefined case, which we already handled
# above.
caseBody.append(CGGeneric("if JSVAL_IS_OBJECT(%s) {" %
caseBody.append(CGGeneric("if (%s).is_object() {" %
(distinguishingArg)))
for idx, sig in enumerate(interfacesSigs):
caseBody.append(CGIndenter(CGGeneric("loop {")));
@@ -570,11 +570,11 @@ def wrapObjectTemplate(templateBody, isDefinitelyObject, type,
# Handle the non-object cases by wrapping up the whole
# thing in an if cascade.
templateBody = (
"if JSVAL_IS_OBJECT(${val}) {\n" +
"if (${val}).is_object() {\n" +
CGIndenter(CGGeneric(templateBody)).define() + "\n")
if type.nullable():
templateBody += (
"} else if RUST_JSVAL_IS_NULL(${val}) != 0 || RUST_JSVAL_IS_VOID(${val}) != 0 {\n"
"} else if (${val}).is_null_or_undefined() {\n"
" %s;\n" % codeToSetNull)
templateBody += (
"} else {\n" +
@@ -799,7 +799,7 @@ def wrapObjectTemplate(templateBody, isDefinitelyObject, type,
if any([arrayObject, dateObject, nonPlatformObject, object]):
templateBody.prepend(CGGeneric("JSObject& argObj = ${val}.toObject();"))
templateBody = CGWrapper(CGIndenter(templateBody),
pre="if JSVAL_IS_OBJECT(${val}) {\n",
pre="if (${val}).is_object() {\n",
post="\n}")
else:
templateBody = CGGeneric()
@@ -844,7 +844,7 @@ def wrapObjectTemplate(templateBody, isDefinitelyObject, type,
nonConstDecl = "${declName}"

def handleNull(templateBody, setToNullVar, extraConditionForNull=""):
null = CGGeneric("if %s(RUST_JSVAL_IS_NULL(${val}) != 0 || RUST_JSVAL_IS_VOID(${val}) != 0) {\n"
null = CGGeneric("if %s((${val}).is_null_or_undefined()) {\n"
" %s = None;\n"
"}" % (extraConditionForNull, setToNullVar))
templateBody = CGWrapper(CGIndenter(templateBody), pre="{\n", post="\n}")
@@ -900,7 +900,7 @@ def handleNull(templateBody, setToNullVar, extraConditionForNull=""):
if descriptor.interface.isCallback():
name = descriptor.nativeType
declType = CGGeneric("Option<%s>" % name);
conversion = (" ${declName} = Some(%s::new(JSVAL_TO_OBJECT(${val})));\n" % name)
conversion = (" ${declName} = Some(%s::new((${val}).to_object()));\n" % name)

template = wrapObjectTemplate(conversion, type,
"${declName} = None",
@@ -922,15 +922,15 @@ def handleNull(templateBody, setToNullVar, extraConditionForNull=""):
if failureCode is not None:
templateBody += str(CastableObjectUnwrapper(
descriptor,
"JSVAL_TO_OBJECT(${val})",
"(${val}).to_object()",
"${declName}",
failureCode,
isOptional or type.nullable(),
preUnwrapped=preSuccess, postUnwrapped=postSuccess))
else:
templateBody += str(FailureFatalCastableObjectUnwrapper(
descriptor,
"JSVAL_TO_OBJECT(${val})",
"(${val}).to_object()",
"${declName}",
isOptional or type.nullable()))
else:
@@ -4360,7 +4360,7 @@ def definition_body(self):
obj = js::UnwrapObject(obj);
}*/
//MOZ_ASSERT(IsProxy(obj));
let box_: *Box<%s> = cast::transmute(RUST_JSVAL_TO_PRIVATE(GetProxyPrivate(obj)));
let box_: *Box<%s> = cast::transmute(GetProxyPrivate(obj).to_private());
return ptr::to_unsafe_ptr(&(*box_).data);""" % (self.descriptor.concreteType)

class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
@@ -4682,7 +4682,7 @@ def generate_code(self):

def finalizeHook(descriptor, hookName, context):
release = """let val = JS_GetReservedSlot(obj, dom_object_slot(obj));
let _: %s %s = cast::transmute(RUST_JSVAL_TO_PRIVATE(val));
let _: %s %s = cast::transmute(val.to_private());
debug!("%s finalize: {:p}", this);
""" % (DOMObjectPointerType(descriptor), descriptor.concreteType, descriptor.concreteType)
return release
@@ -4719,7 +4719,7 @@ def definition_body(self):

def generate_code(self):
preamble = """
let global = global_object_for_js_object(RUST_JSVAL_TO_OBJECT(JS_CALLEE(cx, &*vp)));
let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object());
let obj = global.reflector().get_jsobject();
"""
nativeName = MakeNativeName(self._ctor.identifier.name)
@@ -5012,8 +5012,8 @@ def defaultValue(ty):
"${initParent}"
" let mut found: JSBool = 0;\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"
" let isNull = val.is_null_or_undefined();\n"
" if !isNull && val.is_primitive() {\n"
" return 0; //XXXjdm throw properly here\n"
" //return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);\n"
" }\n"
@@ -5073,15 +5073,15 @@ def getMemberConversion(self, memberInfo):

if True: #XXXjdm hack until 'static mut' exists for global jsids
propName = member.identifier.name
propCheck = ('"%s".to_c_str().with_ref(|s| { JS_HasProperty(cx, RUST_JSVAL_TO_OBJECT(val), s, ptr::to_unsafe_ptr(&found)) })' %
propCheck = ('"%s".to_c_str().with_ref(|s| { JS_HasProperty(cx, val.to_object(), s, ptr::to_unsafe_ptr(&found)) })' %
propName)
propGet = ('"%s".to_c_str().with_ref(|s| { JS_GetProperty(cx, RUST_JSVAL_TO_OBJECT(val), s, ptr::to_unsafe_ptr(&temp)) })' %
propGet = ('"%s".to_c_str().with_ref(|s| { JS_GetProperty(cx, val.to_object(), s, ptr::to_unsafe_ptr(&temp)) })' %
propName)
else:
propId = self.makeIdName(member.identifier.name);
propCheck = ("JS_HasPropertyById(cx, RUST_JSVAL_TO_OBJECT(val), %s, ptr::to_unsafe_ptr(&found))" %
propCheck = ("JS_HasPropertyById(cx, val.to_object(), %s, ptr::to_unsafe_ptr(&found))" %
propId)
propGet = ("JS_GetPropertyById(cx, RUST_JSVAL_TO_OBJECT(val), %s, ptr::to_unsafe_ptr(&temp))" %
propGet = ("JS_GetPropertyById(cx, val.to_object(), %s, ptr::to_unsafe_ptr(&temp))" %
propId)

conversionReplacements = {
@@ -5236,7 +5236,6 @@ def makeEnumTypedef(e):
'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}',
'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}',
'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}',
@@ -5254,9 +5253,6 @@ def makeEnumTypedef(e):
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
'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}',
'dom::types::*',
'dom::bindings::js::JS',
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
@@ -6435,7 +6431,6 @@ def UnionConversions(config):
'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}',
'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}',
'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}',
@@ -6451,10 +6446,7 @@ def UnionConversions(config):
'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}',
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
'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}',], [], curr)
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',], [], curr)

# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@@ -9,7 +9,6 @@ use js::jsapi::{JS_ValueToUint16, JS_ValueToNumber, JS_ValueToBoolean};
use js::jsval::JSVal;
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 {
fn to_jsval(&self) -> JSVal;
@@ -161,7 +160,7 @@ impl<T: JSValConvertible> JSValConvertible for Option<T> {
}

fn from_jsval(cx: *JSContext, value: JSVal) -> Result<Option<T>, ()> {
if unsafe { RUST_JSVAL_IS_NULL(value) != 0 || RUST_JSVAL_IS_VOID(value) != 0 } {
if value.is_null_or_undefined() {
Ok(None)
} else {
let result: Result<T, ()> = JSValConvertible::from_jsval(cx, value);
@@ -7,7 +7,7 @@ use js::jsapi::{JSContext, jsid, JSPropertyDescriptor, JSObject, JSString, jscha
use js::jsapi::{JS_GetPropertyDescriptorById, JS_NewUCString, JS_malloc, JS_free};
use js::jsapi::{JSBool, JS_DefinePropertyById, JS_NewObjectWithGivenProto};
use js::jsval::ObjectValue;
use js::glue::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT, GetProxyExtra};
use js::glue::GetProxyExtra;
use js::glue::{GetObjectProto, GetObjectParent, SetProxyExtra, GetProxyHandler};
use js::glue::InvokeGetOwnPropertyDescriptor;
use js::crust::{JS_StrictPropertyStub};
@@ -98,10 +98,10 @@ pub fn GetExpandoObject(obj: *JSObject) -> *JSObject {
unsafe {
assert!(is_dom_proxy(obj));
let val = GetProxyExtra(obj, JSPROXYSLOT_EXPANDO);
if RUST_JSVAL_IS_VOID(val) == 1 {
if val.is_undefined() {
ptr::null()
} else {
RUST_JSVAL_TO_OBJECT(val)
val.to_object()
}
}
}
@@ -43,19 +43,6 @@ use js::JSPROP_SETTER;
use js::{JSFUN_CONSTRUCTOR, JSPROP_READONLY};
use js;

mod jsval {
use js::glue::{RUST_JSVAL_IS_NULL, RUST_JSVAL_IS_VOID};
use js::jsval::JSVal;

pub fn is_null(v: JSVal) -> bool {
unsafe { RUST_JSVAL_IS_NULL(v) == 1 }
}

pub fn is_undefined(v: JSVal) -> bool {
unsafe { RUST_JSVAL_IS_VOID(v) == 1 }
}
}

pub struct GlobalStaticData {
proxy_handlers: HashMap<uint, *libc::c_void>,
attribute_ids: HashMap<uint, ~[jsid]>,
@@ -98,7 +85,7 @@ pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 {
pub unsafe fn unwrap<T>(obj: *JSObject) -> T {
let slot = dom_object_slot(obj);
let val = JS_GetReservedSlot(obj, slot);
cast::transmute(RUST_JSVAL_TO_PRIVATE(val))
cast::transmute(val.to_private())
}

pub unsafe fn get_dom_class(obj: *JSObject) -> Result<DOMClass, ()> {
@@ -144,7 +131,7 @@ pub fn unwrap_jsmanaged<T: Reflectable>(obj: *JSObject,

pub fn unwrap_value<T>(val: *JSVal, proto_id: PrototypeList::id::ID, proto_depth: uint) -> Result<T, ()> {
unsafe {
let obj = RUST_JSVAL_TO_OBJECT(*val);
let obj = (*val).to_object();
unwrap_object(obj, proto_id, proto_depth)
}
}
@@ -182,7 +169,7 @@ pub enum StringificationBehavior {

pub fn jsval_to_str(cx: *JSContext, v: JSVal,
nullBehavior: StringificationBehavior) -> Result<DOMString, ()> {
if jsval::is_null(v) && nullBehavior == Empty {
if v.is_null() && nullBehavior == Empty {
Ok(~"")
} else {
let jsstr = unsafe { JS_ValueToString(cx, v) };
@@ -196,7 +183,7 @@ pub fn jsval_to_str(cx: *JSContext, v: JSVal,
}

pub fn jsval_to_domstring(cx: *JSContext, v: JSVal) -> Result<Option<DOMString>, ()> {
if jsval::is_null(v) || jsval::is_undefined(v) {
if v.is_null_or_undefined() {
Ok(None)
} else {
let jsstr = unsafe { JS_ValueToString(cx, v) };
@@ -310,7 +297,7 @@ pub struct DOMJSClass {
pub fn GetProtoOrIfaceArray(global: *JSObject) -> **JSObject {
unsafe {
/*assert ((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0;*/
cast::transmute(RUST_JSVAL_TO_PRIVATE(JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT)))
cast::transmute(JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private())
}
}

@@ -33,7 +33,6 @@ use extra::url::Url;
use geom::point::Point2D;
use geom::size::Size2D;
use js::global::DEBUG_FNS;
use js::glue::RUST_JSVAL_TO_OBJECT;
use js::jsapi::{JSObject, JS_InhibitGC, JS_AllowGC, JS_CallFunctionValue};
use js::jsval::NullValue;
use js::rust::{Compartment, Cx, CxUtils, RtUtils};
@@ -651,9 +650,7 @@ impl ScriptTask {
window.get_mut().active_timers.remove(&TimerHandle { handle: timer_data.handle, cancel_chan: None });
let js_info = page.js_info();
let this_value = if timer_data.args.len() > 0 {
unsafe {
RUST_JSVAL_TO_OBJECT(timer_data.args[0])
}
fail!("NYI")
} else {
js_info.get().get_ref().js_compartment.borrow().global_obj.borrow().ptr
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.