OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // ES5 8.10.3. | 329 // ES5 8.10.3. |
330 function IsGenericDescriptor(desc) { | 330 function IsGenericDescriptor(desc) { |
331 return !(IsAccessorDescriptor(desc) || IsDataDescriptor(desc)); | 331 return !(IsAccessorDescriptor(desc) || IsDataDescriptor(desc)); |
332 } | 332 } |
333 | 333 |
334 | 334 |
335 function IsInconsistentDescriptor(desc) { | 335 function IsInconsistentDescriptor(desc) { |
336 return IsAccessorDescriptor(desc) && IsDataDescriptor(desc); | 336 return IsAccessorDescriptor(desc) && IsDataDescriptor(desc); |
337 } | 337 } |
338 | 338 |
339 | |
340 // ES5 8.10.4 | 339 // ES5 8.10.4 |
341 function FromPropertyDescriptor(desc) { | 340 function FromPropertyDescriptor(desc) { |
342 if (IS_UNDEFINED(desc)) return desc; | 341 if (IS_UNDEFINED(desc)) return desc; |
343 var obj = new $Object(); | 342 var obj = new $Object(); |
344 if (IsDataDescriptor(desc)) { | 343 if (IsDataDescriptor(desc)) { |
345 obj.value = desc.getValue(); | 344 obj.value = desc.getValue(); |
346 obj.writable = desc.isWritable(); | 345 obj.writable = desc.isWritable(); |
347 } | 346 } |
348 if (IsAccessorDescriptor(desc)) { | 347 if (IsAccessorDescriptor(desc)) { |
349 obj.get = desc.getGet(); | 348 obj.get = desc.getGet(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 desc.setSet(set); | 392 desc.setSet(set); |
394 } | 393 } |
395 | 394 |
396 if (IsInconsistentDescriptor(desc)) { | 395 if (IsInconsistentDescriptor(desc)) { |
397 throw MakeTypeError("value_and_accessor", [obj]); | 396 throw MakeTypeError("value_and_accessor", [obj]); |
398 } | 397 } |
399 return desc; | 398 return desc; |
400 } | 399 } |
401 | 400 |
402 | 401 |
403 // For Harmony proxies. | |
404 function ToCompletePropertyDescriptor(obj) { | |
405 var desc = ToPropertyDescriptor(obj) | |
406 if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) { | |
407 if (!("value" in desc)) desc.value = void 0; | |
408 if (!("writable" in desc)) desc.writable = false; | |
409 } else { | |
410 // Is accessor descriptor. | |
411 if (!("get" in desc)) desc.get = void 0; | |
412 if (!("set" in desc)) desc.set = void 0; | |
413 } | |
414 if (!("enumerable" in desc)) desc.enumerable = false; | |
415 if (!("configurable" in desc)) desc.configurable = false; | |
416 return desc; | |
417 } | |
418 | |
419 | |
420 function PropertyDescriptor() { | 402 function PropertyDescriptor() { |
421 // Initialize here so they are all in-object and have the same map. | 403 // Initialize here so they are all in-object and have the same map. |
422 // Default values from ES5 8.6.1. | 404 // Default values from ES5 8.6.1. |
423 this.value_ = void 0; | 405 this.value_ = void 0; |
424 this.hasValue_ = false; | 406 this.hasValue_ = false; |
425 this.writable_ = false; | 407 this.writable_ = false; |
426 this.hasWritable_ = false; | 408 this.hasWritable_ = false; |
427 this.enumerable_ = false; | 409 this.enumerable_ = false; |
428 this.hasEnumerable_ = false; | 410 this.hasEnumerable_ = false; |
429 this.configurable_ = false; | 411 this.configurable_ = false; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 } | 540 } |
559 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); | 541 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); |
560 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); | 542 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); |
561 | 543 |
562 return desc; | 544 return desc; |
563 } | 545 } |
564 | 546 |
565 | 547 |
566 // ES5 section 8.12.2. | 548 // ES5 section 8.12.2. |
567 function GetProperty(obj, p) { | 549 function GetProperty(obj, p) { |
568 if (%IsJSProxy(obj)) { | |
569 var handler = %GetHandler(obj); | |
570 var getProperty = handler.getPropertyDescriptor; | |
571 if (IS_UNDEFINED(getProperty)) { | |
572 throw MakeTypeError("handler_trap_missing", | |
573 [handler, "getPropertyDescriptor"]); | |
574 } | |
575 var descriptor = getProperty.call(handler, p); | |
576 if (IS_UNDEFINED(descriptor)) return descriptor; | |
577 var desc = ToCompletePropertyDescriptor(descriptor); | |
578 if (!desc.configurable) { | |
579 throw MakeTypeError("proxy_prop_not_configurable", | |
580 [handler, "getPropertyDescriptor", p, descriptor]); | |
581 } | |
582 return desc; | |
583 } | |
584 var prop = GetOwnProperty(obj); | 550 var prop = GetOwnProperty(obj); |
585 if (!IS_UNDEFINED(prop)) return prop; | 551 if (!IS_UNDEFINED(prop)) return prop; |
586 var proto = %GetPrototype(obj); | 552 var proto = obj.__proto__; |
587 if (IS_NULL(proto)) return void 0; | 553 if (IS_NULL(proto)) return void 0; |
588 return GetProperty(proto, p); | 554 return GetProperty(proto, p); |
589 } | 555 } |
590 | 556 |
591 | 557 |
592 // ES5 section 8.12.6 | 558 // ES5 section 8.12.6 |
593 function HasProperty(obj, p) { | 559 function HasProperty(obj, p) { |
594 if (%IsJSProxy(obj)) { | |
595 var handler = %GetHandler(obj) | |
596 var has = handler.has | |
597 if (IS_UNDEFINED(has)) has = DerivedHasTrap | |
598 return ToBoolean(has.call(handler, obj, p)) | |
599 } | |
600 var desc = GetProperty(obj, p); | 560 var desc = GetProperty(obj, p); |
601 return IS_UNDEFINED(desc) ? false : true; | 561 return IS_UNDEFINED(desc) ? false : true; |
602 } | 562 } |
603 | 563 |
604 | 564 |
605 // ES5 section 8.12.1. | 565 // ES5 section 8.12.1. |
606 function GetOwnProperty(obj, p) { | 566 function GetOwnProperty(obj, p) { |
607 // GetOwnProperty returns an array indexed by the constants | 567 // GetOwnProperty returns an array indexed by the constants |
608 // defined in macros.py. | 568 // defined in macros.py. |
609 // If p is not a property on obj undefined is returned. | 569 // If p is not a property on obj undefined is returned. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 } | 738 } |
779 } | 739 } |
780 return true; | 740 return true; |
781 } | 741 } |
782 | 742 |
783 | 743 |
784 // ES5 section 15.2.3.2. | 744 // ES5 section 15.2.3.2. |
785 function ObjectGetPrototypeOf(obj) { | 745 function ObjectGetPrototypeOf(obj) { |
786 if (!IS_SPEC_OBJECT(obj)) | 746 if (!IS_SPEC_OBJECT(obj)) |
787 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); | 747 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); |
788 return %GetPrototype(obj); | 748 return obj.__proto__; |
789 } | 749 } |
790 | 750 |
791 | 751 |
792 // ES5 section 15.2.3.3 | 752 // ES5 section 15.2.3.3 |
793 function ObjectGetOwnPropertyDescriptor(obj, p) { | 753 function ObjectGetOwnPropertyDescriptor(obj, p) { |
794 if (!IS_SPEC_OBJECT(obj)) | 754 if (!IS_SPEC_OBJECT(obj)) |
795 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); | 755 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); |
796 var desc = GetOwnProperty(obj, p); | 756 var desc = GetOwnProperty(obj, p); |
797 return FromPropertyDescriptor(desc); | 757 return FromPropertyDescriptor(desc); |
798 } | 758 } |
799 | 759 |
800 | 760 |
801 // For Harmony proxies | |
802 function ToStringArray(obj, trap) { | |
803 if (!IS_SPEC_OBJECT(obj)) { | |
804 throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]); | |
805 } | |
806 var n = ToUint32(obj.length); | |
807 var array = new $Array(n); | |
808 var names = {} | |
809 for (var index = 0; index < n; index++) { | |
810 var s = ToString(obj[index]); | |
811 if (s in names) { | |
812 throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]) | |
813 } | |
814 array[index] = s; | |
815 names.s = 0; | |
816 } | |
817 return array; | |
818 } | |
819 | |
820 | |
821 // ES5 section 15.2.3.4. | 761 // ES5 section 15.2.3.4. |
822 function ObjectGetOwnPropertyNames(obj) { | 762 function ObjectGetOwnPropertyNames(obj) { |
823 if (!IS_SPEC_OBJECT(obj)) | 763 if (!IS_SPEC_OBJECT(obj)) |
824 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; | 764 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; |
825 | 765 |
826 // Special handling for proxies. | |
827 if (%IsJSProxy(obj)) { | |
828 var handler = %GetHandler(obj); | |
829 var getOwnPropertyNames = handler.getOwnPropertyNames; | |
830 if (IS_UNDEFINED(getOwnPropertyNames)) { | |
831 throw MakeTypeError("handler_trap_missing", | |
832 [handler, "getOwnPropertyNames"]); | |
833 } | |
834 var names = getOwnPropertyNames.call(handler); | |
835 return ToStringArray(names, "getOwnPropertyNames"); | |
836 } | |
837 | |
838 // Find all the indexed properties. | 766 // Find all the indexed properties. |
839 | 767 |
840 // Get the local element names. | 768 // Get the local element names. |
841 var propertyNames = %GetLocalElementNames(obj); | 769 var propertyNames = %GetLocalElementNames(obj); |
842 | 770 |
843 // Get names for indexed interceptor properties. | 771 // Get names for indexed interceptor properties. |
844 if (%GetInterceptorInfo(obj) & 1) { | 772 if (%GetInterceptorInfo(obj) & 1) { |
845 var indexedInterceptorNames = | 773 var indexedInterceptorNames = |
846 %GetIndexedInterceptorElementNames(obj); | 774 %GetIndexedInterceptorElementNames(obj); |
847 if (indexedInterceptorNames) | 775 if (indexedInterceptorNames) |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 // ---------------------------------------------------------------------------- | 1314 // ---------------------------------------------------------------------------- |
1387 | 1315 |
1388 function SetupFunction() { | 1316 function SetupFunction() { |
1389 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1317 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1390 "bind", FunctionBind, | 1318 "bind", FunctionBind, |
1391 "toString", FunctionToString | 1319 "toString", FunctionToString |
1392 )); | 1320 )); |
1393 } | 1321 } |
1394 | 1322 |
1395 SetupFunction(); | 1323 SetupFunction(); |
OLD | NEW |