From 445701d138f5506af17be4623455bcf4dac460b3 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 18 Nov 2016 14:39:06 +0100 Subject: [PATCH] Update js, AGAIN --- .../dom/bindings/codegen/CodegenRust.py | 6 ++-- components/script/dom/bindings/conversions.rs | 36 ++++++------------- components/script/dom/bindings/interface.rs | 8 ++--- components/script/dom/bindings/utils.rs | 12 +++---- components/script/dom/browsingcontext.rs | 5 +-- components/script/dom/globalscope.rs | 6 ++-- ports/cef/Cargo.lock | 2 +- ports/servo/Cargo.lock | 2 +- 8 files changed, 31 insertions(+), 46 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index e5db3532001..0003496e33e 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2537,7 +2537,7 @@ class CGWrapMethod(CGAbstractMethod): return CGGeneric("""\ let scope = scope.reflector().get_jsobject(); assert!(!scope.get().is_null()); -assert!(((*JS_GetClass(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0); +assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0); rooted!(in(cx) let mut proto = ptr::null_mut()); let _ac = JSAutoCompartment::new(cx, scope.get()); @@ -2954,7 +2954,7 @@ class CGGetPerInterfaceObject(CGAbstractMethod): def definition_body(self): return CGGeneric(""" -assert!(((*JS_GetClass(global.get())).flags & JSCLASS_DOM_GLOBAL) != 0); +assert!(((*get_object_class(global.get())).flags & JSCLASS_DOM_GLOBAL) != 0); /* Check to see whether the interface objects are already installed */ let proto_or_iface_array = get_proto_or_iface_array(global.get()); @@ -5448,7 +5448,6 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::jsapi::JS_DefineProperty', 'js::jsapi::JS_DefinePropertyById2', 'js::jsapi::JS_ForwardGetPropertyTo', - 'js::jsapi::JS_GetClass', 'js::jsapi::JS_GetErrorPrototype', 'js::jsapi::JS_GetFunctionPrototype', 'js::jsapi::JS_GetGlobalForObject', @@ -5501,6 +5500,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::rust::GCMethods', 'js::rust::define_methods', 'js::rust::define_properties', + 'js::rust::get_object_class', 'dom', 'dom::bindings', 'dom::bindings::codegen::InterfaceObjectMap', diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 9143c9cb75b..ba67ad11a7e 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -46,14 +46,14 @@ use js::error::throw_type_error; use js::glue::{GetProxyPrivate, IsWrapper}; use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT}; use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject}; -use js::jsapi::{HandleId, HandleObject, HandleValue, JSClass, JSContext}; -use js::jsapi::{JSObject, JSString, JS_GetArrayBufferViewType, JS_GetClass}; +use js::jsapi::{HandleId, HandleObject, HandleValue, JSContext}; +use js::jsapi::{JSObject, JSString, JS_GetArrayBufferViewType}; use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetObjectAsArrayBuffer, JS_GetObjectAsArrayBufferView}; -use js::jsapi::{JS_GetReservedSlot, JS_GetTwoByteStringCharsAndLength, ToWindowProxyIfWindow}; +use js::jsapi::{JS_GetReservedSlot, JS_GetTwoByteStringCharsAndLength}; use js::jsapi::{JS_IsArrayObject, JS_NewStringCopyN, JS_StringHasLatin1Chars}; -use js::jsapi::{JS_WrapValue, MutableHandleValue, Type, IsObjectInContextCompartment}; +use js::jsapi::{MutableHandleValue, Type}; use js::jsval::{ObjectValue, StringValue}; -use js::rust::ToString; +use js::rust::{ToString, get_object_class, is_dom_class, is_dom_object, maybe_wrap_value}; use libc; use num_traits::Float; use std::{char, mem, ptr, slice}; @@ -308,23 +308,8 @@ impl ToJSValConvertible for Reflector { unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { let obj = self.get_jsobject().get(); assert!(!obj.is_null()); - let same_compartment = IsObjectInContextCompartment(obj, cx); - if same_compartment { - rval.set(ObjectValue(ToWindowProxyIfWindow(obj))); - } else { - rval.set(ObjectValue(obj)); - - if !JS_WrapValue(cx, rval) { - panic!("JS_WrapValue failed."); - } - } - } -} - -/// Returns whether the given `clasp` is one for a DOM object. -pub fn is_dom_class(clasp: *const JSClass) -> bool { - unsafe { - ((*clasp).flags & js::JSCLASS_IS_DOMJSCLASS) != 0 + rval.set(ObjectValue(obj)); + maybe_wrap_value(cx, rval); } } @@ -332,7 +317,7 @@ pub fn is_dom_class(clasp: *const JSClass) -> bool { pub fn is_dom_proxy(obj: *mut JSObject) -> bool { use js::glue::IsProxyHandlerFamily; unsafe { - let clasp = JS_GetClass(obj); + let clasp = get_object_class(obj); ((*clasp).flags & js::JSCLASS_IS_PROXY) != 0 && IsProxyHandlerFamily(obj) != 0 } } @@ -345,8 +330,7 @@ pub const DOM_OBJECT_SLOT: u32 = 0; /// Get the private pointer of a DOM object from a given reflector. pub unsafe fn private_from_object(obj: *mut JSObject) -> *const libc::c_void { - let clasp = JS_GetClass(obj); - let value = if is_dom_class(clasp) { + let value = if is_dom_object(obj) { JS_GetReservedSlot(obj, DOM_OBJECT_SLOT) } else { debug_assert!(is_dom_proxy(obj)); @@ -364,7 +348,7 @@ pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<&'static DOMClass, ()> use dom::bindings::utils::DOMJSClass; use js::glue::GetProxyHandlerExtra; - let clasp = JS_GetClass(obj); + let clasp = get_object_class(obj); if is_dom_class(&*clasp) { trace!("plain old dom object"); let domjsclass: *const DOMJSClass = clasp as *const DOMJSClass; diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index cae5da97887..517adbde425 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -19,14 +19,14 @@ use js::jsapi::{JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING}; use js::jsapi::{JSPropertySpec, JSString, JSTracer, JSVersion, JS_AtomizeAndPinString}; use js::jsapi::{JS_DefineProperty, JS_DefineProperty1, JS_DefineProperty2}; use js::jsapi::{JS_DefineProperty4, JS_DefinePropertyById3, JS_FireOnNewGlobalObject}; -use js::jsapi::{JS_GetClass, JS_GetFunctionObject, JS_GetPrototype}; +use js::jsapi::{JS_GetFunctionObject, JS_GetPrototype}; use js::jsapi::{JS_LinkConstructorAndPrototype, JS_NewFunction, JS_NewGlobalObject}; use js::jsapi::{JS_NewObject, JS_NewObjectWithUniqueType, JS_NewPlainObject}; use js::jsapi::{JS_NewStringCopyN, JS_SetReservedSlot, MutableHandleObject}; use js::jsapi::{MutableHandleValue, ObjectOps, OnNewGlobalHookOption, SymbolCode}; use js::jsapi::{TrueHandleValue, Value}; use js::jsval::{JSVal, PrivateValue}; -use js::rust::{define_methods, define_properties}; +use js::rust::{define_methods, define_properties, get_object_class}; use libc; use std::ptr; @@ -352,7 +352,7 @@ unsafe extern "C" fn fun_to_string_hook(cx: *mut JSContext, obj: HandleObject, _indent: u32) -> *mut JSString { - let js_class = JS_GetClass(obj.get()); + let js_class = get_object_class(obj.get()); assert!(!js_class.is_null()); let repr = (*(js_class as *const NonCallbackInterfaceObjectClass)).representation; assert!(!repr.is_empty()); @@ -388,7 +388,7 @@ unsafe fn has_instance( } rooted!(in(cx) let mut value = value.to_object()); - let js_class = JS_GetClass(interface_object.get()); + let js_class = get_object_class(interface_object.get()); let object_class = &*(js_class as *const NonCallbackInterfaceObjectClass); if let Ok(dom_class) = get_dom_class(UncheckedUnwrapObject(value.get(), diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 32ffe4109ae..de1ac8fcbfd 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::InterfaceObjectMap; use dom::bindings::codegen::PrototypeList; use dom::bindings::codegen::PrototypeList::{MAX_PROTO_CHAIN_LENGTH, PROTO_OR_IFACE_LENGTH}; -use dom::bindings::conversions::{is_dom_class, jsstring_to_str, private_from_proto_check}; +use dom::bindings::conversions::{jsstring_to_str, private_from_proto_check}; use dom::bindings::error::throw_invalid_this; use dom::bindings::inheritance::TopTypeId; use dom::bindings::str::DOMString; @@ -24,13 +24,13 @@ use js::jsapi::{CallArgs, DOMCallbacks, GetGlobalForObjectCrossCompartment}; use js::jsapi::{HandleId, HandleObject, HandleValue, Heap, JSAutoCompartment, JSContext}; use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks}; use js::jsapi::{JS_DeletePropertyById, JS_EnumerateStandardClasses}; -use js::jsapi::{JS_ForwardGetPropertyTo, JS_GetClass, JS_GetLatin1StringCharsAndLength}; +use js::jsapi::{JS_ForwardGetPropertyTo, JS_GetLatin1StringCharsAndLength}; use js::jsapi::{JS_GetProperty, JS_GetPrototype, JS_GetReservedSlot, JS_HasProperty}; use js::jsapi::{JS_HasPropertyById, JS_IsExceptionPending, JS_IsGlobalObject}; use js::jsapi::{JS_ResolveStandardClass, JS_SetProperty, ToWindowProxyIfWindow}; use js::jsapi::{JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult}; use js::jsval::{JSVal, UndefinedValue}; -use js::rust::{GCMethods, ToString}; +use js::rust::{GCMethods, ToString, get_object_class, is_dom_class}; use libc; use std::ffi::CString; use std::os::raw::c_void; @@ -115,7 +115,7 @@ unsafe impl Sync for DOMJSClass {} /// Fails if `global` is not a DOM global object. pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray { unsafe { - assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0); + assert!(((*get_object_class(global)).flags & JSCLASS_DOM_GLOBAL) != 0); JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as *mut ProtoOrIfaceArray } } @@ -198,7 +198,7 @@ pub unsafe fn find_enum_string_index(cx: *mut JSContext, pub fn is_platform_object(obj: *mut JSObject) -> bool { unsafe { // Fast-path the common case - let mut clasp = JS_GetClass(obj); + let mut clasp = get_object_class(obj); if is_dom_class(&*clasp) { return true; } @@ -208,7 +208,7 @@ pub fn is_platform_object(obj: *mut JSObject) -> bool { if unwrapped_obj.is_null() { return false; } - clasp = js::jsapi::JS_GetClass(obj); + clasp = get_object_class(obj); } // TODO also check if JS_IsArrayBufferObject is_dom_class(&*clasp) diff --git a/components/script/dom/browsingcontext.rs b/components/script/dom/browsingcontext.rs index 1409c9c5dcf..2434ab76819 100644 --- a/components/script/dom/browsingcontext.rs +++ b/components/script/dom/browsingcontext.rs @@ -20,11 +20,12 @@ use js::glue::{GetProxyPrivate, SetProxyExtra, GetProxyExtra}; use js::jsapi::{Handle, HandleId, HandleObject, HandleValue}; use js::jsapi::{JSAutoCompartment, JSContext, JSErrNum, JSFreeOp, JSObject}; use js::jsapi::{JSPROP_READONLY, JSTracer, JS_DefinePropertyById}; -use js::jsapi::{JS_ForwardGetPropertyTo, JS_ForwardSetPropertyTo, JS_GetClass}; +use js::jsapi::{JS_ForwardGetPropertyTo, JS_ForwardSetPropertyTo}; use js::jsapi::{JS_GetOwnPropertyDescriptorById, JS_HasPropertyById}; use js::jsapi::{MutableHandle, MutableHandleObject, MutableHandleValue}; use js::jsapi::{ObjectOpResult, PropertyDescriptor}; use js::jsval::{UndefinedValue, PrivateValue}; +use js::rust::get_object_class; use msg::constellation_msg::PipelineId; use std::cell::Cell; @@ -67,7 +68,7 @@ impl BrowsingContext { let cx = window.get_cx(); let parent = window.reflector().get_jsobject(); assert!(!parent.get().is_null()); - assert!(((*JS_GetClass(parent.get())).flags & JSCLASS_IS_GLOBAL) != 0); + assert!(((*get_object_class(parent.get())).flags & JSCLASS_IS_GLOBAL) != 0); let _ac = JSAutoCompartment::new(cx, parent.get()); rooted!(in(cx) let window_proxy = NewWindowProxy(cx, parent, handler)); assert!(!window_proxy.is_null()); diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index d8530001715..7cd092e0683 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -24,10 +24,10 @@ use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; use js::glue::{IsWrapper, UnwrapObject}; use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment}; use js::jsapi::{HandleValue, Evaluate2, JSAutoCompartment, JSContext}; -use js::jsapi::{JSObject, JS_GetClass, JS_GetContext}; +use js::jsapi::{JSObject, JS_GetContext}; use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue}; use js::panic::maybe_resume_unwind; -use js::rust::CompileOptionsWrapper; +use js::rust::{CompileOptionsWrapper, get_object_class}; use libc; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; @@ -516,7 +516,7 @@ fn timestamp_in_ms(time: Timespec) -> u64 { #[allow(unsafe_code)] unsafe fn global_scope_from_global(global: *mut JSObject) -> Root { assert!(!global.is_null()); - let clasp = JS_GetClass(global); + let clasp = get_object_class(global); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); root_from_object(global).unwrap() } diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index a23b463b501..4b305f5034e 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -1089,7 +1089,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.3" -source = "git+https://github.com/servo/rust-mozjs#4f46b376a96dc3bcc53dfe2e394d09843b8a44eb" +source = "git+https://github.com/servo/rust-mozjs#342f304a455080acf64f5ceb40a7f8059481ca01" dependencies = [ "cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/servo/Cargo.lock b/ports/servo/Cargo.lock index 485332a813a..19985a2343d 100644 --- a/ports/servo/Cargo.lock +++ b/ports/servo/Cargo.lock @@ -1168,7 +1168,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.3" -source = "git+https://github.com/servo/rust-mozjs#4f46b376a96dc3bcc53dfe2e394d09843b8a44eb" +source = "git+https://github.com/servo/rust-mozjs#342f304a455080acf64f5ceb40a7f8059481ca01" dependencies = [ "cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",