-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with Object.defineProperties on Android browsers #29
Comments
Hello @garryyao, It seems we should run a quick test to ensure that Object.defineProperties performs its basic function correctly. 👍 Should be an easy addition. Thanks for posting this issue. Have you found any other inconsistencies or problems on Android? -- John |
Hm. I just checked our source code and we already test the basic functionality of the native features. try {
// test it
Object.defineProperties(object, { 'sentinel2': { value: 1 } });
return 'sentinel2' in object;
}
catch (ex) { /* squelch */ } For some reason, your tests are failing, though. Do you have any idea what the substantial difference is? I wonder if it is the fact that you are declaring a function's prototype. |
Nm. I see the problem. We should change the code to test that the value is the same, not just that it exists: try {
// test it
Object.defineProperties(object, { 'sentinel2': { value: true } });
return 'sentinel2' in object && object.sentinel2 === true;
}
catch (ex) { /* squelch */ } |
…perty and Object.defineProperties). Fixes #29.
Hey @garryyao, I just pushed a quick fix to the dev branch. I don't have access to all those Android versions, atm. Do you think you could try it? Thanks! -- J |
@unscriptable, sorry for late reply. |
Yes, defining the |
Hey guys, I'm trying to understand what to do next. Should we change the tests so that they try to define a property named "prototype" instead of "sentinel1" or "sentinel2"? Is that enough to detect the problem? I'm not convinced that that is the right solution. For old Android, it seems like we should allow Object.defineProperty to work as it normally does on all property names except "prototype". Therefore, we need an additional test just for detecting failures when defining "prototype" on functions. Does this sound right? @jaredcacurak: is this something you might have some time to work on? -- John |
I'd be glad to look into it @unscriptable. |
Cool @jaredcacurak! Let's push something to a branch and see if @garryyao or @KimiZH can verify it works. |
@garryyao @KimiZH Does the test, added in the commit above, recreate the issue? |
I think we can replace the native function if 'prototype' property can not be defined. |
Object.defineProperty has the same issue. |
This issue looks to be the culprit. |
Object.defineProperties when the native implementation will not asssign a value to a function's prototype. cujojs#29
It looks good. I think this would resolve. |
The changes are good, while we might want to check the speciality of descriptor of prototype property as well, illustrated by the following tests:
|
@garryyao can you elaborate on your previous comment? |
We have to be careful not to test for every bug in every version of every browser. If these bugs re causing problems in your applications, @garryyao, then perhaps we should open another issue? Otherwise, I think we should just let old Android bugs die out with old Android phones. :) |
So poly doesn't end up being 100KB. :) |
Object.defineProperties when the native implementation will not asssign a value to a function's prototype. cujojs#29
@jaredcacurak |
Hey @jaredcacurak, I think @KimiZH's idea is probably best. Let client code use the native function in the cases where it works correctly. However, I think I'd code it differently. We should probably try to use the existing polyfill as much as possible. (If we add more assertions and such to the original polyfill, they'd also apply to this new polyfill.) I'm thinking something like this: function definePropertyFunctionPrototype (fn, name, descriptor) {
if (name === 'prototype' && typeof fn === 'function') {
// apply shim
return defineProperty(fn, name, descriptor);
}
else {
// use native
return Object.defineProperty(fn, name, descriptor);
}
} See his commit link in his previous comments for the other half of the change. Thoughts? |
Make sense. |
The native implementation of
Object.defineProperties
on Android version >= 2.3.6 && <= 4.0.3 seems to be buggy, where the following test case fails as below, can we check if we need to shim up a bit on those devices?==========Code==========
==========Code==========
==========Result=========
Platform APILevel Result
1.5 3 TypeError: Result of expression 'Object.defineProperties' [undefined] is not a function
1.6 4 TypeError: Result of expression 'Object.defineProperties' [undefined] is not a function
2.1 7 TypeError: Result of expression 'Object.defineProperties' [undefined] is not a function
2.2 8 true
2.3.3 10 true
2.3.6 x undefined
4.0 14 undefined
4.0.3 15 undefined
4.1.2 16 true
4.2.2 17 true
4.3 18 true
4.4.2 19 true
==========Result=========
The text was updated successfully, but these errors were encountered: