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

Side by Side Diff: src/v8natives.js

Issue 1319133002: [es6] Implement spec compliant ToName (actually ToPropertyKey). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@ToPrimitive
Patch Set: Created 5 years, 3 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 | « src/runtime/runtime-object.cc ('k') | test/mjsunit/harmony/to-name.js » ('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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 170
171 // ECMA-262 - 15.2.4.4 171 // ECMA-262 - 15.2.4.4
172 function ObjectValueOf() { 172 function ObjectValueOf() {
173 return TO_OBJECT(this); 173 return TO_OBJECT(this);
174 } 174 }
175 175
176 176
177 // ECMA-262 - 15.2.4.5 177 // ECMA-262 - 15.2.4.5
178 function ObjectHasOwnProperty(value) { 178 function ObjectHasOwnProperty(value) {
179 var name = $toName(value); 179 var name = TO_NAME(value);
180 var object = TO_OBJECT(this); 180 var object = TO_OBJECT(this);
181 181
182 if (%_IsJSProxy(object)) { 182 if (%_IsJSProxy(object)) {
183 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 183 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
184 if (IS_SYMBOL(value)) return false; 184 if (IS_SYMBOL(value)) return false;
185 185
186 var handler = %GetHandler(object); 186 var handler = %GetHandler(object);
187 return CallTrap1(handler, "hasOwn", ProxyDerivedHasOwnTrap, name); 187 return CallTrap1(handler, "hasOwn", ProxyDerivedHasOwnTrap, name);
188 } 188 }
189 return %HasOwnProperty(object, name); 189 return %HasOwnProperty(object, name);
190 } 190 }
191 191
192 192
193 // ECMA-262 - 15.2.4.6 193 // ECMA-262 - 15.2.4.6
194 function ObjectIsPrototypeOf(V) { 194 function ObjectIsPrototypeOf(V) {
195 if (!IS_SPEC_OBJECT(V)) return false; 195 if (!IS_SPEC_OBJECT(V)) return false;
196 var O = TO_OBJECT(this); 196 var O = TO_OBJECT(this);
197 return %_HasInPrototypeChain(V, O); 197 return %_HasInPrototypeChain(V, O);
198 } 198 }
199 199
200 200
201 // ECMA-262 - 15.2.4.6 201 // ECMA-262 - 15.2.4.6
202 function ObjectPropertyIsEnumerable(V) { 202 function ObjectPropertyIsEnumerable(V) {
203 var P = $toName(V); 203 var P = TO_NAME(V);
204 if (%_IsJSProxy(this)) { 204 if (%_IsJSProxy(this)) {
205 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 205 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
206 if (IS_SYMBOL(V)) return false; 206 if (IS_SYMBOL(V)) return false;
207 207
208 var desc = GetOwnPropertyJS(this, P); 208 var desc = GetOwnPropertyJS(this, P);
209 return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); 209 return IS_UNDEFINED(desc) ? false : desc.isEnumerable();
210 } 210 }
211 return %IsPropertyEnumerable(TO_OBJECT(this), P); 211 return %IsPropertyEnumerable(TO_OBJECT(this), P);
212 } 212 }
213 213
214 214
215 // Extensions for providing property getters and setters. 215 // Extensions for providing property getters and setters.
216 function ObjectDefineGetter(name, fun) { 216 function ObjectDefineGetter(name, fun) {
217 var receiver = this; 217 var receiver = this;
218 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { 218 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) {
219 receiver = %GlobalProxy(ObjectDefineGetter); 219 receiver = %GlobalProxy(ObjectDefineGetter);
220 } 220 }
221 if (!IS_SPEC_FUNCTION(fun)) { 221 if (!IS_SPEC_FUNCTION(fun)) {
222 throw MakeTypeError(kObjectGetterExpectingFunction); 222 throw MakeTypeError(kObjectGetterExpectingFunction);
223 } 223 }
224 var desc = new PropertyDescriptor(); 224 var desc = new PropertyDescriptor();
225 desc.setGet(fun); 225 desc.setGet(fun);
226 desc.setEnumerable(true); 226 desc.setEnumerable(true);
227 desc.setConfigurable(true); 227 desc.setConfigurable(true);
228 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); 228 DefineOwnProperty(TO_OBJECT(receiver), TO_NAME(name), desc, false);
229 } 229 }
230 230
231 231
232 function ObjectLookupGetter(name) { 232 function ObjectLookupGetter(name) {
233 var receiver = this; 233 var receiver = this;
234 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { 234 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) {
235 receiver = %GlobalProxy(ObjectLookupGetter); 235 receiver = %GlobalProxy(ObjectLookupGetter);
236 } 236 }
237 return %LookupAccessor(TO_OBJECT(receiver), $toName(name), GETTER); 237 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), GETTER);
238 } 238 }
239 239
240 240
241 function ObjectDefineSetter(name, fun) { 241 function ObjectDefineSetter(name, fun) {
242 var receiver = this; 242 var receiver = this;
243 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { 243 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) {
244 receiver = %GlobalProxy(ObjectDefineSetter); 244 receiver = %GlobalProxy(ObjectDefineSetter);
245 } 245 }
246 if (!IS_SPEC_FUNCTION(fun)) { 246 if (!IS_SPEC_FUNCTION(fun)) {
247 throw MakeTypeError(kObjectSetterExpectingFunction); 247 throw MakeTypeError(kObjectSetterExpectingFunction);
248 } 248 }
249 var desc = new PropertyDescriptor(); 249 var desc = new PropertyDescriptor();
250 desc.setSet(fun); 250 desc.setSet(fun);
251 desc.setEnumerable(true); 251 desc.setEnumerable(true);
252 desc.setConfigurable(true); 252 desc.setConfigurable(true);
253 DefineOwnProperty(TO_OBJECT(receiver), $toName(name), desc, false); 253 DefineOwnProperty(TO_OBJECT(receiver), TO_NAME(name), desc, false);
254 } 254 }
255 255
256 256
257 function ObjectLookupSetter(name) { 257 function ObjectLookupSetter(name) {
258 var receiver = this; 258 var receiver = this;
259 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { 259 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) {
260 receiver = %GlobalProxy(ObjectLookupSetter); 260 receiver = %GlobalProxy(ObjectLookupSetter);
261 } 261 }
262 return %LookupAccessor(TO_OBJECT(receiver), $toName(name), SETTER); 262 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), SETTER);
263 } 263 }
264 264
265 265
266 function ObjectKeys(obj) { 266 function ObjectKeys(obj) {
267 obj = TO_OBJECT(obj); 267 obj = TO_OBJECT(obj);
268 if (%_IsJSProxy(obj)) { 268 if (%_IsJSProxy(obj)) {
269 var handler = %GetHandler(obj); 269 var handler = %GetHandler(obj);
270 var names = CallTrap0(handler, "keys", ProxyDerivedKeysTrap); 270 var names = CallTrap0(handler, "keys", ProxyDerivedKeysTrap);
271 return ToNameArray(names, "keys", false); 271 return ToNameArray(names, "keys", false);
272 } 272 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 554 }
555 555
556 556
557 function CallTrap2(handler, name, defaultTrap, x, y) { 557 function CallTrap2(handler, name, defaultTrap, x, y) {
558 return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap)); 558 return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap));
559 } 559 }
560 560
561 561
562 // ES5 section 8.12.1. 562 // ES5 section 8.12.1.
563 function GetOwnPropertyJS(obj, v) { 563 function GetOwnPropertyJS(obj, v) {
564 var p = $toName(v); 564 var p = TO_NAME(v);
565 if (%_IsJSProxy(obj)) { 565 if (%_IsJSProxy(obj)) {
566 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 566 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
567 if (IS_SYMBOL(v)) return UNDEFINED; 567 if (IS_SYMBOL(v)) return UNDEFINED;
568 568
569 var handler = %GetHandler(obj); 569 var handler = %GetHandler(obj);
570 var descriptor = CallTrap1( 570 var descriptor = CallTrap1(
571 handler, "getOwnPropertyDescriptor", UNDEFINED, p); 571 handler, "getOwnPropertyDescriptor", UNDEFINED, p);
572 if (IS_UNDEFINED(descriptor)) return descriptor; 572 if (IS_UNDEFINED(descriptor)) return descriptor;
573 var desc = ToCompletePropertyDescriptor(descriptor); 573 var desc = ToCompletePropertyDescriptor(descriptor);
574 if (!desc.isConfigurable()) { 574 if (!desc.isConfigurable()) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } else { 625 } else {
626 return false; 626 return false;
627 } 627 }
628 } 628 }
629 return true; 629 return true;
630 } 630 }
631 631
632 632
633 // ES5 8.12.9. 633 // ES5 8.12.9.
634 function DefineObjectProperty(obj, p, desc, should_throw) { 634 function DefineObjectProperty(obj, p, desc, should_throw) {
635 var current_array = %GetOwnProperty(obj, $toName(p)); 635 var current_array = %GetOwnProperty(obj, TO_NAME(p));
636 var current = ConvertDescriptorArrayToDescriptor(current_array); 636 var current = ConvertDescriptorArrayToDescriptor(current_array);
637 var extensible = %IsExtensible(obj); 637 var extensible = %IsExtensible(obj);
638 638
639 // Error handling according to spec. 639 // Error handling according to spec.
640 // Step 3 640 // Step 3
641 if (IS_UNDEFINED(current) && !extensible) { 641 if (IS_UNDEFINED(current) && !extensible) {
642 if (should_throw) { 642 if (should_throw) {
643 throw MakeTypeError(kDefineDisallowed, p); 643 throw MakeTypeError(kDefineDisallowed, p);
644 } else { 644 } else {
645 return false; 645 return false;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 // For Harmony proxies 899 // For Harmony proxies
900 function ToNameArray(obj, trap, includeSymbols) { 900 function ToNameArray(obj, trap, includeSymbols) {
901 if (!IS_SPEC_OBJECT(obj)) { 901 if (!IS_SPEC_OBJECT(obj)) {
902 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj); 902 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj);
903 } 903 }
904 var n = TO_UINT32(obj.length); 904 var n = TO_UINT32(obj.length);
905 var array = new GlobalArray(n); 905 var array = new GlobalArray(n);
906 var realLength = 0; 906 var realLength = 0;
907 var names = { __proto__: null }; // TODO(rossberg): use sets once ready. 907 var names = { __proto__: null }; // TODO(rossberg): use sets once ready.
908 for (var index = 0; index < n; index++) { 908 for (var index = 0; index < n; index++) {
909 var s = $toName(obj[index]); 909 var s = TO_NAME(obj[index]);
910 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 910 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
911 if (IS_SYMBOL(s) && !includeSymbols) continue; 911 if (IS_SYMBOL(s) && !includeSymbols) continue;
912 if (%HasOwnProperty(names, s)) { 912 if (%HasOwnProperty(names, s)) {
913 throw MakeTypeError(kProxyRepeatedPropName, trap, s); 913 throw MakeTypeError(kProxyRepeatedPropName, trap, s);
914 } 914 }
915 array[realLength] = s; 915 array[realLength] = s;
916 ++realLength; 916 ++realLength;
917 names[s] = 0; 917 names[s] = 0;
918 } 918 }
919 array.length = realLength; 919 array.length = realLength;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); 1025 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties);
1026 return obj; 1026 return obj;
1027 } 1027 }
1028 1028
1029 1029
1030 // ES5 section 15.2.3.6. 1030 // ES5 section 15.2.3.6.
1031 function ObjectDefineProperty(obj, p, attributes) { 1031 function ObjectDefineProperty(obj, p, attributes) {
1032 if (!IS_SPEC_OBJECT(obj)) { 1032 if (!IS_SPEC_OBJECT(obj)) {
1033 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty"); 1033 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty");
1034 } 1034 }
1035 var name = $toName(p); 1035 var name = TO_NAME(p);
1036 if (%_IsJSProxy(obj)) { 1036 if (%_IsJSProxy(obj)) {
1037 // Clone the attributes object for protection. 1037 // Clone the attributes object for protection.
1038 // TODO(rossberg): not spec'ed yet, so not sure if this should involve 1038 // TODO(rossberg): not spec'ed yet, so not sure if this should involve
1039 // non-own properties as it does (or non-enumerable ones, as it doesn't?). 1039 // non-own properties as it does (or non-enumerable ones, as it doesn't?).
1040 var attributesClone = { __proto__: null }; 1040 var attributesClone = { __proto__: null };
1041 for (var a in attributes) { 1041 for (var a in attributes) {
1042 attributesClone[a] = attributes[a]; 1042 attributesClone[a] = attributes[a];
1043 } 1043 }
1044 DefineProxyProperty(obj, name, attributesClone, true); 1044 DefineProxyProperty(obj, name, attributesClone, true);
1045 // The following would implement the spec as in the current proposal, 1045 // The following would implement the spec as in the current proposal,
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 }); 1810 });
1811 1811
1812 %InstallToContext([ 1812 %InstallToContext([
1813 "global_eval_fun", GlobalEval, 1813 "global_eval_fun", GlobalEval,
1814 "object_define_own_property", DefineOwnPropertyFromAPI, 1814 "object_define_own_property", DefineOwnPropertyFromAPI,
1815 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, 1815 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor,
1816 "to_complete_property_descriptor", ToCompletePropertyDescriptor, 1816 "to_complete_property_descriptor", ToCompletePropertyDescriptor,
1817 ]); 1817 ]);
1818 1818
1819 }) 1819 })
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/harmony/to-name.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698