| Index: src/v8natives.js
|
| diff --git a/src/v8natives.js b/src/v8natives.js
|
| index b715e8923ff26184b43d2f5f432e9e5a3cf778d3..e9d9fccadd1ed6c2c4033b65b998be6500874de9 100644
|
| --- a/src/v8natives.js
|
| +++ b/src/v8natives.js
|
| @@ -1038,46 +1038,38 @@ function ToNameArray(obj, trap, includeSymbols) {
|
| }
|
|
|
|
|
| -// ES5 section 15.2.3.4.
|
| -function ObjectGetOwnPropertyNames(obj) {
|
| - if (!IS_SPEC_OBJECT(obj)) {
|
| - throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
|
| - }
|
| - // Special handling for proxies.
|
| - if (%IsJSProxy(obj)) {
|
| - var handler = %GetHandler(obj);
|
| - var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
|
| - return ToNameArray(names, "getOwnPropertyNames", false);
|
| - }
|
| -
|
| +function ObjectGetOwnPropertyKeys(obj, type) {
|
| var nameArrays = new InternalArray();
|
|
|
| // Find all the indexed properties.
|
|
|
| - // Get the local element names.
|
| - var localElementNames = %GetLocalElementNames(obj);
|
| - for (var i = 0; i < localElementNames.length; ++i) {
|
| - localElementNames[i] = %_NumberToString(localElementNames[i]);
|
| - }
|
| - nameArrays.push(localElementNames);
|
| -
|
| - // Get names for indexed interceptor properties.
|
| - var interceptorInfo = %GetInterceptorInfo(obj);
|
| - if ((interceptorInfo & 1) != 0) {
|
| - var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
|
| - if (!IS_UNDEFINED(indexedInterceptorNames)) {
|
| - nameArrays.push(indexedInterceptorNames);
|
| + // Only get the local element names if we want to include string keys.
|
| + if (type == PROPERTY_KEY_STRING) {
|
| + var localElementNames = %GetLocalElementNames(obj);
|
| + for (var i = 0; i < localElementNames.length; ++i) {
|
| + localElementNames[i] = %_NumberToString(localElementNames[i]);
|
| + }
|
| + nameArrays.push(localElementNames);
|
| +
|
| + // Get names for indexed interceptor properties.
|
| + var interceptorInfo = %GetInterceptorInfo(obj);
|
| + if ((interceptorInfo & 1) != 0) {
|
| + var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
|
| + if (!IS_UNDEFINED(indexedInterceptorNames)) {
|
| + nameArrays.push(indexedInterceptorNames);
|
| + }
|
| }
|
| }
|
|
|
| // Find all the named properties.
|
|
|
| // Get the local property names.
|
| - nameArrays.push(%GetLocalPropertyNames(obj, false));
|
| + nameArrays.push(%GetLocalPropertyNames(obj, type));
|
|
|
| // Get names for named interceptor properties if any.
|
| if ((interceptorInfo & 2) != 0) {
|
| - var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj);
|
| + var namedInterceptorNames =
|
| + %GetNamedInterceptorPropertyNames(obj, type);
|
| if (!IS_UNDEFINED(namedInterceptorNames)) {
|
| nameArrays.push(namedInterceptorNames);
|
| }
|
| @@ -1090,18 +1082,15 @@ function ObjectGetOwnPropertyNames(obj) {
|
| // Property names are expected to be unique strings,
|
| // but interceptors can interfere with that assumption.
|
| if (interceptorInfo != 0) {
|
| - var propertySet = { __proto__: null };
|
| + var seenNames = { __proto__: null };
|
| var j = 0;
|
| for (var i = 0; i < propertyNames.length; ++i) {
|
| - if (IS_SYMBOL(propertyNames[i])) continue;
|
| - var name = ToString(propertyNames[i]);
|
| - // We need to check for the exact property value since for intrinsic
|
| - // properties like toString if(propertySet["toString"]) will always
|
| - // succeed.
|
| - if (propertySet[name] === true) {
|
| - continue;
|
| + var name = propertyNames[i];
|
| + if (type == PROPERTY_KEY_STRING) {
|
| + name = ToString(name);
|
| }
|
| - propertySet[name] = true;
|
| + if (seenNames[name]) continue;
|
| + seenNames[name] = true;
|
| propertyNames[j++] = name;
|
| }
|
| propertyNames.length = j;
|
| @@ -1111,6 +1100,34 @@ function ObjectGetOwnPropertyNames(obj) {
|
| }
|
|
|
|
|
| +// ES6 19.1.2.8
|
| +function ObjectGetOwnPropertySymbols(obj) {
|
| + if (!IS_SPEC_OBJECT(obj)) {
|
| + throw MakeTypeError("called_on_non_object",
|
| + ["Object.getOwnPropertySymbols"]);
|
| + }
|
| +
|
| + // TODO(arv): Proxies use a shared trap for String and Symbol keys.
|
| +
|
| + return ObjectGetOwnPropertyKeys(obj, PROPERTY_KEY_SYMBOL);
|
| +}
|
| +
|
| +// ES5 section 15.2.3.4.
|
| +function ObjectGetOwnPropertyNames(obj) {
|
| + if (!IS_SPEC_OBJECT(obj)) {
|
| + throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
|
| + }
|
| + // Special handling for proxies.
|
| + if (%IsJSProxy(obj)) {
|
| + var handler = %GetHandler(obj);
|
| + var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
|
| + return ToNameArray(names, "getOwnPropertyNames", false);
|
| + }
|
| +
|
| + return ObjectGetOwnPropertyKeys(obj, PROPERTY_KEY_STRING);
|
| +}
|
| +
|
| +
|
| // ES5 section 15.2.3.5.
|
| function ObjectCreate(proto, properties) {
|
| if (!IS_SPEC_OBJECT(proto) && proto !== null) {
|
| @@ -1420,12 +1437,14 @@ function SetUpObject() {
|
| "getPrototypeOf", ObjectGetPrototypeOf,
|
| "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
|
| "getOwnPropertyNames", ObjectGetOwnPropertyNames,
|
| + // getOwnPropertySymbols is added in symbol.js.
|
| "is", ObjectIs,
|
| "isExtensible", ObjectIsExtensible,
|
| "isFrozen", ObjectIsFrozen,
|
| "isSealed", ObjectIsSealed,
|
| "preventExtensions", ObjectPreventExtension,
|
| "seal", ObjectSeal
|
| + // observe is added in object-observe.js.
|
| ));
|
| }
|
|
|
|
|