From f706123208f3db5f9b81d974a9e8a3628197c1d8 Mon Sep 17 00:00:00 2001 From: lpy Date: Wed, 26 Feb 2014 13:05:06 +0800 Subject: [PATCH] Move Traceable, trace_reflector from utils.rs to trace.rs.(fixes #1748) --- .../dom/bindings/codegen/CodegenRust.py | 3 ++- src/components/script/dom/bindings/trace.rs | 24 +++++++++++++++++-- src/components/script/dom/bindings/utils.rs | 21 ++-------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 270502aeeb6..54325c9113f 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -5339,6 +5339,7 @@ class CGBindingRoot(CGThing): 'dom::types::*', 'dom::bindings::js::JS', 'dom::bindings::utils::*', + 'dom::bindings::trace::Traceable', 'dom::bindings::callback::*', 'dom::bindings::conversions::*', 'dom::bindings::codegen::*', #XXXjdm @@ -6353,7 +6354,7 @@ class GlobalGenRoots(): allprotos = [CGGeneric(declare="#[allow(unused_imports)];\n"), CGGeneric(declare="use dom::types::*;\n"), CGGeneric(declare="use dom::bindings::js::JS;\n"), - CGGeneric(declare="use dom::bindings::utils::Traceable;\n"), + CGGeneric(declare="use dom::bindings::trace::Traceable;\n"), CGGeneric(declare="use extra::serialize::{Encodable, Encoder};\n"), CGGeneric(declare="use js::jsapi::JSTracer;\n\n")] for descriptor in descriptors: diff --git a/src/components/script/dom/bindings/trace.rs b/src/components/script/dom/bindings/trace.rs index 6565bf8c2d9..342c3110f5d 100644 --- a/src/components/script/dom/bindings/trace.rs +++ b/src/components/script/dom/bindings/trace.rs @@ -3,11 +3,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::js::JS; -use dom::bindings::utils::{Reflectable, trace_reflector, Reflector}; +use dom::bindings::utils::{Reflectable, Reflector}; -use js::jsapi::JSTracer; +use js::jsapi::{JSTracer, JS_CallTracer, JSTRACE_OBJECT}; use std::cast; +use std::libc; +use std::ptr; +use std::ptr::null; use extra::serialize::{Encodable, Encoder}; // IMPORTANT: We rely on the fact that we never attempt to encode DOM objects using @@ -26,3 +29,20 @@ impl Encodable for Reflector { fn encode(&self, _s: &mut S) { } } + +pub trait Traceable { + fn trace(&self, trc: *mut JSTracer); +} + +pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) { + unsafe { + description.to_c_str().with_ref(|name| { + (*tracer).debugPrinter = ptr::null(); + (*tracer).debugPrintIndex = -1; + (*tracer).debugPrintArg = name as *libc::c_void; + debug!("tracing {:s}", description); + JS_CallTracer(tracer as *JSTracer, reflector.get_jsobject(), + JSTRACE_OBJECT as u32); + }); + } +} diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 80787d93416..26269ddd8f5 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -30,10 +30,10 @@ use js::jsapi::{JS_GetFunctionPrototype, JS_InternString, JS_GetFunctionObject}; 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, JSTracer}; +use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative}; use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor}; use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses}; -use js::jsapi::{JSString, JS_CallTracer, JSTRACE_OBJECT}; +use js::jsapi::{JSString}; use js::jsapi::{JS_IsExceptionPending, JS_AllowGC, JS_InhibitGC}; use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType; use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS}; @@ -556,23 +556,6 @@ pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: c_uint, _vp: *mut JSVa return 0; } -pub trait Traceable { - fn trace(&self, trc: *mut JSTracer); -} - -pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) { - unsafe { - description.to_c_str().with_ref(|name| { - (*tracer).debugPrinter = ptr::null(); - (*tracer).debugPrintIndex = -1; - (*tracer).debugPrintArg = name as *libc::c_void; - debug!("tracing {:s}", description); - JS_CallTracer(tracer as *JSTracer, reflector.get_jsobject(), - JSTRACE_OBJECT as u32); - }); - } -} - pub fn initialize_global(global: *JSObject) { let protoArray = @mut ([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]); unsafe {