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 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 ToStringArray(names, "getOwnPropertyNames"); | 1014 return ToStringArray(names, "getOwnPropertyNames"); |
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 = new InternalArray; |
1021 %MoveArrayContents(%GetLocalElementNames(obj), propertyNames); | |
1021 for (var i = 0; i < propertyNames.length; ++i) { | 1022 for (var i = 0; i < propertyNames.length; ++i) { |
1022 propertyNames[i] = %_NumberToString(propertyNames[i]); | 1023 propertyNames[i] = %_NumberToString(propertyNames[i]); |
1023 } | 1024 } |
1024 | 1025 |
1025 // Get names for indexed interceptor properties. | 1026 // Get names for indexed interceptor properties. |
1026 var interceptorInfo = %GetInterceptorInfo(obj); | 1027 var interceptorInfo = %GetInterceptorInfo(obj); |
1027 if ((interceptorInfo & 1) != 0) { | 1028 if ((interceptorInfo & 1) != 0) { |
1028 var indexedInterceptorNames = | 1029 var indexedInterceptorNames = |
1029 %GetIndexedInterceptorElementNames(obj); | 1030 %GetIndexedInterceptorElementNames(obj); |
1030 if (indexedInterceptorNames) { | 1031 if (indexedInterceptorNames) { |
1031 propertyNames = propertyNames.concat(indexedInterceptorNames); | 1032 propertyNames = propertyNames.concat(indexedInterceptorNames); |
Vyacheslav Egorov (Google)
2013/02/26 01:21:33
I guess here you should %MoveArrayContents instead
| |
1032 } | 1033 } |
1033 } | 1034 } |
1034 | 1035 |
1035 // Find all the named properties. | 1036 // Find all the named properties. |
1036 | 1037 |
1037 // Get the local property names. | 1038 // Get the local property names. |
1038 propertyNames = propertyNames.concat(%GetLocalPropertyNames(obj)); | 1039 propertyNames = propertyNames.concat(%GetLocalPropertyNames(obj)); |
Vyacheslav Egorov (Google)
2013/02/26 01:21:33
ditto
| |
1039 | 1040 |
1040 // Get names for named interceptor properties if any. | 1041 // Get names for named interceptor properties if any. |
1041 if ((interceptorInfo & 2) != 0) { | 1042 if ((interceptorInfo & 2) != 0) { |
1042 var namedInterceptorNames = | 1043 var namedInterceptorNames = |
1043 %GetNamedInterceptorPropertyNames(obj); | 1044 %GetNamedInterceptorPropertyNames(obj); |
1044 if (namedInterceptorNames) { | 1045 if (namedInterceptorNames) { |
1045 propertyNames = propertyNames.concat(namedInterceptorNames); | 1046 propertyNames = propertyNames.concat(namedInterceptorNames); |
Vyacheslav Egorov (Google)
2013/02/26 01:21:33
here I guess you can leave assignment. though for
| |
1046 } | 1047 } |
1047 } | 1048 } |
1048 | 1049 |
1049 // Property names are expected to be unique strings, | 1050 // Property names are expected to be unique strings, |
1050 // but interceptors can interfere with that assumption. | 1051 // but interceptors can interfere with that assumption. |
1051 if (interceptorInfo != 0) { | 1052 if (interceptorInfo != 0) { |
1052 var propertySet = { __proto__: null }; | 1053 var propertySet = { __proto__: null }; |
1053 var j = 0; | 1054 var j = 0; |
1054 for (var i = 0; i < propertyNames.length; ++i) { | 1055 for (var i = 0; i < propertyNames.length; ++i) { |
1055 var name = ToString(propertyNames[i]); | 1056 var name = ToString(propertyNames[i]); |
1056 // We need to check for the exact property value since for intrinsic | 1057 // We need to check for the exact property value since for intrinsic |
Vyacheslav Egorov (Google)
2013/02/26 01:21:33
I think this comment is out of date
adamk
2013/02/26 02:28:12
Happy to remove if mstarzinger agrees.
| |
1057 // properties like toString if(propertySet["toString"]) will always | 1058 // properties like toString if(propertySet["toString"]) will always |
1058 // succeed. | 1059 // succeed. |
1059 if (propertySet[name] === true) { | 1060 if (propertySet[name] === true) { |
1060 continue; | 1061 continue; |
1061 } | 1062 } |
1062 propertySet[name] = true; | 1063 propertySet[name] = true; |
1063 propertyNames[j++] = name; | 1064 propertyNames[j++] = name; |
1064 } | 1065 } |
1065 propertyNames.length = j; | 1066 propertyNames.length = j; |
1066 } | 1067 } |
1067 | 1068 |
1068 return propertyNames; | 1069 var result = []; |
Vyacheslav Egorov (Google)
2013/02/26 01:21:33
I wonder if it should be new $Array() for consiste
adamk
2013/02/26 02:28:12
Changed to $Array.
| |
1070 %MoveArrayContents(propertyNames, result); | |
1071 return result; | |
1069 } | 1072 } |
1070 | 1073 |
1071 | 1074 |
1072 // ES5 section 15.2.3.5. | 1075 // ES5 section 15.2.3.5. |
1073 function ObjectCreate(proto, properties) { | 1076 function ObjectCreate(proto, properties) { |
1074 if (!IS_SPEC_OBJECT(proto) && proto !== null) { | 1077 if (!IS_SPEC_OBJECT(proto) && proto !== null) { |
1075 throw MakeTypeError("proto_object_or_null", [proto]); | 1078 throw MakeTypeError("proto_object_or_null", [proto]); |
1076 } | 1079 } |
1077 var obj = new $Object(); | 1080 var obj = new $Object(); |
1078 obj.__proto__ = proto; | 1081 obj.__proto__ = proto; |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1724 | 1727 |
1725 function SetUpFunction() { | 1728 function SetUpFunction() { |
1726 %CheckIsBootstrapping(); | 1729 %CheckIsBootstrapping(); |
1727 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1730 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1728 "bind", FunctionBind, | 1731 "bind", FunctionBind, |
1729 "toString", FunctionToString | 1732 "toString", FunctionToString |
1730 )); | 1733 )); |
1731 } | 1734 } |
1732 | 1735 |
1733 SetUpFunction(); | 1736 SetUpFunction(); |
OLD | NEW |