IE8 error

47 views
Skip to first unread message

Nathan Stott

unread,
Jun 17, 2010, 10:33:17 AM6/17/10
to trai...@googlegroups.com
When using TraitJS, this works in IE8:

Trait({})

This does not work:
Trait({ test: "a" });

I get an error of "Object expected"

Tom Van Cutsem

unread,
Jun 17, 2010, 1:46:07 PM6/17/10
to traits-js
I was able to reproduce the error, but it seems to be a bug outside the scope of the traits.js library.

When I execute the following in the IE8 developer console, with Browser mode set to IE8 and Document mode set to IE8 Standards, I get the error you describe:

Object.getOwnPropertyDescriptor({x:5}, 'x')

Executing Object.getOwnPropertyDescriptor.toString() tells me this is the native, built-in method. I tried various other arguments and could not get this method to work. It seems like IE8 implements the ES5 standard 'Object.getOwnPropertyDescriptor' method simply by throwing an exception. In an ES3 browser, Object.getOwnPropertyDescriptor should be undefined. In an ES5 browser, I expect it to behave according to the spec. IE8 seems to conform to neither behavior :-/

2010/6/17 Nathan Stott <nrs...@gmail.com>

Nathan Stott

unread,
Jun 17, 2010, 2:31:03 PM6/17/10
to trai...@googlegroups.com
I actually messed with this quite a bit today and discovered that Object.getOwnPropertyDescriptor only works properly on DOM elements in IE8.  This is about the worst way MS could've implemented it.  It would've been better to have left it out.

Mark S. Miller

unread,
Jun 17, 2010, 8:31:18 PM6/17/10
to trai...@googlegroups.com, Allen Wirfs-Brock
Sorry, I should have spotted this. Nathan's diagnosis is exactly correct. Because of IE8, everyone, including traits.js, should do a more complex feature test for whether these methods are there and seem to work on normal objects. Bleh.
--
    Cheers,
    --MarkM

Nathan Stott

unread,
Jun 17, 2010, 9:45:38 PM6/17/10
to trai...@googlegroups.com
What is the more complicated feature test that should be used?

Mark Miller

unread,
Jun 17, 2010, 11:24:06 PM6/17/10
to trai...@googlegroups.com
How about

  function hasGOPD() {
    var gopd = Object.getOwnPropertyDescriptor;
    if (!gopd) { return false; }
    try {
      return !!gopd({x: 5}, 'x');
    } catch (ex) {
      return false;
    }
  }

?
--
Text by me above is hereby placed in the public domain

   Cheers,
   --MarkM

Tom Van Cutsem

unread,
Jun 18, 2010, 2:32:53 AM6/18/10
to trai...@googlegroups.com
Oh dear...

What about all the other Object.* methods on IE8? Are they equally unreliable? (Object.getOwnProperties, Object.defineProperty, Object.defineProperties, ...) I'll try to test these later.

I'm very reluctant to add this to the library, but I guess we have little choice in the matter.

2010/6/18 Mark Miller <eri...@gmail.com>

Tom Van Cutsem

unread,
Jun 18, 2010, 7:56:53 AM6/18/10
to traits-js
Apparently, Object.defineProperty requires the same kind of feature test. Object.defineProperties and Object.getOwnPropertynames are undefined in IE8. I updated the library and the tests now all seem to pass in IE8. Let me know if you encounter more issues.

Cheers,
Tom

2010/6/18 Tom Van Cutsem <tvcu...@gmail.com>
Reply all
Reply to author
Forward
0 new messages