From 1a9a5c3c1462bd3b3e7905ee2834a5ba906f0214 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 30 Sep 2013 22:13:17 -0400 Subject: [PATCH] Add finalize and trace hooks for proxies. --- glue.rs | 5 +++-- jsglue.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/glue.rs b/glue.rs index cef0fa829..4c7a0c23d 100644 --- a/glue.rs +++ b/glue.rs @@ -44,9 +44,10 @@ pub struct ProxyTraps { //regexp_toShared: *u8, defaultValue: *u8, iteratorNext: *u8, - finalize: *u8, + finalize: extern "C" fn(*JSFreeOp, *JSObject), getElementIfPresent: *u8, - getPrototypeOf: *u8 + getPrototypeOf: *u8, + trace: Option } #[link_args="-ljsglue"] diff --git a/jsglue.cpp b/jsglue.cpp index dbc45abf4..6b31aa13a 100644 --- a/jsglue.cpp +++ b/jsglue.cpp @@ -59,6 +59,7 @@ struct ProxyTraps { bool (*getElementIfPresent)(JSContext *cx, JSObject *obj, JSObject *receiver, uint32_t index, JS::Value *vp, bool *present); bool (*getPrototypeOf)(JSContext *cx, JSObject *proxy, JSObject **proto); + void (*trace)(JSTracer *trc, JSObject *proxy); }; int HandlerFamily = js::JSSLOT_PROXY_EXTRA + 0 /*JSPROXYSLOT_EXPANDO*/; @@ -256,6 +257,13 @@ class ForwardingProxyHandler : public js::BaseProxyHandler mTraps.getPrototypeOf(cx, proxy, proto) : BaseProxyHandler::getPrototypeOf(cx, proxy, proto); } + + virtual void trace(JSTracer *trc, JSObject *proxy) + { + return mTraps.trace ? + mTraps.trace(trc, proxy) : + BaseProxyHandler::trace(trc, proxy); + } }; extern "C" {