Commit 19e49e17 authored by ricow@chromium.org's avatar ricow@chromium.org

Enabled es5conform tests for new array methods and corrected errors that was...

Enabled es5conform tests for new array methods and corrected errors that was discovered by enabling these.

Added new es5 methods:
GetOwnPropertyDescriptor
GetOwnProperty
FromPropertyDescriptor

Review URL: http://codereview.chromium.org/546032

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3595 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 39b9f57f
......@@ -919,7 +919,7 @@ function ArrayForEach(f, receiver) {
}
// Pull out the length so that modifications to the length in the
// loop will not affect the looping.
var length = this.length;
var length = TO_UINT32(this.length);
for (var i = 0; i < length; i++) {
var current = this[i];
if (!IS_UNDEFINED(current) || i in this) {
......@@ -937,7 +937,7 @@ function ArraySome(f, receiver) {
}
// Pull out the length so that modifications to the length in the
// loop will not affect the looping.
var length = this.length;
var length = TO_UINT32(this.length);
for (var i = 0; i < length; i++) {
var current = this[i];
if (!IS_UNDEFINED(current) || i in this) {
......@@ -954,25 +954,23 @@ function ArrayEvery(f, receiver) {
}
// Pull out the length so that modifications to the length in the
// loop will not affect the looping.
var length = this.length;
var length = TO_UINT32(this.length);
for (var i = 0; i < length; i++) {
var current = this[i];
if (!IS_UNDEFINED(current) || i in this) {
if (!f.call(receiver, current, i, this)) return false;
}
}
return true;
}
function ArrayMap(f, receiver) {
if (!IS_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
}
// Pull out the length so that modifications to the length in the
// loop will not affect the looping.
var length = this.length;
var length = TO_UINT32(this.length);
var result = new $Array(length);
for (var i = 0; i < length; i++) {
var current = this[i];
......@@ -985,6 +983,9 @@ function ArrayMap(f, receiver) {
function ArrayIndexOf(element, index) {
if (IS_UNDEFINED(element)) {
throw MakeTypeError('array_indexof_not_defined', [element]);
}
var length = this.length;
if (index == null) {
index = 0;
......
......@@ -179,7 +179,8 @@ function FormatMessage(message) {
invalid_json: "String '%0' is not valid JSON",
circular_structure: "Converting circular structure to JSON",
object_keys_non_object: "Object.keys called on non-object",
object_get_prototype_non_object: "Object.getPrototypeOf called on non-object"
object_get_prototype_non_object: "Object.getPrototypeOf called on non-object",
array_indexof_not_defined: "Array.getIndexOf: Argument undefined"
};
}
var format = kMessages[message.type];
......
......@@ -559,6 +559,67 @@ static Object* Runtime_IsConstructCall(Arguments args) {
}
// Recursively traverses hidden prototypes if property is not found
static void GetOwnPropertyImplementation(JSObject* obj,
String* name,
LookupResult* result) {
obj->LocalLookupRealNamedProperty(name, result);
if (!result->IsProperty()) {
Object* proto = obj->GetPrototype();
if (proto->IsJSObject() &&
JSObject::cast(proto)->map()->is_hidden_prototype())
GetOwnPropertyImplementation(JSObject::cast(proto),
name, result);
}
}
// Returns an array with the property description:
// if args[1] is not a property on args[0]
// returns undefined
// if args[1] is a data property on args[0]
// [false, value, Writeable, Enumerable, Configurable]
// if args[1] is an accessor on args[0]
// [true, GetFunction, SetFunction, Enumerable, Configurable]
static Object* Runtime_GetOwnProperty(Arguments args) {
HandleScope scope;
Handle<FixedArray> elms = Factory::NewFixedArray(5);
Handle<JSArray> desc = Factory::NewJSArrayWithElements(elms);
LookupResult result;
CONVERT_CHECKED(JSObject, obj, args[0]);
CONVERT_CHECKED(String, name, args[1]);
// Use recursive implementation to also traverse hidden prototypes
GetOwnPropertyImplementation(obj, name, &result);
if (!result.IsProperty())
return Heap::undefined_value();
if (result.type() == CALLBACKS) {
elms->set(0, Heap::true_value());
Object* structure = result.GetCallbackObject();
if (structure->IsProxy()) {
Object* value = obj->GetPropertyWithCallback(
obj, structure, name, result.holder());
elms->set(1, value);
elms->set(2, Heap::ToBoolean(!result.IsReadOnly()));
} else {
elms->set(1, FixedArray::cast(structure)->get(0));
elms->set(2, FixedArray::cast(structure)->get(1));
}
} else {
elms->set(0, Heap::false_value());
elms->set(1, result.GetLazyValue());
elms->set(2, Heap::ToBoolean(!result.IsReadOnly()));
}
elms->set(3, Heap::ToBoolean(!result.IsDontEnum()));
elms->set(4, Heap::ToBoolean(!result.IsReadOnly()));
return *desc;
}
static Object* Runtime_RegExpCompile(Arguments args) {
HandleScope scope;
ASSERT(args.length() == 3);
......
......@@ -61,6 +61,8 @@ namespace internal {
\
F(IsConstructCall, 0, 1) \
\
F(GetOwnProperty, 2, 1) \
\
/* Utilities */ \
F(GetCalledFunction, 0, 1) \
F(GetFunctionDelegate, 1, 1) \
......
......@@ -305,6 +305,22 @@ function IsInconsistentDescriptor(desc) {
return IsAccessorDescriptor(desc) && IsDataDescriptor(desc);
}
// ES5 8.10.4
function FromPropertyDescriptor(desc) {
if(IS_UNDEFINED(desc)) return desc;
var obj = new $Object();
if (IsDataDescriptor(desc)) {
obj.value = desc.getValue();
obj.writable = desc.isWritable();
}
if (IsAccessorDescriptor(desc)) {
obj.get = desc.getGet();
obj.set = desc.getSet();
}
obj.enumerable = desc.isEnumerable();
obj.configurable = desc.isConfigurable();
return obj;
}
// ES5 8.10.5.
function ToPropertyDescriptor(obj) {
......@@ -433,6 +449,33 @@ PropertyDescriptor.prototype.getSet = function() {
}
// ES5 section 8.12.1.
function GetOwnProperty(obj, p) {
var desc = new PropertyDescriptor();
// An array with:
// obj is a data property [false, value, Writeable, Enumerable, Configurable]
// obj is an accessor [true, Get, Set, Enumerable, Configurable]
var props = %GetOwnProperty(ToObject(obj), ToString(p));
if (IS_UNDEFINED(props))
return void 0;
// This is an accessor
if (props[0]) {
desc.setGet(props[1]);
desc.setSet(props[2]);
} else {
desc.setValue(props[1]);
desc.setWritable(props[2]);
}
desc.setEnumerable(props[3]);
desc.setConfigurable(props[4]);
return desc;
}
// ES5 8.12.9. This version cannot cope with the property p already
// being present on obj.
function DefineOwnProperty(obj, p, desc, should_throw) {
......@@ -457,6 +500,16 @@ function ObjectGetPrototypeOf(obj) {
}
// ES5 section 15.2.3.3
function ObjectGetOwnPropertyDescriptor(obj, p) {
if (!IS_OBJECT(obj) && !IS_FUNCTION(obj)) {
throw MakeTypeError("object_get_prototype_non_object", [obj]);
}
var desc = GetOwnProperty(obj, p);
return FromPropertyDescriptor(desc);
}
// ES5 section 15.2.3.5.
function ObjectCreate(proto, properties) {
if (!IS_OBJECT(proto) && !IS_NULL(proto)) {
......@@ -522,7 +575,8 @@ function SetupObject() {
InstallFunctions($Object, DONT_ENUM, $Array(
"keys", ObjectKeys,
"create", ObjectCreate,
"getPrototypeOf", ObjectGetPrototypeOf
"getPrototypeOf", ObjectGetPrototypeOf,
"getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor
));
}
......
......@@ -38,7 +38,6 @@ chapter13: UNIMPLEMENTED
chapter14: UNIMPLEMENTED
chapter15/15.1: UNIMPLEMENTED
chapter15/15.2/15.2.3/15.2.3.1: UNIMPLEMENTED
chapter15/15.2/15.2.3/15.2.3.3: UNIMPLEMENTED
chapter15/15.2/15.2.3/15.2.3.4: UNIMPLEMENTED
chapter15/15.2/15.2.3/15.2.3.5: UNIMPLEMENTED
chapter15/15.2/15.2.3/15.2.3.6: UNIMPLEMENTED
......@@ -53,6 +52,96 @@ chapter15/15.2/15.2.3/15.2.3.13: UNIMPLEMENTED
# Object.getPrototypeOf
chapter15/15.2/15.2.3/15.2.3.2: PASS
# Object.getOwnPropertyDescriptor
chapter15/15.2/15.2.3/15.2.3.3: PASS
# NOT IMPLEMENTED: defineProperty
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-3: FAIL_OK
# NOT IMPLEMENTED: getOwnPropertyNames
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-16: FAIL_OK
# NOT IMPLEMENTED: defineProperty
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-18: FAIL_OK
# NOT IMPLEMENTED: defineProperties
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-19: FAIL_OK
# NOT IMPLEMENTED: seal
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-20: FAIL_OK
# NOT IMPLEMENTED: freeze
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-21: FAIL_OK
# NOT IMPLEMENTED: preventExtensions
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-22: FAIL_OK
# NOT IMPLEMENTED: isSealed
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-23: FAIL_OK
# NOT IMPLEMENTED: isFrozen
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-24: FAIL_OK
# NOT IMPLEMENTED: isExtensible
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-25: FAIL_OK
# NOT IMPLEMENTED: bind
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-38: FAIL_OK
# Built-ins have wrong descriptor (should all be false)
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-178: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-179: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-180: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-182: FAIL_OK
# Our Function object has a "arguments" property which is used as a non
# property in in the test
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-183: FAIL_OK
# Our Function object has a "caller" property which is used as a non
# property in in the test
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-184: FAIL_OK
# Built-ins have wrong descriptor (should all be false)
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-185: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-186: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-187: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-188: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-189: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-190: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-191: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-192: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-193: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-194: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-195: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-201: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-210: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-211: FAIL_OK
# NOT IMPLEMENTED: RegExp.prototype.source
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-212: FAIL_OK
# NOT IMPLEMENTED: RegExp.prototype.global
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-213: FAIL_OK
# NOT IMPLEMENTED: RegExp.prototype.ignoreCase
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-214: FAIL_OK
# NOT IMPLEMENTED: RegExp.prototype.multiline
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-215: FAIL_OK
# Errors have wrong descriptor (should all be false)
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-216: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-217: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-218: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-219: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-220: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-221: FAIL_OK
chapter15/15.2/15.2.3/15.2.3.3/15.2.3.3-4-222: FAIL_OK
# Object.keys
chapter15/15.2/15.2.3/15.2.3.14: PASS
......@@ -61,7 +150,74 @@ chapter15/15.2/15.2.3/15.2.3.14: PASS
chapter15/15.2/15.2.3/15.2.3.14/15.2.3.14-3-3: FAIL_OK
chapter15/15.3: UNIMPLEMENTED
chapter15/15.4: UNIMPLEMENTED
chapter15/15.4/15.4.4/15.4.4.14: UNIMPLEMENTED
chapter15/15.4/15.4.4/15.4.4.15: UNIMPLEMENTED
chapter15/15.4/15.4.4/15.4.4.20: UNIMPLEMENTED
chapter15/15.4/15.4.4/15.4.4.21: UNIMPLEMENTED
chapter15/15.4/15.4.4/15.4.4.22: UNIMPLEMENTED
# Array.prototype.every
chapter15/15.4/15.4.4/15.4.4.16: PASS
# Wrong test - because this is not given as argument to arr.every
# this._15_4_4_16_5_1 evaluates to undefined
chapter15/15.4/15.4.4/15.4.4.16/15.4.4.16-5-1: FAIL_OK
# In test case the element is not appended - it is added in the middle of
# the array
chapter15/15.4/15.4.4/15.4.4.16/15.4.4.16-7-1: FAIL_OK
# We fail because the test assumes that if the reference to array is deleted it
# is not longer traversed
chapter15/15.4/15.4.4/15.4.4.16/15.4.4.16-7-7: FAIL_OK
# if (val>1) in test should be if (val>2)
chapter15/15.4/15.4.4/15.4.4.16/15.4.4.16-8-10: FAIL_OK
# Array.prototype.some
chapter15/15.4/15.4.4/15.4.4.17: PASS
# Wrong assumption - according to spec some returns a Boolean, not a number
chapter15/15.4/15.4.4/15.4.4.17/15.4.4.17-4-9: FAIL_OK
# Same as 15.4.4.16-5-1
chapter15/15.4/15.4.4/15.4.4.17/15.4.4.17-5-1: FAIL_OK
# Same as 15.4.4.16-7-1
chapter15/15.4/15.4.4/15.4.4.17/15.4.4.17-7-1: FAIL_OK
# Same as 15.4.4.16-7-7
chapter15/15.4/15.4.4/15.4.4.17/15.4.4.17-7-7: FAIL_OK
# Same as 15.4.4.16-10-8
chapter15/15.4/15.4.4/15.4.4.17/15.4.4.17-8-10: FAIL_OK
# Array.prototype.forEach
chapter15/15.4/15.4.4/15.4.4.18: PASS
# Same as 15.4.4.16-5-1
chapter15/15.4/15.4.4/15.4.4.18/15.4.4.18-5-1: FAIL_OK
# Same as 15.4.4.16-7-7
chapter15/15.4/15.4.4/15.4.4.18/15.4.4.18-7-6: FAIL_OK
# Array.prototype.map
chapter15/15.4/15.4.4/15.4.4.19: PASS
# Same as 15.4.4.16-5-1
chapter15/15.4/15.4.4/15.4.4.19/15.4.4.19-5-1: FAIL_OK
# Same as 15.4.4.16-7-7
chapter15/15.4/15.4.4/15.4.4.19/15.4.4.19-8-7: FAIL_OK
# Uses a array index number as a property
chapter15/15.4/15.4.4/15.4.4.19/15.4.4.19-8-c-iii-1: FAIL_OK
chapter15/15.5: UNIMPLEMENTED
chapter15/15.6: UNIMPLEMENTED
chapter15/15.7: UNIMPLEMENTED
......
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function get(){return x}
function set(x){this.x=x};
var obj = {x:1};
obj.__defineGetter__("accessor", get);
obj.__defineSetter__("accessor", set);
var descIsData = Object.getOwnPropertyDescriptor(obj,'x');
assertTrue(descIsData.enumerable);
assertTrue(descIsData.writable);
assertTrue(descIsData.configurable);
var descIsAccessor = Object.getOwnPropertyDescriptor(obj, 'accessor');
assertTrue(descIsAccessor.enumerable);
assertTrue(descIsAccessor.configurable);
assertTrue(descIsAccessor.get == get);
assertTrue(descIsAccessor.set == set);
var descIsNotData = Object.getOwnPropertyDescriptor(obj, 'not-x');
assertTrue(descIsNotData == undefined);
var descIsNotAccessor = Object.getOwnPropertyDescriptor(obj, 'not-accessor');
assertTrue(descIsNotAccessor == undefined);
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