Commit ae853be8 authored by oliver@apple.com's avatar oliver@apple.com

[ES5] Implement Object.getPrototypeOf

https://bugs.webkit.org/show_bug.cgi?id=28114

Reviewed by Eric Seidel and Sam Weinig.

Implement getPrototypeOf


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@46963 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 84a177de
2009-08-08 Oliver Hunt <oliver@apple.com>
Reviewed by Eric Seidel and Sam Weinig.
[ES5] Implement Object.getPrototypeOf
https://bugs.webkit.org/show_bug.cgi?id=28114
Implement getPrototypeOf
* runtime/CommonIdentifiers.h:
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::reset):
* runtime/ObjectConstructor.cpp:
(JSC::ObjectConstructor::ObjectConstructor):
(JSC::objectConsGetPrototypeOf):
* runtime/ObjectConstructor.h:
2009-08-07 Zoltan Horvath <hzoltan@inf.u-szeged.hu>
Reviewed by Eric Seidel.
......
......@@ -42,6 +42,7 @@
macro(exec) \
macro(fromCharCode) \
macro(global) \
macro(getPrototypeOf) \
macro(hasOwnProperty) \
macro(ignoreCase) \
macro(index) \
......
......@@ -256,7 +256,7 @@ void JSGlobalObject::reset(JSValue prototype)
// Constructors
JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype);
JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get());
JSCell* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype);
JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype);
JSCell* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
......
......@@ -29,7 +29,9 @@ namespace JSC {
ASSERT_CLASS_FITS_IN_CELL(ObjectConstructor);
ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype)
static JSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*, JSObject*, JSValue, const ArgList&);
ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype, Structure* prototypeFunctionStructure)
: InternalFunction(&exec->globalData(), structure, Identifier(exec, "Object"))
{
// ECMA 15.2.3.1
......@@ -37,6 +39,8 @@ ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> stru
// no. of arguments for constructor
putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().getPrototypeOf, objectConstructorGetPrototypeOf), DontEnum);
}
// ECMA 15.2.2
......@@ -70,4 +74,11 @@ CallType ObjectConstructor::getCallData(CallData& callData)
return CallTypeHost;
}
JSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec, JSObject*, JSValue, const ArgList& args)
{
if (!args.at(0).isObject())
return throwError(exec, TypeError, "Requested prototype of a value that is not an object.");
return asObject(args.at(0))->prototype();
}
} // namespace JSC
......@@ -29,7 +29,7 @@ namespace JSC {
class ObjectConstructor : public InternalFunction {
public:
ObjectConstructor(ExecState*, PassRefPtr<Structure>, ObjectPrototype*);
ObjectConstructor(ExecState*, PassRefPtr<Structure>, ObjectPrototype*, Structure* prototypeFunctionStructure);
private:
virtual ConstructType getConstructData(ConstructData&);
......
2009-08-08 Oliver Hunt <oliver@apple.com>
Reviewed by Eric Seidel and Sam Weinig.
[ES5] Implement Object.getPrototypeOf
https://bugs.webkit.org/show_bug.cgi?id=28114
Add tests for getPrototypeOf
* fast/js/prototypes-expected.txt:
* fast/js/resources/prototypes.js:
2009-08-08 Jan Michael Alonzo <jmalonzo@webkit.org>
[Gtk] Skip media/controls-right-click-on-timebar.html as it needs
......
Test prototoypes of various objects.
Test prototypes of various objects and the various means to access them.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......@@ -20,6 +20,39 @@ PASS Array.__proto__ is Object.__proto__
PASS Date.__proto__ is Object.__proto__
PASS Number.__proto__ is Object.__proto__
PASS String.__proto__ is Object.__proto__
PASS Object.getPrototypeOf('') threw exception TypeError: Requested prototype of a value that is not an object..
PASS Object.getPrototypeOf(0) threw exception TypeError: Requested prototype of a value that is not an object..
PASS Object.getPrototypeOf([]) is Array.prototype
PASS Object.getPrototypeOf({}) is Object.prototype
PASS Object.getPrototypeOf(new Date) is Date.prototype
PASS Object.getPrototypeOf(new Number) is Number.prototype
PASS Object.getPrototypeOf(new Object) is Object.prototype
PASS Object.getPrototypeOf(new String) is String.prototype
PASS Object.getPrototypeOf(Array.prototype) is Object.prototype
PASS Object.getPrototypeOf(Date.prototype) is Object.prototype
PASS Object.getPrototypeOf(Number.prototype) is Object.prototype
PASS Object.getPrototypeOf(Object.prototype) is null
PASS Object.getPrototypeOf(String.prototype) is Object.prototype
PASS Object.getPrototypeOf(Array) is Object.__proto__
PASS Object.getPrototypeOf(Date) is Object.__proto__
PASS Object.getPrototypeOf(Number) is Object.__proto__
PASS Object.getPrototypeOf(String) is Object.__proto__
PASS String.prototype.isPrototypeOf('') is false
PASS Number.prototype.isPrototypeOf(0) is false
PASS Array.prototype.isPrototypeOf([]) is true
PASS Object.prototype.isPrototypeOf({}) is true
PASS Date.prototype.isPrototypeOf(new Date) is true
PASS Number.prototype.isPrototypeOf(new Number) is true
PASS Object.prototype.isPrototypeOf(new Object) is true
PASS String.prototype.isPrototypeOf(new String) is true
PASS Object.prototype.isPrototypeOf(Array.prototype) is true
PASS Object.prototype.isPrototypeOf(Date.prototype) is true
PASS Object.prototype.isPrototypeOf(Number.prototype) is true
PASS Object.prototype.isPrototypeOf(String.prototype) is true
PASS Object.__proto__.isPrototypeOf(Array) is true
PASS Object.__proto__.isPrototypeOf(Date) is true
PASS Object.__proto__.isPrototypeOf(Number) is true
PASS Object.__proto__.isPrototypeOf(String) is true
PASS successfullyParsed is true
TEST COMPLETE
......
description(
'Test prototoypes of various objects.'
'Test prototypes of various objects and the various means to access them.'
);
shouldBe("('').__proto__", "String.prototype");
......@@ -20,4 +20,39 @@ shouldBe("Date.__proto__", "Object.__proto__");
shouldBe("Number.__proto__", "Object.__proto__");
shouldBe("String.__proto__", "Object.__proto__");
shouldThrow("Object.getPrototypeOf('')");
shouldThrow("Object.getPrototypeOf(0)");
shouldBe("Object.getPrototypeOf([])", "Array.prototype");
shouldBe("Object.getPrototypeOf({})", "Object.prototype");
shouldBe("Object.getPrototypeOf(new Date)", "Date.prototype");
shouldBe("Object.getPrototypeOf(new Number)", "Number.prototype");
shouldBe("Object.getPrototypeOf(new Object)", "Object.prototype");
shouldBe("Object.getPrototypeOf(new String)", "String.prototype");
shouldBe("Object.getPrototypeOf(Array.prototype)", "Object.prototype");
shouldBe("Object.getPrototypeOf(Date.prototype)", "Object.prototype");
shouldBe("Object.getPrototypeOf(Number.prototype)", "Object.prototype");
shouldBe("Object.getPrototypeOf(Object.prototype)", "null");
shouldBe("Object.getPrototypeOf(String.prototype)", "Object.prototype");
shouldBe("Object.getPrototypeOf(Array)", "Object.__proto__");
shouldBe("Object.getPrototypeOf(Date)", "Object.__proto__");
shouldBe("Object.getPrototypeOf(Number)", "Object.__proto__");
shouldBe("Object.getPrototypeOf(String)", "Object.__proto__");
shouldBeFalse("String.prototype.isPrototypeOf('')");
shouldBeFalse("Number.prototype.isPrototypeOf(0)");
shouldBeTrue("Array.prototype.isPrototypeOf([])");
shouldBeTrue("Object.prototype.isPrototypeOf({})");
shouldBeTrue("Date.prototype.isPrototypeOf(new Date)");
shouldBeTrue("Number.prototype.isPrototypeOf(new Number)");
shouldBeTrue("Object.prototype.isPrototypeOf(new Object)");
shouldBeTrue("String.prototype.isPrototypeOf(new String)");
shouldBeTrue("Object.prototype.isPrototypeOf(Array.prototype)");
shouldBeTrue("Object.prototype.isPrototypeOf(Date.prototype)");
shouldBeTrue("Object.prototype.isPrototypeOf(Number.prototype)");
shouldBeTrue("Object.prototype.isPrototypeOf(String.prototype)");
shouldBeTrue("Object.__proto__.isPrototypeOf(Array)");
shouldBeTrue("Object.__proto__.isPrototypeOf(Date)");
shouldBeTrue("Object.__proto__.isPrototypeOf(Number)");
shouldBeTrue("Object.__proto__.isPrototypeOf(String)");
var successfullyParsed = true;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment