Re: Problem with object properties/hasOwnProperty() in Spidermonkey 78

Jan de Mooij <[email protected]> Tue, 2 Feb 2021 18:25:52 +0100
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <CABTC+JdgtDHtok47HBps0LB8C=bFS0qUeu2xjDipyj7XrMZJMA@mail.gmail.com>
The cookbook example uses getters + JS_SetReservedSlot, I just realized
you're probably following that part too. In that case the getter lives on
n.__proto__ (in your example JS code) and it returns a value stored in a
slot on |n|. Question then is what the old code was doing differently,
maybe it did a JS_SetProperty/JS_DefineProperty somewhere?

Jan

On Tue, Feb 2, 2021 at 6:00 PM Jan de Mooij <[email protected]> wrote:

> On Tue, Feb 2, 2021 at 4:55 PM Miles <[email protected]> wrote:
>
>> However, for some reason I don't understand the properties that I define
>> for my class do not return true for Object.prototype.hasOwnProperty() in
>> Spidermonkey 78 but they did in Spidermonkey 1.8.5.
>> For example I define a Node class with properties x,y,z (and lots more...)
>>
>
> The properties in the JSPropertySpec that you pass to JS_InitClass (the
> 7th argument?) are defined on the prototype chain. Looking at Firefox 3 era
> code that hasn't changed and the SpiderMonkey 78 behavior is what I'd
> expect.
>
> Are these getters? If not, how do you assign the 1.1/2.2/3.3 properties in
> your constructor? Can you post all the relevant code for one of these
> properties?
>
> Thanks,
> Jan
>
>
>>
>> To do the upgrade I have been using all sorts of macros/pre-processor
>> logic so that I can compile using either the old 1.8.5 version or the new
>> 78 version of Spidermonkey until we are sure everything is working.
>> With the old 1.8.5 engine if I run the following code
>>
>> var n = new Node(1.1, 2.2, 3.3);
>> for (a in n)
>>         Message("  Property "+a+": "+n[a]);
>> Message("  n.hasOwnProperty('x') returns "+n.hasOwnProperty('x'));
>>
>> I get the output
>>
>>   Property x: 1.100000023841858
>>   Property y: 2.200000047683716
>> ...
>>   n.hasOwnProperty('x') returns true
>>
>> However, in the new Spidermonkey 78 engine I get
>>
>>   Property x: 1.100000023841858
>>   Property y: 2.200000047683716
>> ...
>>   n.hasOwnProperty('x') returns false
>>
>> i.e. In the new Spidermonkey 78 engine I can still enumerate over the
>> properties but some some unknown reason the properties are not defined in
>> this class. Presumably the engine thinks they are somehow being defined in
>> the prototype chain somewhere else...
>> There are differences as to what is exactly being executed in the
>> different engines due to my macros but I'm running the same basic code with
>> JS_InitClass etc.
>> My class stores private data and I am setting JSCLASS_HAS_PRIVATE
>> My properties are defined with the flags JSPROP_ENUMERATE|JSPROP_PERMANENT
>>
>> No doubt I'm (yet again) being stupid and missing something obvious but I
>> can't for the life of me see what the problem is.
>> Can anybody help?
>>
>> Many thanks in advance for any assistance
>>
>> Miles
>> _______________________________________________
>> dev-tech-js-engine mailing list
>> [email protected]
>> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>>
>