-
Notifications
You must be signed in to change notification settings - Fork 215
Fix defineProperty to work with Java7 Rhino JS #207
Conversation
Apparently `Object.defineProperty(obj, 'prototype', { writable: false });` sets `obj.prototype` to `null` in Java7 Rhino JS. Naive version works, so update detection code to check that.
LGTM, maybe we should use |
I would perhaps disagree. Since defineProperty() is the method we are considering to use here, I think all tests should be directed against that method - there is a risk that the defineProperties() implementation would work slightly differently in these border-case JS engines. One alternative would perhaps be to refactor the code to always use defineProperties() instead - after all there seem to be many cases where defineProperty is called several times in a row against the same object. |
@xkr47 you're absolutely right. I was looking to merge this, and found some unit-test errors, when looking into the details, it seems that your detection is always failing. e.g. this is the output from chrome console:
then doing:
As a result, v8 will fail the detection, and will use the fallback mechanism, which is not the desired outcome here. In other words, we need a better detection for Rhino if it happens that it doesn't really support |
ok this definately needs more testing then. What did you think about using defineProperties() in general? |
@xkr47 let's stick to what it is there today, which is |
Bah I've mixed JS concepts here.. been too long since.. Hope I remember this correctly now after some thought: The standardized way to access the prototype that was used to create an object is available through
|
soo the original issue in Rhino:
So based on this if I'd update the test function to use a function (constructor) instead of an object then it should work.. Pushing change in a little while.. |
This is needed in order to be able to test the `prototype` property behaviour, and regular objects don't have that property.
I still need to verify this with Rhino. |
Alright, this makes more sense, and tests are passing. Let me know if this is enough for Rhino, and we can go from there. |
Rhino says: LGTM :) |
Good, I will merge this in the next few days. |
@caridy any chance of a new release soon? |
this Thursday! |
Apparently
Object.defineProperty(obj, 'prototype', { writable: false });
setsobj.prototype
tonull
in Java7 Rhino JS. Naive version works, so update detection code to check that.