Chromium Code Reviews| 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 } | 347 } |
| 348 if (IsAccessorDescriptor(desc)) { | 348 if (IsAccessorDescriptor(desc)) { |
| 349 obj.get = desc.getGet(); | 349 obj.get = desc.getGet(); |
| 350 obj.set = desc.getSet(); | 350 obj.set = desc.getSet(); |
| 351 } | 351 } |
| 352 obj.enumerable = desc.isEnumerable(); | 352 obj.enumerable = desc.isEnumerable(); |
| 353 obj.configurable = desc.isConfigurable(); | 353 obj.configurable = desc.isConfigurable(); |
| 354 return obj; | 354 return obj; |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Harmony Proxies | |
| 358 function FromGenericPropertyDescriptor(desc) { | |
| 359 if (IS_UNDEFINED(desc)) return desc; | |
| 360 var obj = new $Object(); | |
| 361 if (desc.hasValue_) obj.value = desc.getValue(); | |
|
Kevin Millikin (Chromium)
2011/07/07 08:12:02
It's not obvious why you use the property hasValue
rossberg
2011/07/07 09:19:32
True. I copied from pre-existing functions. I fixe
| |
| 362 if (desc.hasWritable_) obj.writable = desc.isWritable(); | |
| 363 if (desc.hasGetter_) obj.get = desc.getGet(); | |
| 364 if (desc.hasSetter_) obj.set = desc.getSet(); | |
| 365 if (desc.hasEnumerable_) obj.enumerable = desc.isEnumerable(); | |
| 366 if (desc.hasConfigurable_) obj.configurable = desc.isConfigurable(); | |
| 367 return obj; | |
| 368 } | |
| 369 | |
| 357 // ES5 8.10.5. | 370 // ES5 8.10.5. |
| 358 function ToPropertyDescriptor(obj) { | 371 function ToPropertyDescriptor(obj) { |
| 359 if (!IS_SPEC_OBJECT(obj)) { | 372 if (!IS_SPEC_OBJECT(obj)) { |
| 360 throw MakeTypeError("property_desc_object", [obj]); | 373 throw MakeTypeError("property_desc_object", [obj]); |
| 361 } | 374 } |
| 362 var desc = new PropertyDescriptor(); | 375 var desc = new PropertyDescriptor(); |
| 363 | 376 |
| 364 if ("enumerable" in obj) { | 377 if ("enumerable" in obj) { |
| 365 desc.setEnumerable(ToBoolean(obj.enumerable)); | 378 desc.setEnumerable(ToBoolean(obj.enumerable)); |
| 366 } | 379 } |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 // If p is not a property on obj undefined is returned. | 622 // If p is not a property on obj undefined is returned. |
| 610 var props = %GetOwnProperty(ToObject(obj), ToString(p)); | 623 var props = %GetOwnProperty(ToObject(obj), ToString(p)); |
| 611 | 624 |
| 612 // A false value here means that access checks failed. | 625 // A false value here means that access checks failed. |
| 613 if (props === false) return void 0; | 626 if (props === false) return void 0; |
| 614 | 627 |
| 615 return ConvertDescriptorArrayToDescriptor(props); | 628 return ConvertDescriptorArrayToDescriptor(props); |
| 616 } | 629 } |
| 617 | 630 |
| 618 | 631 |
| 632 // Harmony proxies. | |
| 633 function DefineProxyProperty(obj, p, attributes, should_throw) { | |
| 634 var handler = %GetHandler(obj); | |
| 635 var defineProperty = handler.defineProperty; | |
| 636 if (IS_UNDEFINED(defineProperty)) { | |
| 637 throw MakeTypeError("handler_trap_missing", [handler, "defineProperty"]); | |
| 638 } | |
| 639 var result = defineProperty.call(handler, p, attributes); | |
| 640 if (!ToBoolean(result)) { | |
| 641 if (should_throw) { | |
| 642 throw MakeTypeError("handler_failed", [handler, "defineProperty"]); | |
| 643 } else { | |
| 644 return false; | |
| 645 } | |
| 646 } | |
| 647 return true; | |
| 648 } | |
| 649 | |
| 650 | |
| 619 // ES5 8.12.9. | 651 // ES5 8.12.9. |
| 620 function DefineOwnProperty(obj, p, desc, should_throw) { | 652 function DefineOwnProperty(obj, p, desc, should_throw) { |
| 653 if (%IsJSProxy(obj)) { | |
| 654 var attributes = FromGenericPropertyDescriptor(desc); | |
| 655 return DefineProxyProperty(obj, p, attributes, should_throw); | |
| 656 } | |
| 657 | |
| 621 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); | 658 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); |
| 622 // A false value here means that access checks failed. | 659 // A false value here means that access checks failed. |
| 623 if (current_or_access === false) return void 0; | 660 if (current_or_access === false) return void 0; |
| 624 | 661 |
| 625 var current = ConvertDescriptorArrayToDescriptor(current_or_access); | 662 var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
| 626 var extensible = %IsExtensible(ToObject(obj)); | 663 var extensible = %IsExtensible(ToObject(obj)); |
| 627 | 664 |
| 628 // Error handling according to spec. | 665 // Error handling according to spec. |
| 629 // Step 3 | 666 // Step 3 |
| 630 if (IS_UNDEFINED(current) && !extensible) { | 667 if (IS_UNDEFINED(current) && !extensible) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 893 return obj; | 930 return obj; |
| 894 } | 931 } |
| 895 | 932 |
| 896 | 933 |
| 897 // ES5 section 15.2.3.6. | 934 // ES5 section 15.2.3.6. |
| 898 function ObjectDefineProperty(obj, p, attributes) { | 935 function ObjectDefineProperty(obj, p, attributes) { |
| 899 if (!IS_SPEC_OBJECT(obj)) { | 936 if (!IS_SPEC_OBJECT(obj)) { |
| 900 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); | 937 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); |
| 901 } | 938 } |
| 902 var name = ToString(p); | 939 var name = ToString(p); |
| 903 var desc = ToPropertyDescriptor(attributes); | 940 if (%IsJSProxy(obj)) { |
| 904 DefineOwnProperty(obj, name, desc, true); | 941 // Clone the attributes object for protection. |
| 942 // TODO(rossberg): not spec'ed yet, so not sure if this should involve | |
| 943 // non-own properties as it does (or non-enumerable ones, as it doesn't?). | |
| 944 var attributesClone = {} | |
| 945 for (var a in attributes) { | |
| 946 attributesClone[a] = attributes[a]; | |
| 947 } | |
| 948 DefineProxyProperty(obj, name, attributesClone, true); | |
| 949 // The following would implement the spec as in the current proposal, | |
| 950 // but after recent comments on es-discuss, is most likely obsolete. | |
| 951 /* | |
| 952 var defineObj = FromGenericPropertyDescriptor(desc); | |
| 953 var names = ObjectGetOwnPropertyNames(attributes); | |
| 954 var standardNames = | |
| 955 {value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0}; | |
| 956 for (var i = 0; i < names.length; i++) { | |
| 957 var N = names[i]; | |
| 958 if (!(%HasLocalProperty(standardNames, N))) { | |
| 959 var attr = GetOwnProperty(attributes, N); | |
| 960 DefineOwnProperty(descObj, N, attr, true); | |
| 961 } | |
| 962 } | |
| 963 // This is really confusing the types, but it is what the proxies spec | |
| 964 // currently requires: | |
| 965 desc = descObj; | |
| 966 */ | |
| 967 } else { | |
| 968 var desc = ToPropertyDescriptor(attributes); | |
| 969 DefineOwnProperty(obj, name, desc, true); | |
| 970 } | |
| 905 return obj; | 971 return obj; |
| 906 } | 972 } |
| 907 | 973 |
| 908 | 974 |
| 909 // ES5 section 15.2.3.7. | 975 // ES5 section 15.2.3.7. |
| 910 function ObjectDefineProperties(obj, properties) { | 976 function ObjectDefineProperties(obj, properties) { |
| 911 if (!IS_SPEC_OBJECT(obj)) | 977 if (!IS_SPEC_OBJECT(obj)) |
| 912 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); | 978 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); |
| 913 var props = ToObject(properties); | 979 var props = ToObject(properties); |
| 914 var key_values = []; | 980 var key_values = []; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1391 // ---------------------------------------------------------------------------- | 1457 // ---------------------------------------------------------------------------- |
| 1392 | 1458 |
| 1393 function SetupFunction() { | 1459 function SetupFunction() { |
| 1394 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1460 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1395 "bind", FunctionBind, | 1461 "bind", FunctionBind, |
| 1396 "toString", FunctionToString | 1462 "toString", FunctionToString |
| 1397 )); | 1463 )); |
| 1398 } | 1464 } |
| 1399 | 1465 |
| 1400 SetupFunction(); | 1466 SetupFunction(); |
| OLD | NEW |