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

Side by Side Diff: src/v8natives.js

Issue 108083005: ES6: Add Object.getOwnPropertySymbols (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: reitveld error Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 } 1031 }
1032 array[index] = s; 1032 array[index] = s;
1033 ++realLength; 1033 ++realLength;
1034 names[s] = 0; 1034 names[s] = 0;
1035 } 1035 }
1036 array.length = realLength; 1036 array.length = realLength;
1037 return array; 1037 return array;
1038 } 1038 }
1039 1039
1040 1040
1041 function GetSymbolsInArray(propertyKeys) {
rossberg 2013/12/10 10:39:53 Nit: perhaps call this FilterPublicSymbols?
arv (Not doing code reviews) 2013/12/11 00:16:26 Done.
1042 var symbols = new InternalArray();
1043 var j = 0;
1044 for (var i = 0; i < propertyKeys.length; i++) {
1045 if (IS_SYMBOL(propertyKeys[i]) && !%SymbolIsPrivate(propertyKeys[i])) {
rossberg 2013/12/10 10:39:53 It might make sense to introduce an IS_PRIVATE mac
arv (Not doing code reviews) 2013/12/11 00:16:26 Done.
1046 symbols[j++] = propertyKeys[i];
1047 }
1048 }
1049 return symbols;
1050 }
1051
1052
1053 // ES6 19.1.2.8
1054 function ObjectGetOwnPropertySymbols(obj) {
1055 if (!IS_SPEC_OBJECT(obj)) {
1056 throw MakeTypeError("called_on_non_object",
1057 ["Object.getOwnPropertySymbols"]);
1058 }
1059
1060 // FIXME: Proxies use a shared trap for String and Symbol keys.
rossberg 2013/12/10 10:39:53 Please use TODO(arv); same below
arv (Not doing code reviews) 2013/12/11 00:16:26 Done.
1061
1062 var nameArrays = new InternalArray();
1063
1064 // Find all the indexed properties.
1065
1066 // Get names for indexed interceptor properties.
1067 var interceptorInfo = %GetInterceptorInfo(obj);
1068
1069 // Find all the named properties.
1070
1071 // Get the local property symbols.
1072 // FIXME: Have the runtime do the filtering.
rossberg 2013/12/10 10:39:53 Yeah, I would very much prefer to have this implem
1073 nameArrays.push(GetSymbolsInArray(%GetLocalPropertyNames(obj, true)));
1074
1075 // Get names for named interceptor properties if any.
1076 if ((interceptorInfo & 2) != 0) {
1077 // FIXME: Have the runtime do the filtering.
1078 var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj);
1079 if (!IS_UNDEFINED(namedInterceptorNames)) {
1080 nameArrays.push(GetSymbolsInArray(namedInterceptorSymbols));
1081 }
1082 }
1083
1084 var propertySymbols =
1085 %Apply(InternalArray.prototype.concat,
1086 nameArrays[0], nameArrays, 1, nameArrays.length - 1);
1087
1088 // Property names are expected to be unique,
1089 // but interceptors can interfere with that assumption.
1090 if (interceptorInfo != 0) {
1091 var propertySet = { __proto__: null };
1092 var j = 0;
1093 for (var i = 0; i < propertySymbols.length; ++i) {
1094 var symbol = propertySymbols[i];
1095 if (!IS_SYMBOL(symbol) || %SymbolIsPrivate(symbol)) continue;
1096
1097 // We need to check for the exact property value since for intrinsic
1098 // properties like toString if(propertySet["toString"]) will always
1099 // succeed.
1100 if (propertySet[symbol] === true) {
rossberg 2013/12/10 10:39:53 Could combine this with the previous if.
arv (Not doing code reviews) 2013/12/11 00:16:26 I also don't think this comment is correct. proper
1101 continue;
1102 }
1103 propertySet[symbol] = true;
1104 propertySymbols[j++] = symbol;
1105 }
1106 propertySymbols.length = j;
1107 }
1108
1109 return propertySymbols;
1110 }
1111
1041 // ES5 section 15.2.3.4. 1112 // ES5 section 15.2.3.4.
1042 function ObjectGetOwnPropertyNames(obj) { 1113 function ObjectGetOwnPropertyNames(obj) {
1043 if (!IS_SPEC_OBJECT(obj)) { 1114 if (!IS_SPEC_OBJECT(obj)) {
1044 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); 1115 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1045 } 1116 }
1046 // Special handling for proxies. 1117 // Special handling for proxies.
1047 if (%IsJSProxy(obj)) { 1118 if (%IsJSProxy(obj)) {
1048 var handler = %GetHandler(obj); 1119 var handler = %GetHandler(obj);
1049 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); 1120 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1050 return ToNameArray(names, "getOwnPropertyNames", false); 1121 return ToNameArray(names, "getOwnPropertyNames", false);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 // Set up non-enumerable functions in the Object object. 1484 // Set up non-enumerable functions in the Object object.
1414 InstallFunctions($Object, DONT_ENUM, $Array( 1485 InstallFunctions($Object, DONT_ENUM, $Array(
1415 "keys", ObjectKeys, 1486 "keys", ObjectKeys,
1416 "create", ObjectCreate, 1487 "create", ObjectCreate,
1417 "defineProperty", ObjectDefineProperty, 1488 "defineProperty", ObjectDefineProperty,
1418 "defineProperties", ObjectDefineProperties, 1489 "defineProperties", ObjectDefineProperties,
1419 "freeze", ObjectFreeze, 1490 "freeze", ObjectFreeze,
1420 "getPrototypeOf", ObjectGetPrototypeOf, 1491 "getPrototypeOf", ObjectGetPrototypeOf,
1421 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 1492 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
1422 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 1493 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
1494 // getOwnPropertySymbols is added in symbol.js
rossberg 2013/12/10 10:39:53 Good to have that comment here. While you're at it
arv (Not doing code reviews) 2013/12/11 00:16:26 Done.
1423 "is", ObjectIs, 1495 "is", ObjectIs,
1424 "isExtensible", ObjectIsExtensible, 1496 "isExtensible", ObjectIsExtensible,
1425 "isFrozen", ObjectIsFrozen, 1497 "isFrozen", ObjectIsFrozen,
1426 "isSealed", ObjectIsSealed, 1498 "isSealed", ObjectIsSealed,
1427 "preventExtensions", ObjectPreventExtension, 1499 "preventExtensions", ObjectPreventExtension,
1428 "seal", ObjectSeal 1500 "seal", ObjectSeal
1429 )); 1501 ));
1430 } 1502 }
1431 1503
1432 SetUpObject(); 1504 SetUpObject();
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 // Eventually, we should move to a real event queue that allows to maintain 1917 // Eventually, we should move to a real event queue that allows to maintain
1846 // relative ordering of different kinds of tasks. 1918 // relative ordering of different kinds of tasks.
1847 1919
1848 RunMicrotasks.runners = new InternalArray; 1920 RunMicrotasks.runners = new InternalArray;
1849 1921
1850 function RunMicrotasks() { 1922 function RunMicrotasks() {
1851 while (%SetMicrotaskPending(false)) { 1923 while (%SetMicrotaskPending(false)) {
1852 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); 1924 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i]();
1853 } 1925 }
1854 } 1926 }
OLDNEW
« no previous file with comments | « src/symbol.js ('k') | test/mjsunit/harmony/symbols.js » ('j') | test/mjsunit/harmony/symbols.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698