Skip to content
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

Kindle Fire HD 8.9: Uncaught TypeError: Cannot redefine property: defineProperty #373

Closed
anton-rodin opened this issue Jan 14, 2016 · 7 comments · Fixed by #394
Closed

Comments

@anton-rodin
Copy link

I use es5-shim as node module and making build via webpack.

For Kindle Fire HD 8.9 Android 4.0.3 I've got this error:
undefined: Uncaught TypeError: Cannot redefine property: defineProperty

Here is the context:

    if (supportsDescriptors) {
        var ensureNonEnumerable = function (obj, prop) {
            if (isEnum(obj, prop)) {
                var desc = Object.getOwnPropertyDescriptor(obj, prop);
                desc.enumerable = false;
                Object.defineProperty(obj, prop, desc); // <------------ it happened here!
            }
        };
        ensureNonEnumerable(Error.prototype, 'message');
        if (Error.prototype.message !== '') {
          Error.prototype.message = '';

User-Agent: Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; WFJWAE Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30

Could you please fix it?
Thanks :)

@Xotic750
Copy link
Contributor

This is all the related code from the library, with use strict added as I don't know what your bundle is adding to/or changing in the build.

'use strict';

var isEnum = Function.prototype.call.bind(Object.prototype.propertyIsEnumerable);

var supportsDescriptors = Object.defineProperty && (function() {
  try {
    var obj = {};
    Object.defineProperty(obj, 'x', {
      enumerable: false,
      value: obj
    });
    for (var _ in obj) {
      return false;
    }
    return obj.x === obj;
  } catch (e) { /* this is ES3 */
    return false;
  }
}());

if (supportsDescriptors) {
  var ensureNonEnumerable = function(obj, prop) {
    if (isEnum(obj, prop)) {
      var desc = Object.getOwnPropertyDescriptor(obj, prop);
      desc.enumerable = false;
      Object.defineProperty(obj, prop, desc);
    }
  };
  ensureNonEnumerable(Error.prototype, 'message');
  if (Error.prototype.message !== '') {
    Error.prototype.message = '';
  }
  ensureNonEnumerable(Error.prototype, 'name');
}

You will see that defineProperty is not being redefined at any point, it only affects Error.prototype and the properties message and name and only under the condition that they are enumerable. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable which appears to be supported.

It looks like you will need to perform some further investigation to narrow down the issue and for a fix to be possible.

Here is that code, as a jsfiddle https://jsfiddle.net/Xotic750/sLepdpfz/ and you can perhaps try it on Android 4.0.3 and see if any error is thrown.

@anton-rodin
Copy link
Author

I run your code on Kindle Fire HD 8.9 Android 4.0.3 and I've got the same error.
Here is call stack error https://app.getsentry.com/share/issue/36313732342e313036343732383338/

Code:

try {
    "use strict";

    var isEnum = Function.prototype.call.bind(Object.prototype.propertyIsEnumerable);

    var supportsDescriptors = Object.defineProperty && (function() {
        try {
            var obj = {};
            Object.defineProperty(obj, "x", {
                enumerable: false,
                value: obj
            });
            for (var _ in obj) { // eslint-disable-line
                return false;
            }
            return obj.x === obj;
        } catch (e) { /* this is ES3 */
            return false;
        }
    }());

    if (supportsDescriptors) {
        var ensureNonEnumerable = function(obj, prop) {
            if (isEnum(obj, prop)) {
                var desc = Object.getOwnPropertyDescriptor(obj, prop);
                desc.enumerable = false;
                Object.defineProperty(obj, prop, desc);
            }
        };
        ensureNonEnumerable(Error.prototype, "message");
        if (Error.prototype.message !== "") {
            Error.prototype.message = "";
        }
        ensureNonEnumerable(Error.prototype, "name");
    }
} catch (e) {
    trackError(e);
}

@ljharb
Copy link
Member

ljharb commented Jan 14, 2016

It's entirely possible that the Kindle Fire Android browser has some new bugs we've yet to encounter.

Thanks for sharing the call stack! Can you provide one that's not using webpack? Webpack is known to sometimes mess with dependencies (unlike browserify which never touches anything in node_modules) so I want to eliminate that as a problem.

Another possibility is that var defineProperty = … is breaking - some old browsers have issues with naming a variable toString, for example. It would be very strange to have an ES5 browser with this bug, though.

@Xotic750
Copy link
Contributor

@sloot14 The stack trace appear to have es5-shim plus the code snippet that I supplied and other code too, is it possible that you could execute just the code that I supplied so that it could be narrowed down?

@anton-rodin
Copy link
Author

Here it is:
https://app.getsentry.com/share/issue/36313732342e313036353035383034/
The same result.
I actually using browserstack for testing, you can use it to reproduce the error

@Xotic750
Copy link
Contributor

I'm unable to get a stable connection to browserstack. You could try and run the es5-shim browser test https://rawgit.com/es-shims/es5-shim/master/tests/index.html and see what you get.

@ljharb ljharb changed the title undefined: Uncaught TypeError: Cannot redefine property: defineProperty Kindle Fire HD 8.9: Uncaught TypeError: Cannot redefine property: defineProperty Jan 27, 2016
@Xotic750
Copy link
Contributor

I managed to run the tests.
No mention of failure with defineProperty, just with Function#apply, Function#bind and enumerable properties on Error.

bs_android_tablet_amazon kindle fire hd 8 9-4 0-1200x1920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants