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

Function.prototype.name bug in Internet Explorer #12294

Closed
3 of 13 tasks
ben-girardet opened this issue Sep 27, 2017 · 3 comments
Closed
3 of 13 tasks

Function.prototype.name bug in Internet Explorer #12294

ben-girardet opened this issue Sep 27, 2017 · 3 comments
Labels

Comments

@ben-girardet
Copy link

Description of the problem

I'm using THREE in an Aurelia-CLI project. It means it is loaded using modules and RequireJS. It works all fine except in Internet Explorer (tested in IE 11).

The code that breaks is the following (in the polyfill section at the top, lines 42-57) in the /build/three.js file

if ( Function.prototype.name === undefined ) {

  // Missing in IE
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name

  Object.defineProperty( Function.prototype, 'name', {

    get: function () {

      return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];

    }

  } );

}

It returns the can't redefine non-configurable property "name" error.

Following this post I've tried to replace the code above with:

if (!(function f() {}).name) {
  Object.defineProperty(Function.prototype, 'name', {
    get: function() {
      var name = (this.toString().match(/^function\s*([^\s(]+)/) || [])[1];
      // For better performance only parse once, and then cache the
      // result through a new accessor for repeated access.
      Object.defineProperty(this, 'name', { value: name });
      return name;
    }
  });
}

And it fixes the problem !

=> It seems that the polyfill code currently used in /build/three.js doesn't work well. Is it possible to replace this code for future builds ?

Three.js version
  • Dev
  • r87
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
@mrdoob
Copy link
Owner

mrdoob commented Sep 27, 2017

Would change the check to this make any difference?

if ( 'name' in Function.prototype === false ) {

Or

if ( Function.prototype.hasOwnProperty( 'name' ) === false ) {

@ben-girardet
Copy link
Author

I confirm that only changing the if is enough.

if ( 'name' in Function.prototype === false ) {

it the way to go!

@mrdoob
Copy link
Owner

mrdoob commented Oct 2, 2017

Fixed. Thanks!

@mrdoob mrdoob closed this as completed Oct 2, 2017
@mrdoob mrdoob added Bug and removed Bug (easy) labels Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants