Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef jswatchpoint_h
8 #define jswatchpoint_h
10 #include "jsalloc.h"
12 #include "gc/Barrier.h"
13 #include "js/HashTable.h"
14 #include "js/OldDebugAPI.h"
16 namespace js {
18 struct WeakMapTracer;
20 struct WatchKey {
21 WatchKey() {}
22 WatchKey(JSObject *obj, jsid id) : object(obj), id(id) {}
23 WatchKey(const WatchKey &key) : object(key.object.get()), id(key.id.get()) {}
24 EncapsulatedPtrObject object;
25 EncapsulatedId id;
27 bool operator!=(const WatchKey &other) const {
28 return object != other.object || id != other.id;
29 }
30 };
32 struct Watchpoint {
33 JSWatchPointHandler handler;
34 EncapsulatedPtrObject closure; /* This is always marked in minor GCs and so doesn't require a postbarrier. */
35 bool held; /* true if currently running handler */
36 Watchpoint(JSWatchPointHandler handler, JSObject* closure, bool held)
37 : handler(handler), closure(closure), held(held) {}
38 };
40 template <>
41 struct DefaultHasher<WatchKey>
42 {
43 typedef WatchKey Lookup;
44 static inline js::HashNumber hash(const Lookup &key);
46 static bool match(const WatchKey &k, const Lookup &l) {
47 return k.object == l.object && k.id.get() == l.id.get();
48 }
50 static void rekey(WatchKey &k, const WatchKey& newKey) {
51 k.object.unsafeSet(newKey.object);
52 k.id.unsafeSet(newKey.id);
53 }
54 };
56 class WatchpointMap {
57 public:
58 typedef HashMap<WatchKey, Watchpoint, DefaultHasher<WatchKey>, SystemAllocPolicy> Map;
60 bool init();
61 bool watch(JSContext *cx, HandleObject obj, HandleId id,
62 JSWatchPointHandler handler, HandleObject closure);
63 void unwatch(JSObject *obj, jsid id,
64 JSWatchPointHandler *handlerp, JSObject **closurep);
65 void unwatchObject(JSObject *obj);
66 void clear();
68 bool triggerWatchpoint(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp);
70 static bool markCompartmentIteratively(JSCompartment *c, JSTracer *trc);
71 bool markIteratively(JSTracer *trc);
72 void markAll(JSTracer *trc);
73 static void sweepAll(JSRuntime *rt);
74 void sweep();
76 static void traceAll(WeakMapTracer *trc);
77 void trace(WeakMapTracer *trc);
79 private:
80 Map map;
81 };
83 }
85 #endif /* jswatchpoint_h */