Hello Steve,

thank you for your reply.

Am 09.01.2014 21:47, schrieb Steve Fink:
> 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?
Yes I'm doing experimental work on transparent proxies, but I hope this
gives not a really bad perf. I will evaluate it later. I try to change
as few as possible on the program structure to increase the acceptance
for this thematic.
But I think you're correct and I can only define the operator outside
JS::Value to get it to work. Is it really possible to create it in
jsapi.cpp, because Value.h is an include in jsapi.h(-->Circle include)?

If I understand it correct with "JS_GetObjectRuntime" I get the Runtime
and there is only one. With "DefaultJSContext(rt)" I get the correct
Context if only one is available or the default in an multi-threading
application.
If I have a multi-threaded application and the object has an other
Context as the default is this correct or not? If not how can I get the
correct?
>> 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.
You mean I should declarate it as extern in Value.h and implement it in
jsproxy.cpp?
>
Thanks
Andreas
_______________________________________________
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

Reply via email to