1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jswatchpoint.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef jswatchpoint_h 1.11 +#define jswatchpoint_h 1.12 + 1.13 +#include "jsalloc.h" 1.14 + 1.15 +#include "gc/Barrier.h" 1.16 +#include "js/HashTable.h" 1.17 +#include "js/OldDebugAPI.h" 1.18 + 1.19 +namespace js { 1.20 + 1.21 +struct WeakMapTracer; 1.22 + 1.23 +struct WatchKey { 1.24 + WatchKey() {} 1.25 + WatchKey(JSObject *obj, jsid id) : object(obj), id(id) {} 1.26 + WatchKey(const WatchKey &key) : object(key.object.get()), id(key.id.get()) {} 1.27 + EncapsulatedPtrObject object; 1.28 + EncapsulatedId id; 1.29 + 1.30 + bool operator!=(const WatchKey &other) const { 1.31 + return object != other.object || id != other.id; 1.32 + } 1.33 +}; 1.34 + 1.35 +struct Watchpoint { 1.36 + JSWatchPointHandler handler; 1.37 + EncapsulatedPtrObject closure; /* This is always marked in minor GCs and so doesn't require a postbarrier. */ 1.38 + bool held; /* true if currently running handler */ 1.39 + Watchpoint(JSWatchPointHandler handler, JSObject* closure, bool held) 1.40 + : handler(handler), closure(closure), held(held) {} 1.41 +}; 1.42 + 1.43 +template <> 1.44 +struct DefaultHasher<WatchKey> 1.45 +{ 1.46 + typedef WatchKey Lookup; 1.47 + static inline js::HashNumber hash(const Lookup &key); 1.48 + 1.49 + static bool match(const WatchKey &k, const Lookup &l) { 1.50 + return k.object == l.object && k.id.get() == l.id.get(); 1.51 + } 1.52 + 1.53 + static void rekey(WatchKey &k, const WatchKey& newKey) { 1.54 + k.object.unsafeSet(newKey.object); 1.55 + k.id.unsafeSet(newKey.id); 1.56 + } 1.57 +}; 1.58 + 1.59 +class WatchpointMap { 1.60 + public: 1.61 + typedef HashMap<WatchKey, Watchpoint, DefaultHasher<WatchKey>, SystemAllocPolicy> Map; 1.62 + 1.63 + bool init(); 1.64 + bool watch(JSContext *cx, HandleObject obj, HandleId id, 1.65 + JSWatchPointHandler handler, HandleObject closure); 1.66 + void unwatch(JSObject *obj, jsid id, 1.67 + JSWatchPointHandler *handlerp, JSObject **closurep); 1.68 + void unwatchObject(JSObject *obj); 1.69 + void clear(); 1.70 + 1.71 + bool triggerWatchpoint(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp); 1.72 + 1.73 + static bool markCompartmentIteratively(JSCompartment *c, JSTracer *trc); 1.74 + bool markIteratively(JSTracer *trc); 1.75 + void markAll(JSTracer *trc); 1.76 + static void sweepAll(JSRuntime *rt); 1.77 + void sweep(); 1.78 + 1.79 + static void traceAll(WeakMapTracer *trc); 1.80 + void trace(WeakMapTracer *trc); 1.81 + 1.82 + private: 1.83 + Map map; 1.84 +}; 1.85 + 1.86 +} 1.87 + 1.88 +#endif /* jswatchpoint_h */