diff options
-rw-r--r-- | src/components/script/dom/bindings/callback.rs | 9 | ||||
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 103 | ||||
-rw-r--r-- | src/components/script/dom/bindings/conversions.rs | 42 | ||||
-rw-r--r-- | src/components/script/dom/bindings/proxyhandler.rs | 9 | ||||
-rw-r--r-- | src/components/script/dom/bindings/utils.rs | 58 | ||||
-rw-r--r-- | src/components/script/dom/htmlelement.rs | 6 | ||||
-rw-r--r-- | src/components/script/dom/testbinding.rs | 6 | ||||
-rw-r--r-- | src/components/script/dom/window.rs | 10 | ||||
-rw-r--r-- | src/components/script/script_task.rs | 9 | ||||
m--------- | src/support/spidermonkey/rust-mozjs | 0 |
10 files changed, 110 insertions, 142 deletions
diff --git a/src/components/script/dom/bindings/callback.rs b/src/components/script/dom/bindings/callback.rs index 10cb35c3af4..b965fcbfb72 100644 --- a/src/components/script/dom/bindings/callback.rs +++ b/src/components/script/dom/bindings/callback.rs @@ -3,9 +3,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::utils::Reflectable; -use js::jsapi::{JSContext, JSObject, JS_WrapObject, JSVal, JS_ObjectIsCallable}; +use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable}; use js::jsapi::{JS_GetProperty, JSTracer, JS_CallTracer}; -use js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT, JSTRACE_OBJECT}; +use js::jsval::JSVal; +use js::JSTRACE_OBJECT; use std::cast; use std::libc; @@ -66,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 47c91614d52..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: @@ -1152,7 +1152,7 @@ for (uint32_t i = 0; i < length; ++i) { 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 @@ for (uint32_t i = 0; i < length; ++i) { # 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 getWrapTemplateForType(type, descriptorProvider, result, successCode, 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 getWrapTemplateForType(type, descriptorProvider, result, successCode, 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 @@ for (uint32_t i = 0; i < length; ++i) { 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 @@ if %(resultStr)s.is_null() { """ % { "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 @@ if %(resultStr)s.is_null() { # 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 @@ class CGGenericSetter(CGAbstractBindingMethod): 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 @@ class CGGenericSetter(CGAbstractBindingMethod): "if ok == 0 {\n" " return 0;\n" "}\n" - "*vp = JSVAL_VOID;\n" + "*vp = UndefinedValue();\n" "return 1;")) class CGSpecializedSetter(CGAbstractExternMethod): @@ -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): @@ -4621,7 +4621,7 @@ if found { return 1; } %s -*vp = JSVAL_VOID; +*vp = UndefinedValue(); return 1;""" % (getIndexedOrExpando, getNamed) def definition_body(self): @@ -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) @@ -5011,9 +5011,9 @@ class CGDictionary(CGThing): " }\n" "${initParent}" " let mut found: JSBool = 0;\n" - " let temp: JSVal = JSVAL_NULL;\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 temp: JSVal = NullValue();\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 = { @@ -5235,8 +5235,7 @@ class CGBindingRoot(CGThing): '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::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}', 'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}', 'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}', @@ -5246,15 +5245,14 @@ class CGBindingRoot(CGThing): 'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}', 'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor}', 'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}', - 'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer, JSVal}', + '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_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_FUNCTION_VALUE_TO_JITINFO}', + 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings::js::JS', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', @@ -5695,7 +5693,7 @@ class CGCallback(CGClass): # 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. @@ -5860,7 +5858,7 @@ class CallbackMember(CGNativeMember): 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 @@ -6044,7 +6042,7 @@ class CallbackMethod(CallbackMember): 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 = { @@ -6111,9 +6109,9 @@ class CallbackOperationBase(CallbackMethod): 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()) @@ -6432,8 +6430,7 @@ class GlobalGenRoots(): '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::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}', 'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}', 'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}', @@ -6443,15 +6440,13 @@ class GlobalGenRoots(): 'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}', 'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor}', 'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}', - 'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer, JSVal}', + '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_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_FUNCTION_VALUE_TO_JITINFO}', + '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 6b033225c85..9e2ab829dc6 100644 --- a/src/components/script/dom/bindings/conversions.rs +++ b/src/components/script/dom/bindings/conversions.rs @@ -2,13 +2,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use js::jsapi::{JSVal, JSBool, JSContext}; +use js::jsapi::{JSBool, JSContext}; 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_FALSE, JSVAL_TRUE, JSVAL_NULL}; -use js::glue::{RUST_INT_TO_JSVAL, RUST_UINT_TO_JSVAL, RUST_JS_NumberValue}; -use js::glue::{RUST_JSVAL_IS_NULL, RUST_JSVAL_IS_VOID}; +use js::jsval::JSVal; +use js::jsval::{NullValue, BooleanValue, Int32Value, UInt32Value}; +use js::glue::RUST_JS_NumberValue; pub trait JSValConvertible { fn to_jsval(&self) -> JSVal; @@ -30,11 +30,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, ()> { @@ -45,9 +41,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, ()> { @@ -58,9 +52,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, ()> { @@ -71,9 +63,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, ()> { @@ -84,9 +74,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, ()> { @@ -96,9 +84,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, ()> { @@ -108,9 +94,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, ()> { @@ -171,12 +155,12 @@ 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(), } } 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 2f8267d4f29..aaf75a7bc7a 100644 --- a/src/components/script/dom/bindings/proxyhandler.rs +++ b/src/components/script/dom/bindings/proxyhandler.rs @@ -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::GetProxyExtra; use js::glue::{GetObjectProto, GetObjectParent, SetProxyExtra, GetProxyHandler}; use js::glue::InvokeGetOwnPropertyDescriptor; use js::crust::{JS_StrictPropertyStub}; @@ -97,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() } } } @@ -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; } diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index a749b26b42c..c4506f96855 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -19,7 +19,6 @@ use std::str; use std::vec; use std::unstable::raw::Box; use js::glue::*; -use js::glue::{RUST_OBJECT_TO_JSVAL}; use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily}; use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction}; use js::jsapi::{JS_DefineProperties, JS_WrapValue, JS_ForwardGetPropertyTo}; @@ -30,30 +29,20 @@ use js::jsapi::{JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject}; use js::jsapi::{JS_NewUCStringCopyN, JS_DefineFunctions, JS_DefineProperty}; use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot}; use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative}; -use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor}; +use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSPropertyDescriptor}; use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses}; use js::jsapi::{JSString}; use js::jsapi::{JS_AllowGC, JS_InhibitGC}; use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType; -use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS}; +use js::jsval::JSVal; +use js::jsval::{StringValue, PrivateValue, ObjectValue, NullValue, Int32Value}; +use js::jsval::{UInt32Value, DoubleValue, BooleanValue, UndefinedValue}; +use js::{JSPROP_ENUMERATE, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS}; use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER}; -use js::{JSPROP_SETTER, JSVAL_VOID, JSVAL_TRUE, JSVAL_FALSE}; +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::jsapi::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]>, @@ -96,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, ()> { @@ -142,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) } } @@ -180,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) }; @@ -194,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) }; @@ -213,12 +202,12 @@ pub unsafe fn str_to_jsval(cx: *JSContext, string: DOMString) -> JSVal { if jsstr.is_null() { fail!("JS_NewUCStringCopyN failed"); } - RUST_STRING_TO_JSVAL(jsstr) + StringValue(&*jsstr) } pub unsafe fn domstring_to_jsval(cx: *JSContext, string: Option<DOMString>) -> JSVal { match string { - None => JSVAL_NULL, + None => NullValue(), Some(s) => str_to_jsval(cx, s), } } @@ -308,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()) } } @@ -333,7 +322,7 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO unsafe { JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT, - RUST_PRIVATE_TO_JSVAL(domClass as *libc::c_void)); + PrivateValue(domClass as *libc::c_void)); } } @@ -392,7 +381,7 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject, } if alreadyDefined == 0 && - JS_DefineProperty(cx, receiver, name, RUST_OBJECT_TO_JSVAL(constructor), + JS_DefineProperty(cx, receiver, name, ObjectValue(&*constructor), None, None, 0) == 0 { return ptr::null(); } @@ -410,13 +399,12 @@ fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> return true; } let jsval = match spec.value { - NullVal => JSVAL_NULL, - IntVal(i) => RUST_INT_TO_JSVAL(i), - UintVal(u) => RUST_UINT_TO_JSVAL(u), - DoubleVal(d) => RUST_DOUBLE_TO_JSVAL(d), - BoolVal(b) if b => JSVAL_TRUE, - BoolVal(_) => JSVAL_FALSE, - VoidVal => JSVAL_VOID + NullVal => NullValue(), + IntVal(i) => Int32Value(i), + UintVal(u) => UInt32Value(u), + DoubleVal(d) => DoubleValue(d), + BoolVal(b) => BooleanValue(b), + VoidVal => UndefinedValue(), }; if JS_DefineProperty(cx, obj, spec.name, jsval, None, @@ -480,7 +468,7 @@ pub fn initialize_global(global: *JSObject) { let box_ = squirrel_away_unboxed(protoArray); JS_SetReservedSlot(global, DOM_PROTOTYPE_SLOT, - RUST_PRIVATE_TO_JSVAL(box_ as *libc::c_void)); + PrivateValue(box_ as *libc::c_void)); } } @@ -528,7 +516,7 @@ pub fn GetReflector(cx: *JSContext, reflector: &Reflector, let obj = reflector.get_jsobject(); assert!(obj.is_not_null()); unsafe { - *vp = RUST_OBJECT_TO_JSVAL(obj); + *vp = ObjectValue(&*obj); return JS_WrapValue(cx, cast::transmute(vp)); } } diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index b27afdfff2e..8464d23aec0 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -10,8 +10,8 @@ use dom::document::Document; use dom::element::{Element, ElementTypeId, HTMLElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{Node, ElementNodeTypeId}; -use js::jsapi::{JSContext, JSVal}; -use js::JSVAL_NULL; +use js::jsapi::JSContext; +use js::jsval::{JSVal, NullValue}; use servo_util::namespace; use servo_util::str::DOMString; @@ -66,7 +66,7 @@ impl HTMLElement { } pub fn GetItemValue(&self, _cx: *JSContext) -> Fallible<JSVal> { - Ok(JSVAL_NULL) + Ok(NullValue()) } pub fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult { diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 634e569791f..514260c5c10 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -8,8 +8,8 @@ use dom::blob::Blob; use dom::window::Window; use servo_util::str::DOMString; -use js::JSVAL_NULL; -use js::jsapi::{JSVal, JSContext}; +use js::jsapi::JSContext; +use js::jsval::{JSVal, NullValue}; #[deriving(Encodable)] pub struct TestBinding { @@ -44,7 +44,7 @@ impl TestBinding { pub fn SetStringAttribute(&self, _: DOMString) {} pub fn InterfaceAttribute(&self) -> JS<Blob> { Blob::new(&self.window) } pub fn SetInterfaceAttribute(&self, _: &JS<Blob>) {} - pub fn AnyAttribute(&self, _: *JSContext) -> JSVal { JSVAL_NULL } + pub fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() } pub fn SetAnyAttribute(&self, _: *JSContext, _: JSVal) {} pub fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) } diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index d431745f018..7c3d2e90280 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -20,8 +20,10 @@ use servo_util::str::DOMString; use servo_util::task::{spawn_named}; use js::glue::*; -use js::jsapi::{JSObject, JSContext, JS_DefineProperty, JSVal}; -use js::{JSVAL_NULL, JSPROP_ENUMERATE}; +use js::jsapi::{JSObject, JSContext, JS_DefineProperty}; +use js::jsval::JSVal; +use js::jsval::{NullValue, ObjectValue}; +use js::JSPROP_ENUMERATE; use std::cast; use std::comm::SharedChan; @@ -208,7 +210,7 @@ impl Window { } pub fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option<JSVal>) -> JSVal { - JSVAL_NULL + NullValue() } } @@ -317,7 +319,7 @@ impl Window { for str in fn_names.iter() { (*str).to_c_str().with_ref(|name| { JS_DefineProperty(cx, global, name, - RUST_OBJECT_TO_JSVAL(global), + ObjectValue(&*global), Some(cast::transmute(GetJSClassHookStubPointer(PROPERTY_STUB))), Some(cast::transmute(GetJSClassHookStubPointer(STRICT_PROPERTY_STUB))), JSPROP_ENUMERATE); diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index d4215b46c28..d4561ebc21b 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -32,10 +32,9 @@ use layout_interface; use extra::url::Url; use geom::point::Point2D; use geom::size::Size2D; -use js::JSVAL_NULL; 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}; use js; use servo_msg::compositor_msg::{FinishedLoading, Loading, PerformingLayout, ScriptListener}; @@ -651,15 +650,13 @@ 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 }; // TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`. - let rval = JSVAL_NULL; + let rval = NullValue(); let cx = js_info.get().get_ref().js_context.borrow().ptr; with_gc_enabled(cx, || { unsafe { diff --git a/src/support/spidermonkey/rust-mozjs b/src/support/spidermonkey/rust-mozjs -Subproject 1730e6bf24fdacb958061b8ee80d5289f7a7b49 +Subproject a75966e3ccacf39c41776a94ad654492c311666 |