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

Side by Side Diff: src/js/v8natives.js

Issue 1412893005: Revert of Use C++ implementation of Object.definePropert{y,ies} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ---------------------------------------------------------------------------- 9 // ----------------------------------------------------------------------------
10 // Imports 10 // Imports
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 } 1025 }
1026 var obj = {}; 1026 var obj = {};
1027 %InternalSetPrototype(obj, proto); 1027 %InternalSetPrototype(obj, proto);
1028 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); 1028 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties);
1029 return obj; 1029 return obj;
1030 } 1030 }
1031 1031
1032 1032
1033 // ES5 section 15.2.3.6. 1033 // ES5 section 15.2.3.6.
1034 function ObjectDefineProperty(obj, p, attributes) { 1034 function ObjectDefineProperty(obj, p, attributes) {
1035 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o. 1035 if (!IS_SPEC_OBJECT(obj)) {
1036 // TODO(jkummerow): Implement missing features and remove fallback path. 1036 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty");
1037 if (%_IsJSProxy(obj) || %IsObserved(obj)) { 1037 }
1038 if (!IS_SPEC_OBJECT(obj)) { 1038 var name = TO_NAME(p);
1039 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty"); 1039 if (%_IsJSProxy(obj)) {
1040 // Clone the attributes object for protection.
1041 // TODO(rossberg): not spec'ed yet, so not sure if this should involve
1042 // non-own properties as it does (or non-enumerable ones, as it doesn't?).
1043 var attributesClone = { __proto__: null };
1044 for (var a in attributes) {
1045 attributesClone[a] = attributes[a];
1040 } 1046 }
1041 var name = TO_NAME(p); 1047 DefineProxyProperty(obj, name, attributesClone, true);
1042 if (%_IsJSProxy(obj)) { 1048 // The following would implement the spec as in the current proposal,
1043 // Clone the attributes object for protection. 1049 // but after recent comments on es-discuss, is most likely obsolete.
1044 // TODO(rossberg): not spec'ed yet, so not sure if this should involve 1050 /*
1045 // non-own properties as it does (or non-enumerable ones, as it doesn't?). 1051 var defineObj = FromGenericPropertyDescriptor(desc);
1046 var attributesClone = { __proto__: null }; 1052 var names = ObjectGetOwnPropertyNames(attributes);
1047 for (var a in attributes) { 1053 var standardNames =
1048 attributesClone[a] = attributes[a]; 1054 {value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0};
1055 for (var i = 0; i < names.length; i++) {
1056 var N = names[i];
1057 if (!(%HasOwnProperty(standardNames, N))) {
1058 var attr = GetOwnPropertyJS(attributes, N);
1059 DefineOwnProperty(descObj, N, attr, true);
1049 } 1060 }
1050 DefineProxyProperty(obj, name, attributesClone, true);
1051 // The following would implement the spec as in the current proposal,
1052 // but after recent comments on es-discuss, is most likely obsolete.
1053 /*
1054 var defineObj = FromGenericPropertyDescriptor(desc);
1055 var names = ObjectGetOwnPropertyNames(attributes);
1056 var standardNames =
1057 {value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0};
1058 for (var i = 0; i < names.length; i++) {
1059 var N = names[i];
1060 if (!(%HasOwnProperty(standardNames, N))) {
1061 var attr = GetOwnPropertyJS(attributes, N);
1062 DefineOwnProperty(descObj, N, attr, true);
1063 }
1064 }
1065 // This is really confusing the types, but it is what the proxies spec
1066 // currently requires:
1067 desc = descObj;
1068 */
1069 } else {
1070 var desc = ToPropertyDescriptor(attributes);
1071 DefineOwnProperty(obj, name, desc, true);
1072 } 1061 }
1073 return obj; 1062 // This is really confusing the types, but it is what the proxies spec
1063 // currently requires:
1064 desc = descObj;
1065 */
1066 } else {
1067 var desc = ToPropertyDescriptor(attributes);
1068 DefineOwnProperty(obj, name, desc, true);
1074 } 1069 }
1075 return %ObjectDefineProperty(obj, p, attributes); 1070 return obj;
1076 } 1071 }
1077 1072
1078 1073
1079 function GetOwnEnumerablePropertyNames(object) { 1074 function GetOwnEnumerablePropertyNames(object) {
1080 var names = new InternalArray(); 1075 var names = new InternalArray();
1081 for (var key in object) { 1076 for (var key in object) {
1082 if (%HasOwnProperty(object, key)) { 1077 if (%HasOwnProperty(object, key)) {
1083 names.push(key); 1078 names.push(key);
1084 } 1079 }
1085 } 1080 }
1086 1081
1087 var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL; 1082 var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
1088 var symbols = %GetOwnPropertyNames(object, filter); 1083 var symbols = %GetOwnPropertyNames(object, filter);
1089 for (var i = 0; i < symbols.length; ++i) { 1084 for (var i = 0; i < symbols.length; ++i) {
1090 var symbol = symbols[i]; 1085 var symbol = symbols[i];
1091 if (IS_SYMBOL(symbol)) { 1086 if (IS_SYMBOL(symbol)) {
1092 var desc = ObjectGetOwnPropertyDescriptor(object, symbol); 1087 var desc = ObjectGetOwnPropertyDescriptor(object, symbol);
1093 if (desc.enumerable) names.push(symbol); 1088 if (desc.enumerable) names.push(symbol);
1094 } 1089 }
1095 } 1090 }
1096 1091
1097 return names; 1092 return names;
1098 } 1093 }
1099 1094
1100 1095
1101 // ES5 section 15.2.3.7. 1096 // ES5 section 15.2.3.7.
1102 function ObjectDefineProperties(obj, properties) { 1097 function ObjectDefineProperties(obj, properties) {
1103 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o. 1098 if (!IS_SPEC_OBJECT(obj)) {
1104 // TODO(jkummerow): Implement missing features and remove fallback path. 1099 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties");
1105 if (%_IsJSProxy(obj) || %_IsJSProxy(properties) || %IsObserved(obj)) {
1106 if (!IS_SPEC_OBJECT(obj)) {
1107 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties");
1108 }
1109 var props = TO_OBJECT(properties);
1110 var names = GetOwnEnumerablePropertyNames(props);
1111 var descriptors = new InternalArray();
1112 for (var i = 0; i < names.length; i++) {
1113 descriptors.push(ToPropertyDescriptor(props[names[i]]));
1114 }
1115 for (var i = 0; i < names.length; i++) {
1116 DefineOwnProperty(obj, names[i], descriptors[i], true);
1117 }
1118 return obj;
1119 } 1100 }
1120 return %ObjectDefineProperties(obj, properties); 1101 var props = TO_OBJECT(properties);
1102 var names = GetOwnEnumerablePropertyNames(props);
1103 var descriptors = new InternalArray();
1104 for (var i = 0; i < names.length; i++) {
1105 descriptors.push(ToPropertyDescriptor(props[names[i]]));
1106 }
1107 for (var i = 0; i < names.length; i++) {
1108 DefineOwnProperty(obj, names[i], descriptors[i], true);
1109 }
1110 return obj;
1121 } 1111 }
1122 1112
1123 1113
1124 // Harmony proxies. 1114 // Harmony proxies.
1125 function ProxyFix(obj) { 1115 function ProxyFix(obj) {
1126 var handler = %GetHandler(obj); 1116 var handler = %GetHandler(obj);
1127 var props = CallTrap0(handler, "fix", UNDEFINED); 1117 var props = CallTrap0(handler, "fix", UNDEFINED);
1128 if (IS_UNDEFINED(props)) { 1118 if (IS_UNDEFINED(props)) {
1129 throw MakeTypeError(kProxyHandlerReturned, handler, "undefined", "fix"); 1119 throw MakeTypeError(kProxyHandlerReturned, handler, "undefined", "fix");
1130 } 1120 }
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 %InstallToContext([ 1843 %InstallToContext([
1854 "global_eval_fun", GlobalEval, 1844 "global_eval_fun", GlobalEval,
1855 "object_value_of", ObjectValueOf, 1845 "object_value_of", ObjectValueOf,
1856 "object_to_string", ObjectToString, 1846 "object_to_string", ObjectToString,
1857 "object_define_own_property", DefineOwnPropertyFromAPI, 1847 "object_define_own_property", DefineOwnPropertyFromAPI,
1858 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, 1848 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor,
1859 "to_complete_property_descriptor", ToCompletePropertyDescriptor, 1849 "to_complete_property_descriptor", ToCompletePropertyDescriptor,
1860 ]); 1850 ]);
1861 1851
1862 }) 1852 })
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698