Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(787)

Unified Diff: src/v8natives.js

Issue 108083005: ES6: Add Object.getOwnPropertySymbols (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment and formatting based on code review Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/symbol.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 96b88c5285c9962d479fa75d0e71031cd0c35b6c..773e371f17d497828213ab07d848d3d2ff5e4ed2 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1037,42 +1037,36 @@ 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, symbolsOnly) {
var nameArrays = new InternalArray();
+ var filter = symbolsOnly ?
+ PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL :
+ PROPERTY_ATTRIBUTES_SYMBOLIC;
// 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 (!symbolsOnly) {
+ 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, filter));
// Get names for named interceptor properties if any.
if ((interceptorInfo & 2) != 0) {
@@ -1089,18 +1083,18 @@ 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 seenKeys = { __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 (symbolsOnly) {
+ if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue;
+ } else {
+ if (IS_SYMBOL(name)) continue;
+ name = ToString(name);
}
- propertySet[name] = true;
+ if (seenKeys[name]) continue;
+ seenKeys[name] = true;
propertyNames[j++] = name;
}
propertyNames.length = j;
@@ -1110,6 +1104,22 @@ function ObjectGetOwnPropertyNames(obj) {
}
+// 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, false);
+}
+
+
// ES5 section 15.2.3.5.
function ObjectCreate(proto, properties) {
if (!IS_SPEC_OBJECT(proto) && proto !== null) {
@@ -1419,12 +1429,15 @@ 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
+ // deliverChangeRecords, getNotifier, observe and unobserve are added
+ // in object-observe.js.
));
}
« no previous file with comments | « src/symbol.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698