michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef jswatchpoint_h michael@0: #define jswatchpoint_h michael@0: michael@0: #include "jsalloc.h" michael@0: michael@0: #include "gc/Barrier.h" michael@0: #include "js/HashTable.h" michael@0: #include "js/OldDebugAPI.h" michael@0: michael@0: namespace js { michael@0: michael@0: struct WeakMapTracer; michael@0: michael@0: struct WatchKey { michael@0: WatchKey() {} michael@0: WatchKey(JSObject *obj, jsid id) : object(obj), id(id) {} michael@0: WatchKey(const WatchKey &key) : object(key.object.get()), id(key.id.get()) {} michael@0: EncapsulatedPtrObject object; michael@0: EncapsulatedId id; michael@0: michael@0: bool operator!=(const WatchKey &other) const { michael@0: return object != other.object || id != other.id; michael@0: } michael@0: }; michael@0: michael@0: struct Watchpoint { michael@0: JSWatchPointHandler handler; michael@0: EncapsulatedPtrObject closure; /* This is always marked in minor GCs and so doesn't require a postbarrier. */ michael@0: bool held; /* true if currently running handler */ michael@0: Watchpoint(JSWatchPointHandler handler, JSObject* closure, bool held) michael@0: : handler(handler), closure(closure), held(held) {} michael@0: }; michael@0: michael@0: template <> michael@0: struct DefaultHasher michael@0: { michael@0: typedef WatchKey Lookup; michael@0: static inline js::HashNumber hash(const Lookup &key); michael@0: michael@0: static bool match(const WatchKey &k, const Lookup &l) { michael@0: return k.object == l.object && k.id.get() == l.id.get(); michael@0: } michael@0: michael@0: static void rekey(WatchKey &k, const WatchKey& newKey) { michael@0: k.object.unsafeSet(newKey.object); michael@0: k.id.unsafeSet(newKey.id); michael@0: } michael@0: }; michael@0: michael@0: class WatchpointMap { michael@0: public: michael@0: typedef HashMap, SystemAllocPolicy> Map; michael@0: michael@0: bool init(); michael@0: bool watch(JSContext *cx, HandleObject obj, HandleId id, michael@0: JSWatchPointHandler handler, HandleObject closure); michael@0: void unwatch(JSObject *obj, jsid id, michael@0: JSWatchPointHandler *handlerp, JSObject **closurep); michael@0: void unwatchObject(JSObject *obj); michael@0: void clear(); michael@0: michael@0: bool triggerWatchpoint(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp); michael@0: michael@0: static bool markCompartmentIteratively(JSCompartment *c, JSTracer *trc); michael@0: bool markIteratively(JSTracer *trc); michael@0: void markAll(JSTracer *trc); michael@0: static void sweepAll(JSRuntime *rt); michael@0: void sweep(); michael@0: michael@0: static void traceAll(WeakMapTracer *trc); michael@0: void trace(WeakMapTracer *trc); michael@0: michael@0: private: michael@0: Map map; michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif /* jswatchpoint_h */