Changeset 46963 in webkit


Ignore:
Timestamp:
Aug 9, 2009 3:33:57 AM (15 years ago)
Author:
oliver@apple.com
Message:

[ES5] Implement Object.getPrototypeOf
https://bugs.webkit.org/show_bug.cgi?id=28114

Reviewed by Eric Seidel and Sam Weinig.

Implement getPrototypeOf

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r46933 r46963  
     12009-08-08  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Eric Seidel and Sam Weinig.
     4
     5        [ES5] Implement Object.getPrototypeOf
     6        https://bugs.webkit.org/show_bug.cgi?id=28114
     7
     8        Implement getPrototypeOf
     9
     10        * runtime/CommonIdentifiers.h:
     11        * runtime/JSGlobalObject.cpp:
     12        (JSC::JSGlobalObject::reset):
     13        * runtime/ObjectConstructor.cpp:
     14        (JSC::ObjectConstructor::ObjectConstructor):
     15        (JSC::objectConsGetPrototypeOf):
     16        * runtime/ObjectConstructor.h:
     17
    1182009-08-07  Zoltan Horvath  <hzoltan@inf.u-szeged.hu>
    219
  • trunk/JavaScriptCore/runtime/CommonIdentifiers.h

    r45891 r46963  
    4343    macro(fromCharCode) \
    4444    macro(global) \
     45    macro(getPrototypeOf) \
    4546    macro(hasOwnProperty) \
    4647    macro(ignoreCase) \
  • trunk/JavaScriptCore/runtime/JSGlobalObject.cpp

    r44550 r46963  
    257257    // Constructors
    258258
    259     JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype);
     259    JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get());
    260260    JSCell* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype);
    261261    JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype);
  • trunk/JavaScriptCore/runtime/ObjectConstructor.cpp

    r43372 r46963  
    3030ASSERT_CLASS_FITS_IN_CELL(ObjectConstructor);
    3131
    32 ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype)
     32static JSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*, JSObject*, JSValue, const ArgList&);
     33
     34ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype, Structure* prototypeFunctionStructure)
    3335    : InternalFunction(&exec->globalData(), structure, Identifier(exec, "Object"))
    3436{
     
    3840    // no. of arguments for constructor
    3941    putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
     42
     43    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().getPrototypeOf, objectConstructorGetPrototypeOf), DontEnum);
    4044}
    4145
     
    7175}
    7276
     77JSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec, JSObject*, JSValue, const ArgList& args)
     78{
     79    if (!args.at(0).isObject())
     80        return throwError(exec, TypeError, "Requested prototype of a value that is not an object.");
     81    return asObject(args.at(0))->prototype();
     82}
     83
    7384} // namespace JSC
  • trunk/JavaScriptCore/runtime/ObjectConstructor.h

    r38440 r46963  
    3030    class ObjectConstructor : public InternalFunction {
    3131    public:
    32         ObjectConstructor(ExecState*, PassRefPtr<Structure>, ObjectPrototype*);
     32        ObjectConstructor(ExecState*, PassRefPtr<Structure>, ObjectPrototype*, Structure* prototypeFunctionStructure);
    3333
    3434    private:
  • trunk/LayoutTests/ChangeLog

    r46960 r46963  
     12009-08-08  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Eric Seidel and Sam Weinig.
     4
     5        [ES5] Implement Object.getPrototypeOf
     6        https://bugs.webkit.org/show_bug.cgi?id=28114
     7
     8        Add tests for getPrototypeOf
     9
     10        * fast/js/prototypes-expected.txt:
     11        * fast/js/resources/prototypes.js:
     12
    1132009-08-08  Jan Michael Alonzo  <jmalonzo@webkit.org>
    214
  • trunk/LayoutTests/fast/js/prototypes-expected.txt

    r43506 r46963  
    1 Test prototoypes of various objects.
     1Test prototypes of various objects and the various means to access them.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     
    2121PASS Number.__proto__ is Object.__proto__
    2222PASS String.__proto__ is Object.__proto__
     23PASS Object.getPrototypeOf('') threw exception TypeError: Requested prototype of a value that is not an object..
     24PASS Object.getPrototypeOf(0) threw exception TypeError: Requested prototype of a value that is not an object..
     25PASS Object.getPrototypeOf([]) is Array.prototype
     26PASS Object.getPrototypeOf({}) is Object.prototype
     27PASS Object.getPrototypeOf(new Date) is Date.prototype
     28PASS Object.getPrototypeOf(new Number) is Number.prototype
     29PASS Object.getPrototypeOf(new Object) is Object.prototype
     30PASS Object.getPrototypeOf(new String) is String.prototype
     31PASS Object.getPrototypeOf(Array.prototype) is Object.prototype
     32PASS Object.getPrototypeOf(Date.prototype) is Object.prototype
     33PASS Object.getPrototypeOf(Number.prototype) is Object.prototype
     34PASS Object.getPrototypeOf(Object.prototype) is null
     35PASS Object.getPrototypeOf(String.prototype) is Object.prototype
     36PASS Object.getPrototypeOf(Array) is Object.__proto__
     37PASS Object.getPrototypeOf(Date) is Object.__proto__
     38PASS Object.getPrototypeOf(Number) is Object.__proto__
     39PASS Object.getPrototypeOf(String) is Object.__proto__
     40PASS String.prototype.isPrototypeOf('') is false
     41PASS Number.prototype.isPrototypeOf(0) is false
     42PASS Array.prototype.isPrototypeOf([]) is true
     43PASS Object.prototype.isPrototypeOf({}) is true
     44PASS Date.prototype.isPrototypeOf(new Date) is true
     45PASS Number.prototype.isPrototypeOf(new Number) is true
     46PASS Object.prototype.isPrototypeOf(new Object) is true
     47PASS String.prototype.isPrototypeOf(new String) is true
     48PASS Object.prototype.isPrototypeOf(Array.prototype) is true
     49PASS Object.prototype.isPrototypeOf(Date.prototype) is true
     50PASS Object.prototype.isPrototypeOf(Number.prototype) is true
     51PASS Object.prototype.isPrototypeOf(String.prototype) is true
     52PASS Object.__proto__.isPrototypeOf(Array) is true
     53PASS Object.__proto__.isPrototypeOf(Date) is true
     54PASS Object.__proto__.isPrototypeOf(Number) is true
     55PASS Object.__proto__.isPrototypeOf(String) is true
    2356PASS successfullyParsed is true
    2457
  • trunk/LayoutTests/fast/js/resources/prototypes.js

    r43506 r46963  
    11description(
    2 'Test prototoypes of various objects.'
     2'Test prototypes of various objects and the various means to access them.'
    33);
    44
     
    2121shouldBe("String.__proto__", "Object.__proto__");
    2222
     23shouldThrow("Object.getPrototypeOf('')");
     24shouldThrow("Object.getPrototypeOf(0)");
     25shouldBe("Object.getPrototypeOf([])", "Array.prototype");
     26shouldBe("Object.getPrototypeOf({})", "Object.prototype");
     27shouldBe("Object.getPrototypeOf(new Date)", "Date.prototype");
     28shouldBe("Object.getPrototypeOf(new Number)", "Number.prototype");
     29shouldBe("Object.getPrototypeOf(new Object)", "Object.prototype");
     30shouldBe("Object.getPrototypeOf(new String)", "String.prototype");
     31shouldBe("Object.getPrototypeOf(Array.prototype)", "Object.prototype");
     32shouldBe("Object.getPrototypeOf(Date.prototype)", "Object.prototype");
     33shouldBe("Object.getPrototypeOf(Number.prototype)", "Object.prototype");
     34shouldBe("Object.getPrototypeOf(Object.prototype)", "null");
     35shouldBe("Object.getPrototypeOf(String.prototype)", "Object.prototype");
     36shouldBe("Object.getPrototypeOf(Array)", "Object.__proto__");
     37shouldBe("Object.getPrototypeOf(Date)", "Object.__proto__");
     38shouldBe("Object.getPrototypeOf(Number)", "Object.__proto__");
     39shouldBe("Object.getPrototypeOf(String)", "Object.__proto__");
     40
     41shouldBeFalse("String.prototype.isPrototypeOf('')");
     42shouldBeFalse("Number.prototype.isPrototypeOf(0)");
     43shouldBeTrue("Array.prototype.isPrototypeOf([])");
     44shouldBeTrue("Object.prototype.isPrototypeOf({})");
     45shouldBeTrue("Date.prototype.isPrototypeOf(new Date)");
     46shouldBeTrue("Number.prototype.isPrototypeOf(new Number)");
     47shouldBeTrue("Object.prototype.isPrototypeOf(new Object)");
     48shouldBeTrue("String.prototype.isPrototypeOf(new String)");
     49shouldBeTrue("Object.prototype.isPrototypeOf(Array.prototype)");
     50shouldBeTrue("Object.prototype.isPrototypeOf(Date.prototype)");
     51shouldBeTrue("Object.prototype.isPrototypeOf(Number.prototype)");
     52shouldBeTrue("Object.prototype.isPrototypeOf(String.prototype)");
     53shouldBeTrue("Object.__proto__.isPrototypeOf(Array)");
     54shouldBeTrue("Object.__proto__.isPrototypeOf(Date)");
     55shouldBeTrue("Object.__proto__.isPrototypeOf(Number)");
     56shouldBeTrue("Object.__proto__.isPrototypeOf(String)");
     57
    2358var successfullyParsed = true;
Note: See TracChangeset for help on using the changeset viewer.