Ignore:
Timestamp:
Jan 21, 2010, 12:46:03 PM (15 years ago)
Author:
[email protected]
Message:

2010-01-21 Kent Hansen <[email protected]>

Reviewed by Geoffrey Garen.

Object.getOwnPropertyDescriptor always returns undefined for JS API objects
https://bugs.webkit.org/show_bug.cgi?id=33946

Ideally the getOwnPropertyDescriptor() reimplementation should return an
access descriptor that wraps the property getter and setter callbacks, but
that approach is much more involved than returning a value descriptor.
Keep it simple for now.

  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h: (JSC::::getOwnPropertyDescriptor):
  • API/tests/testapi.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/tests/testapi.js

    r43603 r53638  
    114114    fail("MyObject.regularType was not enumerated");
    115115
     116var alwaysOneDescriptor = Object.getOwnPropertyDescriptor(MyObject, "alwaysOne");
     117shouldBe('typeof alwaysOneDescriptor', "object");
     118shouldBe('alwaysOneDescriptor.value', MyObject.alwaysOne);
     119shouldBe('alwaysOneDescriptor.configurable', true);
     120shouldBe('alwaysOneDescriptor.enumerable', false); // Actually it is.
     121var cantFindDescriptor = Object.getOwnPropertyDescriptor(MyObject, "cantFind");
     122shouldBe('typeof cantFindDescriptor', "object");
     123shouldBe('cantFindDescriptor.value', MyObject.cantFind);
     124shouldBe('cantFindDescriptor.configurable', true);
     125shouldBe('cantFindDescriptor.enumerable', false);
     126try {
     127    // If getOwnPropertyDescriptor() returned an access descriptor, this wouldn't throw.
     128    Object.getOwnPropertyDescriptor(MyObject, "throwOnGet");
     129} catch (e) {
     130    pass("getting property descriptor of throwOnGet threw exception");
     131}
     132var myPropertyNameDescriptor = Object.getOwnPropertyDescriptor(MyObject, "myPropertyName");
     133shouldBe('typeof myPropertyNameDescriptor', "object");
     134shouldBe('myPropertyNameDescriptor.value', MyObject.myPropertyName);
     135shouldBe('myPropertyNameDescriptor.configurable', true);
     136shouldBe('myPropertyNameDescriptor.enumerable', false); // Actually it is.
     137try {
     138    // if getOwnPropertyDescriptor() returned an access descriptor, this wouldn't throw.
     139    Object.getOwnPropertyDescriptor(MyObject, "hasPropertyLie");
     140} catch (e) {
     141    pass("getting property descriptor of hasPropertyLie threw exception");
     142}
     143shouldBe('Object.getOwnPropertyDescriptor(MyObject, "doesNotExist")', undefined);
     144
    116145myObject = new MyObject();
    117146
     
    156185shouldBe("derived.protoDup = 0", 2);
    157186
     187shouldBe('Object.getOwnPropertyDescriptor(derived, "baseProto")', undefined);
     188shouldBe('Object.getOwnPropertyDescriptor(derived, "baseProtoDup")', undefined);
     189var baseDupDescriptor = Object.getOwnPropertyDescriptor(derived, "baseDup");
     190shouldBe('typeof baseDupDescriptor', "object");
     191shouldBe('baseDupDescriptor.value', derived.baseDup);
     192shouldBe('baseDupDescriptor.configurable', true);
     193shouldBe('baseDupDescriptor.enumerable', false);
     194var baseOnlyDescriptor = Object.getOwnPropertyDescriptor(derived, "baseOnly");
     195shouldBe('typeof baseOnlyDescriptor', "object");
     196shouldBe('baseOnlyDescriptor.value', derived.baseOnly);
     197shouldBe('baseOnlyDescriptor.configurable', true);
     198shouldBe('baseOnlyDescriptor.enumerable', false);
     199shouldBe('Object.getOwnPropertyDescriptor(derived, "protoOnly")', undefined);
     200var protoDupDescriptor = Object.getOwnPropertyDescriptor(derived, "protoDup");
     201shouldBe('typeof protoDupDescriptor', "object");
     202shouldBe('protoDupDescriptor.value', derived.protoDup);
     203shouldBe('protoDupDescriptor.configurable', true);
     204shouldBe('protoDupDescriptor.enumerable', false);
     205var derivedOnlyDescriptor = Object.getOwnPropertyDescriptor(derived, "derivedOnly");
     206shouldBe('typeof derivedOnlyDescriptor', "object");
     207shouldBe('derivedOnlyDescriptor.value', derived.derivedOnly);
     208shouldBe('derivedOnlyDescriptor.configurable', true);
     209shouldBe('derivedOnlyDescriptor.enumerable', false);
     210
    158211shouldBe("undefined instanceof MyObject", false);
    159212EvilExceptionObject.hasInstance = function f() { return f(); };
Note: See TracChangeset for help on using the changeset viewer.