Commit 004452bf authored by adamk@chromium.org's avatar adamk@chromium.org

Use InternalArray in Object.getOwnPropertyNames() implementation

Review URL: https://codereview.chromium.org/12342003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13918 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 479e39a0
...@@ -1553,6 +1553,7 @@ function SetUpArray() { ...@@ -1553,6 +1553,7 @@ function SetUpArray() {
// exposed to user code. // exposed to user code.
// Adding only the functions that are actually used. // Adding only the functions that are actually used.
SetUpLockedPrototype(InternalArray, $Array(), $Array( SetUpLockedPrototype(InternalArray, $Array(), $Array(
"concat", getFunction("concat", ArrayConcat),
"indexOf", getFunction("indexOf", ArrayIndexOf), "indexOf", getFunction("indexOf", ArrayIndexOf),
"join", getFunction("join", ArrayJoin), "join", getFunction("join", ArrayJoin),
"pop", getFunction("pop", ArrayPop), "pop", getFunction("pop", ArrayPop),
......
...@@ -1014,39 +1014,44 @@ function ObjectGetOwnPropertyNames(obj) { ...@@ -1014,39 +1014,44 @@ function ObjectGetOwnPropertyNames(obj) {
return ToNameArray(names, "getOwnPropertyNames", true); return ToNameArray(names, "getOwnPropertyNames", true);
} }
var nameArrays = new InternalArray();
// Find all the indexed properties. // Find all the indexed properties.
// Get the local element names. // Get the local element names.
var propertyNames = %GetLocalElementNames(obj); var localElementNames = %GetLocalElementNames(obj);
for (var i = 0; i < propertyNames.length; ++i) { for (var i = 0; i < localElementNames.length; ++i) {
propertyNames[i] = %_NumberToString(propertyNames[i]); localElementNames[i] = %_NumberToString(localElementNames[i]);
} }
nameArrays.push(localElementNames);
// Get names for indexed interceptor properties. // Get names for indexed interceptor properties.
var interceptorInfo = %GetInterceptorInfo(obj); var interceptorInfo = %GetInterceptorInfo(obj);
if ((interceptorInfo & 1) != 0) { if ((interceptorInfo & 1) != 0) {
var indexedInterceptorNames = var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
%GetIndexedInterceptorElementNames(obj); if (!IS_UNDEFINED(indexedInterceptorNames)) {
if (indexedInterceptorNames) { nameArrays.push(indexedInterceptorNames);
propertyNames = propertyNames.concat(indexedInterceptorNames);
} }
} }
// Find all the named properties. // Find all the named properties.
// Get the local property names. // Get the local property names.
propertyNames = propertyNames.concat(%GetLocalPropertyNames(obj)); nameArrays.push(%GetLocalPropertyNames(obj));
// Get names for named interceptor properties if any. // Get names for named interceptor properties if any.
if ((interceptorInfo & 2) != 0) { if ((interceptorInfo & 2) != 0) {
var namedInterceptorNames = var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj);
%GetNamedInterceptorPropertyNames(obj); if (!IS_UNDEFINED(namedInterceptorNames)) {
if (namedInterceptorNames) { nameArrays.push(namedInterceptorNames);
propertyNames = propertyNames.concat(namedInterceptorNames);
} }
} }
// Property names are expected to be unique names, var propertyNames =
%Apply(InternalArray.prototype.concat,
nameArrays[0], nameArrays, 1, nameArrays.length - 1);
// Property names are expected to be unique strings,
// but interceptors can interfere with that assumption. // but interceptors can interfere with that assumption.
if (interceptorInfo != 0) { if (interceptorInfo != 0) {
var propertySet = { __proto__: null }; var propertySet = { __proto__: null };
......
...@@ -77,6 +77,16 @@ propertyNames.sort(); ...@@ -77,6 +77,16 @@ propertyNames.sort();
assertEquals(1, propertyNames.length); assertEquals(1, propertyNames.length);
assertEquals("getter", propertyNames[0]); assertEquals("getter", propertyNames[0]);
// Check that implementation does not access Array.prototype.
var savedConcat = Array.prototype.concat;
Array.prototype.concat = function() { return []; }
propertyNames = Object.getOwnPropertyNames({0: 'foo', bar: 'baz'});
assertEquals(2, propertyNames.length);
assertEquals('0', propertyNames[0]);
assertEquals('bar', propertyNames[1]);
assertSame(Array.prototype, propertyNames.__proto__);
Array.prototype.concat = savedConcat;
try { try {
Object.getOwnPropertyNames(4); Object.getOwnPropertyNames(4);
assertTrue(false); assertTrue(false);
......
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