On 01/06/2014 09:25 AM, Andreas Schlegel wrote: > Hello, > > I need the JSContext to declare JS::RootedObjects or Values. > Especially for the case of WeakMap/Map/Set-Hasher I don't have the > JSContext. > > At the moment I use the following implementation to get the JSContext > (this is a code snipped of a hash-function): > > JSRuntime * rt = JS_GetObjectRuntime(&value.toObject()); > JSContext *cx = DefaultJSContext(rt); > return DefaultHasher<JSObject > *>::hash(value.toObject().GetIdentityObject(cx)); > > If I want to change the operator== of Value.h, I cannot use the first > two functions, because they aren't known and I cannot include jsapi.h > because of circle include errors. > > Is there a better way to retrieve the JSContext from JS::Value or JSObject?
No, since Values and JSObjects are not associated with JSContexts. JSContexts relate to control flow, and are independent of the data. One way to solve this would be to reimplement the JSRuntime rooters, and automatically fetch the runtime from TLS. We had that before, but removed it because it was such a large perf footgun. It sounds like Gecko has places where it would be properly used, though, so we should perhaps add it back in some form. AIUI, you're doing experimental work on transparent proxies. I assume perf doesn't matter too much? (Must not, if you're willing to make '==' way way more complex!) Then why not make operator== out of line and define it in jsapi.cpp or somewhere? > > My sencond question is: > Where is the best place for the GetIdentityObject-function? Because > JSObject and most other files are also not known to Value.h. I've tried > to include jsproxy.h with my function, which leads also to a circle include. What types does it require? I'd kind of expect it to be declared in Value.h and defined somewhere like jsproxy.cpp. _______________________________________________ dev-tech-js-engine-internals mailing list dev-tech-js-engine-internals@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals