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

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

Issue 1413123004: Reland "Use C++ implementation of Object.definePropert{y,ies}" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixes for access checks and interceptors 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 if (!IS_SPEC_OBJECT(obj)) { 1035 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o.
1036 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty"); 1036 // TODO(jkummerow): Implement missing features and remove fallback path.
1037 if (%_IsJSProxy(obj) || %IsObserved(obj)) {
1038 if (!IS_SPEC_OBJECT(obj)) {
1039 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty");
1040 }
1041 var name = TO_NAME(p);
1042 if (%_IsJSProxy(obj)) {
1043 // Clone the attributes object for protection.
1044 // TODO(rossberg): not spec'ed yet, so not sure if this should involve
1045 // non-own properties as it does (or non-enumerable ones, as it doesn't?).
1046 var attributesClone = { __proto__: null };
1047 for (var a in attributes) {
1048 attributesClone[a] = attributes[a];
1049 }
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 }
1073 return obj;
1037 } 1074 }
1038 var name = TO_NAME(p); 1075 return %ObjectDefineProperty(obj, p, attributes);
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];
1046 }
1047 DefineProxyProperty(obj, name, attributesClone, true);
1048 // The following would implement the spec as in the current proposal,
1049 // but after recent comments on es-discuss, is most likely obsolete.
1050 /*
1051 var defineObj = FromGenericPropertyDescriptor(desc);
1052 var names = ObjectGetOwnPropertyNames(attributes);
1053 var standardNames =
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);
1060 }
1061 }
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);
1069 }
1070 return obj;
1071 } 1076 }
1072 1077
1073 1078
1074 function GetOwnEnumerablePropertyNames(object) { 1079 function GetOwnEnumerablePropertyNames(object) {
1075 var names = new InternalArray(); 1080 var names = new InternalArray();
1076 for (var key in object) { 1081 for (var key in object) {
1077 if (%HasOwnProperty(object, key)) { 1082 if (%HasOwnProperty(object, key)) {
1078 names.push(key); 1083 names.push(key);
1079 } 1084 }
1080 } 1085 }
1081 1086
1082 var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL; 1087 var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
1083 var symbols = %GetOwnPropertyNames(object, filter); 1088 var symbols = %GetOwnPropertyNames(object, filter);
1084 for (var i = 0; i < symbols.length; ++i) { 1089 for (var i = 0; i < symbols.length; ++i) {
1085 var symbol = symbols[i]; 1090 var symbol = symbols[i];
1086 if (IS_SYMBOL(symbol)) { 1091 if (IS_SYMBOL(symbol)) {
1087 var desc = ObjectGetOwnPropertyDescriptor(object, symbol); 1092 var desc = ObjectGetOwnPropertyDescriptor(object, symbol);
1088 if (desc.enumerable) names.push(symbol); 1093 if (desc.enumerable) names.push(symbol);
1089 } 1094 }
1090 } 1095 }
1091 1096
1092 return names; 1097 return names;
1093 } 1098 }
1094 1099
1095 1100
1096 // ES5 section 15.2.3.7. 1101 // ES5 section 15.2.3.7.
1097 function ObjectDefineProperties(obj, properties) { 1102 function ObjectDefineProperties(obj, properties) {
1098 if (!IS_SPEC_OBJECT(obj)) { 1103 // The new pure-C++ implementation doesn't support Proxies yet, nor O.o.
1099 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); 1104 // TODO(jkummerow): Implement missing features and remove fallback path.
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;
1100 } 1119 }
1101 var props = TO_OBJECT(properties); 1120 return %ObjectDefineProperties(obj, 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;
1111 } 1121 }
1112 1122
1113 1123
1114 // Harmony proxies. 1124 // Harmony proxies.
1115 function ProxyFix(obj) { 1125 function ProxyFix(obj) {
1116 var handler = %GetHandler(obj); 1126 var handler = %GetHandler(obj);
1117 var props = CallTrap0(handler, "fix", UNDEFINED); 1127 var props = CallTrap0(handler, "fix", UNDEFINED);
1118 if (IS_UNDEFINED(props)) { 1128 if (IS_UNDEFINED(props)) {
1119 throw MakeTypeError(kProxyHandlerReturned, handler, "undefined", "fix"); 1129 throw MakeTypeError(kProxyHandlerReturned, handler, "undefined", "fix");
1120 } 1130 }
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 %InstallToContext([ 1853 %InstallToContext([
1844 "global_eval_fun", GlobalEval, 1854 "global_eval_fun", GlobalEval,
1845 "object_value_of", ObjectValueOf, 1855 "object_value_of", ObjectValueOf,
1846 "object_to_string", ObjectToString, 1856 "object_to_string", ObjectToString,
1847 "object_define_own_property", DefineOwnPropertyFromAPI, 1857 "object_define_own_property", DefineOwnPropertyFromAPI,
1848 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, 1858 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor,
1849 "to_complete_property_descriptor", ToCompletePropertyDescriptor, 1859 "to_complete_property_descriptor", ToCompletePropertyDescriptor,
1850 ]); 1860 ]);
1851 1861
1852 }) 1862 })
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