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

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

Issue 1451703003: [proxies] Wire up Object.getOwnPropertyDescriptor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: moved test file Created 5 years, 1 month 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.h » ('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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (IS_UNDEFINED(desc)) return false; 302 if (IS_UNDEFINED(desc)) return false;
303 return !(IsAccessorDescriptor(desc) || IsDataDescriptor(desc)); 303 return !(IsAccessorDescriptor(desc) || IsDataDescriptor(desc));
304 } 304 }
305 305
306 306
307 function IsInconsistentDescriptor(desc) { 307 function IsInconsistentDescriptor(desc) {
308 return IsAccessorDescriptor(desc) && IsDataDescriptor(desc); 308 return IsAccessorDescriptor(desc) && IsDataDescriptor(desc);
309 } 309 }
310 310
311 311
312 // ES5 8.10.4
313 function FromPropertyDescriptor(desc) {
314 if (IS_UNDEFINED(desc)) return desc;
315
316 if (IsDataDescriptor(desc)) {
317 return { value: desc.getValue(),
318 writable: desc.isWritable(),
319 enumerable: desc.isEnumerable(),
320 configurable: desc.isConfigurable() };
321 }
322 // Must be an AccessorDescriptor then. We never return a generic descriptor.
323 return { get: desc.getGet(),
324 set: desc.getSet(),
325 enumerable: desc.isEnumerable(),
326 configurable: desc.isConfigurable() };
327 }
328
329
330 // Harmony Proxies 312 // Harmony Proxies
331 function FromGenericPropertyDescriptor(desc) { 313 function FromGenericPropertyDescriptor(desc) {
332 if (IS_UNDEFINED(desc)) return desc; 314 if (IS_UNDEFINED(desc)) return desc;
333 var obj = new GlobalObject(); 315 var obj = new GlobalObject();
334 316
335 if (desc.hasValue()) { 317 if (desc.hasValue()) {
336 %AddNamedProperty(obj, "value", desc.getValue(), NONE); 318 %AddNamedProperty(obj, "value", desc.getValue(), NONE);
337 } 319 }
338 if (desc.hasWritable()) { 320 if (desc.hasWritable()) {
339 %AddNamedProperty(obj, "writable", desc.isWritable(), NONE); 321 %AddNamedProperty(obj, "writable", desc.isWritable(), NONE);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 return %_Call(GetTrap(handler, name, defaultTrap), handler, x); 544 return %_Call(GetTrap(handler, name, defaultTrap), handler, x);
563 } 545 }
564 546
565 547
566 function CallTrap2(handler, name, defaultTrap, x, y) { 548 function CallTrap2(handler, name, defaultTrap, x, y) {
567 return %_Call(GetTrap(handler, name, defaultTrap), handler, x, y); 549 return %_Call(GetTrap(handler, name, defaultTrap), handler, x, y);
568 } 550 }
569 551
570 552
571 // ES5 section 8.12.1. 553 // ES5 section 8.12.1.
554 // TODO(jkummerow): Deprecated. Migrate all callers to
555 // ObjectGetOwnPropertyDescriptor and delete this.
572 function GetOwnPropertyJS(obj, v) { 556 function GetOwnPropertyJS(obj, v) {
573 var p = TO_NAME(v); 557 var p = TO_NAME(v);
574 if (%_IsJSProxy(obj)) { 558 if (%_IsJSProxy(obj)) {
575 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 559 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
576 if (IS_SYMBOL(v)) return UNDEFINED; 560 if (IS_SYMBOL(v)) return UNDEFINED;
577 561
578 var handler = %GetHandler(obj); 562 var handler = %GetHandler(obj);
579 var descriptor = CallTrap1( 563 var descriptor = CallTrap1(
580 handler, "getOwnPropertyDescriptor", UNDEFINED, p); 564 handler, "getOwnPropertyDescriptor", UNDEFINED, p);
581 if (IS_UNDEFINED(descriptor)) return descriptor; 565 if (IS_UNDEFINED(descriptor)) return descriptor;
582 var desc = ToCompletePropertyDescriptor(descriptor); 566 var desc = ToCompletePropertyDescriptor(descriptor);
583 if (!desc.isConfigurable()) { 567 if (!desc.isConfigurable()) {
584 throw MakeTypeError(kProxyPropNotConfigurable, 568 throw MakeTypeError(kProxyPropNotConfigurable,
585 handler, p, "getOwnPropertyDescriptor"); 569 handler, p, "getOwnPropertyDescriptor");
586 } 570 }
587 return desc; 571 return desc;
588 } 572 }
589 573
590 // GetOwnProperty returns an array indexed by the constants 574 // GetOwnProperty returns an array indexed by the constants
591 // defined in macros.py. 575 // defined in macros.py.
592 // If p is not a property on obj undefined is returned. 576 // If p is not a property on obj undefined is returned.
593 var props = %GetOwnProperty(TO_OBJECT(obj), p); 577 var props = %GetOwnProperty_Legacy(TO_OBJECT(obj), p);
594 578
595 return ConvertDescriptorArrayToDescriptor(props); 579 return ConvertDescriptorArrayToDescriptor(props);
596 } 580 }
597 581
598 582
599 // ES5 section 8.12.7. 583 // ES5 section 8.12.7.
600 function Delete(obj, p, should_throw) { 584 function Delete(obj, p, should_throw) {
601 var desc = GetOwnPropertyJS(obj, p); 585 var desc = GetOwnPropertyJS(obj, p);
602 if (IS_UNDEFINED(desc)) return true; 586 if (IS_UNDEFINED(desc)) return true;
603 if (desc.isConfigurable()) { 587 if (desc.isConfigurable()) {
(...skipping 30 matching lines...) Expand all
634 } else { 618 } else {
635 return false; 619 return false;
636 } 620 }
637 } 621 }
638 return true; 622 return true;
639 } 623 }
640 624
641 625
642 // ES5 8.12.9. 626 // ES5 8.12.9.
643 function DefineObjectProperty(obj, p, desc, should_throw) { 627 function DefineObjectProperty(obj, p, desc, should_throw) {
644 var current_array = %GetOwnProperty(obj, TO_NAME(p)); 628 var current_array = %GetOwnProperty_Legacy(obj, TO_NAME(p));
645 var current = ConvertDescriptorArrayToDescriptor(current_array); 629 var current = ConvertDescriptorArrayToDescriptor(current_array);
646 var extensible = %IsExtensible(obj); 630 var extensible = %IsExtensible(obj);
647 631
648 // Error handling according to spec. 632 // Error handling according to spec.
649 // Step 3 633 // Step 3
650 if (IS_UNDEFINED(current) && !extensible) { 634 if (IS_UNDEFINED(current) && !extensible) {
651 if (should_throw) { 635 if (should_throw) {
652 throw MakeTypeError(kDefineDisallowed, p); 636 throw MakeTypeError(kDefineDisallowed, p);
653 } else { 637 } else {
654 return false; 638 return false;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 if (IS_SPEC_OBJECT(obj)) { 866 if (IS_SPEC_OBJECT(obj)) {
883 %SetPrototype(obj, proto); 867 %SetPrototype(obj, proto);
884 } 868 }
885 869
886 return obj; 870 return obj;
887 } 871 }
888 872
889 873
890 // ES6 section 19.1.2.6 874 // ES6 section 19.1.2.6
891 function ObjectGetOwnPropertyDescriptor(obj, p) { 875 function ObjectGetOwnPropertyDescriptor(obj, p) {
892 var desc = GetOwnPropertyJS(TO_OBJECT(obj), p); 876 return %GetOwnProperty(obj, p);
893 return FromPropertyDescriptor(desc);
894 } 877 }
895 878
896 879
897 // For Harmony proxies 880 // For Harmony proxies
898 function ToNameArray(obj, trap, includeSymbols) { 881 function ToNameArray(obj, trap, includeSymbols) {
899 if (!IS_SPEC_OBJECT(obj)) { 882 if (!IS_SPEC_OBJECT(obj)) {
900 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj); 883 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj);
901 } 884 }
902 var n = TO_UINT32(obj.length); 885 var n = TO_UINT32(obj.length);
903 var array = new GlobalArray(n); 886 var array = new GlobalArray(n);
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 1794
1812 %InstallToContext([ 1795 %InstallToContext([
1813 "global_eval_fun", GlobalEval, 1796 "global_eval_fun", GlobalEval,
1814 "object_value_of", ObjectValueOf, 1797 "object_value_of", ObjectValueOf,
1815 "object_to_string", ObjectToString, 1798 "object_to_string", ObjectToString,
1816 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, 1799 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor,
1817 "to_complete_property_descriptor", ToCompletePropertyDescriptor, 1800 "to_complete_property_descriptor", ToCompletePropertyDescriptor,
1818 ]); 1801 ]);
1819 1802
1820 }) 1803 })
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698