aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-03-09 11:29:23 +0100
committerMs2ger <ms2ger@gmail.com>2014-03-09 18:52:05 +0100
commit9709dce07a56029edf2b812f371e7e07a69ef4ed (patch)
treee0173e82351bcc08ee4bcfd63e2faab1b6578421 /src
parent84b0f45ed5d1e6fdff24c195699218c8743b561e (diff)
downloadservo-9709dce07a56029edf2b812f371e7e07a69ef4ed.tar.gz
servo-9709dce07a56029edf2b812f371e7e07a69ef4ed.zip
Use the JSVal member functions to replace JSVAL_IS_* and JSVAL_TO_*.
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/bindings/callback.rs6
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py44
-rw-r--r--src/components/script/dom/bindings/conversions.rs3
-rw-r--r--src/components/script/dom/bindings/proxyhandler.rs6
-rw-r--r--src/components/script/dom/bindings/utils.rs23
-rw-r--r--src/components/script/script_task.rs5
m---------src/support/spidermonkey/rust-mozjs0
7 files changed, 31 insertions, 56 deletions
diff --git a/src/components/script/dom/bindings/callback.rs b/src/components/script/dom/bindings/callback.rs
index 2263ea9d224..b965fcbfb72 100644
--- a/src/components/script/dom/bindings/callback.rs
+++ b/src/components/script/dom/bindings/callback.rs
@@ -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;
}
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index 3de049cfd1f..e11a67fae8a 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -290,7 +290,7 @@ class CGMethodCall(CGThing):
# 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 getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
# 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 @@ for (uint32_t i = 0; i < length; ++i) {
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 @@ for (uint32_t i = 0; i < length; ++i) {
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 @@ for (uint32_t i = 0; i < length; ++i) {
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,7 +922,7 @@ for (uint32_t i = 0; i < length; ++i) {
if failureCode is not None:
templateBody += str(CastableObjectUnwrapper(
descriptor,
- "JSVAL_TO_OBJECT(${val})",
+ "(${val}).to_object()",
"${declName}",
failureCode,
isOptional or type.nullable(),
@@ -930,7 +930,7 @@ for (uint32_t i = 0; i < length; ++i) {
else:
templateBody += str(FailureFatalCastableObjectUnwrapper(
descriptor,
- "JSVAL_TO_OBJECT(${val})",
+ "(${val}).to_object()",
"${declName}",
isOptional or type.nullable()))
else:
@@ -4360,7 +4360,7 @@ class CGProxyUnwrap(CGAbstractMethod):
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 @@ class CGAbstractClassHook(CGAbstractExternMethod):
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 @@ class CGClassConstructHook(CGAbstractExternMethod):
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 @@ class CGDictionary(CGThing):
"${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 @@ class CGDictionary(CGThing):
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 @@ class CGBindingRoot(CGThing):
'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 @@ class CGBindingRoot(CGThing):
'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 @@ class GlobalGenRoots():
'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 @@ class GlobalGenRoots():
'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)
diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs
index d488c70fc82..9e2ab829dc6 100644
--- a/src/components/script/dom/bindings/conversions.rs
+++ b/src/components/script/dom/bindings/conversions.rs
@@ -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);
diff --git a/src/components/script/dom/bindings/proxyhandler.rs b/src/components/script/dom/bindings/proxyhandler.rs
index e090d759920..aaf75a7bc7a 100644
--- a/src/components/script/dom/bindings/proxyhandler.rs
+++ b/src/components/script/dom/bindings/proxyhandler.rs
@@ -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()
}
}
}
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs
index 57e3c39adf8..c4506f96855 100644
--- a/src/components/script/dom/bindings/utils.rs
+++ b/src/components/script/dom/bindings/utils.rs
@@ -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())
}
}
diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs
index a2e2b3fc9fd..d4561ebc21b 100644
--- a/src/components/script/script_task.rs
+++ b/src/components/script/script_task.rs
@@ -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
};
diff --git a/src/support/spidermonkey/rust-mozjs b/src/support/spidermonkey/rust-mozjs
-Subproject e993175799354c94224f89e2e2bdc5676998dcd
+Subproject 85dc7859ef52da2efdee7dde905f76c17cdc79f