OLD | NEW |
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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 339 } |
340 | 340 |
341 | 341 |
342 function ObjectKeys(obj) { | 342 function ObjectKeys(obj) { |
343 if (!IS_SPEC_OBJECT(obj)) { | 343 if (!IS_SPEC_OBJECT(obj)) { |
344 throw MakeTypeError("called_on_non_object", ["Object.keys"]); | 344 throw MakeTypeError("called_on_non_object", ["Object.keys"]); |
345 } | 345 } |
346 if (%IsJSProxy(obj)) { | 346 if (%IsJSProxy(obj)) { |
347 var handler = %GetHandler(obj); | 347 var handler = %GetHandler(obj); |
348 var names = CallTrap0(handler, "keys", DerivedKeysTrap); | 348 var names = CallTrap0(handler, "keys", DerivedKeysTrap); |
349 // TODO(rossberg): filter non-string keys. | 349 return ToNameArray(names, "keys", false); |
350 return ToNameArray(names, "keys"); | |
351 } | 350 } |
352 return %LocalKeys(obj); | 351 return %LocalKeys(obj); |
353 } | 352 } |
354 | 353 |
355 | 354 |
356 // ES5 8.10.1. | 355 // ES5 8.10.1. |
357 function IsAccessorDescriptor(desc) { | 356 function IsAccessorDescriptor(desc) { |
358 if (IS_UNDEFINED(desc)) return false; | 357 if (IS_UNDEFINED(desc)) return false; |
359 return desc.hasGetter() || desc.hasSetter(); | 358 return desc.hasGetter() || desc.hasSetter(); |
360 } | 359 } |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 if (!IS_SPEC_OBJECT(obj)) { | 975 if (!IS_SPEC_OBJECT(obj)) { |
977 throw MakeTypeError("called_on_non_object", | 976 throw MakeTypeError("called_on_non_object", |
978 ["Object.getOwnPropertyDescriptor"]); | 977 ["Object.getOwnPropertyDescriptor"]); |
979 } | 978 } |
980 var desc = GetOwnProperty(obj, p); | 979 var desc = GetOwnProperty(obj, p); |
981 return FromPropertyDescriptor(desc); | 980 return FromPropertyDescriptor(desc); |
982 } | 981 } |
983 | 982 |
984 | 983 |
985 // For Harmony proxies | 984 // For Harmony proxies |
986 function ToNameArray(obj, trap) { | 985 function ToNameArray(obj, trap, includeSymbols) { |
987 if (!IS_SPEC_OBJECT(obj)) { | 986 if (!IS_SPEC_OBJECT(obj)) { |
988 throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]); | 987 throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]); |
989 } | 988 } |
990 var n = ToUint32(obj.length); | 989 var n = ToUint32(obj.length); |
991 var array = new $Array(n); | 990 var array = new $Array(n); |
992 var names = { __proto__: null }; // TODO(rossberg): use sets once ready. | 991 var names = { __proto__: null }; // TODO(rossberg): use sets once ready. |
993 for (var index = 0; index < n; index++) { | 992 for (var index = 0; index < n; index++) { |
994 var s = ToName(obj[index]); | 993 var s = ToName(obj[index]); |
| 994 if (IS_SYMBOL(s) && !includeSymbols) continue; |
995 if (%HasLocalProperty(names, s)) { | 995 if (%HasLocalProperty(names, s)) { |
996 throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]); | 996 throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]); |
997 } | 997 } |
998 array[index] = s; | 998 array[index] = s; |
999 names[s] = 0; | 999 names[s] = 0; |
1000 } | 1000 } |
1001 return array; | 1001 return array; |
1002 } | 1002 } |
1003 | 1003 |
1004 | 1004 |
1005 // ES5 section 15.2.3.4. | 1005 // ES5 section 15.2.3.4. |
1006 function ObjectGetOwnPropertyNames(obj) { | 1006 function ObjectGetOwnPropertyNames(obj) { |
1007 if (!IS_SPEC_OBJECT(obj)) { | 1007 if (!IS_SPEC_OBJECT(obj)) { |
1008 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); | 1008 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); |
1009 } | 1009 } |
1010 // Special handling for proxies. | 1010 // Special handling for proxies. |
1011 if (%IsJSProxy(obj)) { | 1011 if (%IsJSProxy(obj)) { |
1012 var handler = %GetHandler(obj); | 1012 var handler = %GetHandler(obj); |
1013 var names = CallTrap0(handler, "getOwnPropertyNames", void 0); | 1013 var names = CallTrap0(handler, "getOwnPropertyNames", void 0); |
1014 return ToNameArray(names, "getOwnPropertyNames"); | 1014 return ToNameArray(names, "getOwnPropertyNames", true); |
1015 } | 1015 } |
1016 | 1016 |
1017 // Find all the indexed properties. | 1017 // Find all the indexed properties. |
1018 | 1018 |
1019 // Get the local element names. | 1019 // Get the local element names. |
1020 var propertyNames = %GetLocalElementNames(obj); | 1020 var propertyNames = %GetLocalElementNames(obj); |
1021 for (var i = 0; i < propertyNames.length; ++i) { | 1021 for (var i = 0; i < propertyNames.length; ++i) { |
1022 propertyNames[i] = %_NumberToString(propertyNames[i]); | 1022 propertyNames[i] = %_NumberToString(propertyNames[i]); |
1023 } | 1023 } |
1024 | 1024 |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 | 1724 |
1725 function SetUpFunction() { | 1725 function SetUpFunction() { |
1726 %CheckIsBootstrapping(); | 1726 %CheckIsBootstrapping(); |
1727 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1727 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1728 "bind", FunctionBind, | 1728 "bind", FunctionBind, |
1729 "toString", FunctionToString | 1729 "toString", FunctionToString |
1730 )); | 1730 )); |
1731 } | 1731 } |
1732 | 1732 |
1733 SetUpFunction(); | 1733 SetUpFunction(); |
OLD | NEW |