| 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 var current = GetOwnProperty(obj, p); | 540 var current = GetOwnProperty(obj, p); |
| 541 var extensible = %IsExtensible(ToObject(obj)); | 541 var extensible = %IsExtensible(ToObject(obj)); |
| 542 | 542 |
| 543 // Error handling according to spec. | 543 // Error handling according to spec. |
| 544 // Step 3 | 544 // Step 3 |
| 545 if (IS_UNDEFINED(current) && !extensible) | 545 if (IS_UNDEFINED(current) && !extensible) |
| 546 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 546 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
| 547 | 547 |
| 548 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { | 548 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { |
| 549 // Step 5 and 6 | 549 // Step 5 and 6 |
| 550 if ((!desc.hasEnumerable() || | 550 if ((!desc.hasEnumerable() || |
| 551 SameValue(desc.isEnumerable() && current.isEnumerable())) && | 551 SameValue(desc.isEnumerable() && current.isEnumerable())) && |
| 552 (!desc.hasConfigurable() || | 552 (!desc.hasConfigurable() || |
| 553 SameValue(desc.isConfigurable(), current.isConfigurable())) && | 553 SameValue(desc.isConfigurable(), current.isConfigurable())) && |
| 554 (!desc.hasWritable() || | 554 (!desc.hasWritable() || |
| 555 SameValue(desc.isWritable(), current.isWritable())) && | 555 SameValue(desc.isWritable(), current.isWritable())) && |
| 556 (!desc.hasValue() || | 556 (!desc.hasValue() || |
| 557 SameValue(desc.getValue(), current.getValue())) && | 557 SameValue(desc.getValue(), current.getValue())) && |
| 558 (!desc.hasGetter() || | 558 (!desc.hasGetter() || |
| 559 SameValue(desc.getGet(), current.getGet())) && | 559 SameValue(desc.getGet(), current.getGet())) && |
| 560 (!desc.hasSetter() || | 560 (!desc.hasSetter() || |
| 561 SameValue(desc.getSet(), current.getSet()))) { | 561 SameValue(desc.getSet(), current.getSet()))) { |
| 562 return true; | 562 return true; |
| 563 } | 563 } |
| 564 | 564 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 function ObjectSeal(obj) { | 748 function ObjectSeal(obj) { |
| 749 if (!IS_SPEC_OBJECT(obj)) { | 749 if (!IS_SPEC_OBJECT(obj)) { |
| 750 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]); | 750 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]); |
| 751 } | 751 } |
| 752 var names = ObjectGetOwnPropertyNames(obj); | 752 var names = ObjectGetOwnPropertyNames(obj); |
| 753 for (var i = 0; i < names.length; i++) { | 753 for (var i = 0; i < names.length; i++) { |
| 754 var name = names[i]; | 754 var name = names[i]; |
| 755 var desc = GetOwnProperty(obj, name); | 755 var desc = GetOwnProperty(obj, name); |
| 756 if (desc.isConfigurable()) desc.setConfigurable(false); | 756 if (desc.isConfigurable()) desc.setConfigurable(false); |
| 757 DefineOwnProperty(obj, name, desc, true); | 757 DefineOwnProperty(obj, name, desc, true); |
| 758 } | 758 } |
| 759 return ObjectPreventExtension(obj); | 759 return ObjectPreventExtension(obj); |
| 760 } | 760 } |
| 761 | 761 |
| 762 | 762 |
| 763 // ES5 section 15.2.3.9. | 763 // ES5 section 15.2.3.9. |
| 764 function ObjectFreeze(obj) { | 764 function ObjectFreeze(obj) { |
| 765 if (!IS_SPEC_OBJECT(obj)) { | 765 if (!IS_SPEC_OBJECT(obj)) { |
| 766 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); | 766 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); |
| 767 } | 767 } |
| 768 var names = ObjectGetOwnPropertyNames(obj); | 768 var names = ObjectGetOwnPropertyNames(obj); |
| 769 for (var i = 0; i < names.length; i++) { | 769 for (var i = 0; i < names.length; i++) { |
| 770 var name = names[i]; | 770 var name = names[i]; |
| 771 var desc = GetOwnProperty(obj, name); | 771 var desc = GetOwnProperty(obj, name); |
| 772 if (IsDataDescriptor(desc)) desc.setWritable(false); | 772 if (IsDataDescriptor(desc)) desc.setWritable(false); |
| 773 if (desc.isConfigurable()) desc.setConfigurable(false); | 773 if (desc.isConfigurable()) desc.setConfigurable(false); |
| 774 DefineOwnProperty(obj, name, desc, true); | 774 DefineOwnProperty(obj, name, desc, true); |
| 775 } | 775 } |
| 776 return ObjectPreventExtension(obj); | 776 return ObjectPreventExtension(obj); |
| 777 } | 777 } |
| 778 | 778 |
| 779 | 779 |
| 780 // ES5 section 15.2.3.10 | 780 // ES5 section 15.2.3.10 |
| 781 function ObjectPreventExtension(obj) { | 781 function ObjectPreventExtension(obj) { |
| 782 if (!IS_SPEC_OBJECT(obj)) { | 782 if (!IS_SPEC_OBJECT(obj)) { |
| 783 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); | 783 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); |
| 784 } | 784 } |
| 785 %PreventExtensions(obj); | 785 %PreventExtensions(obj); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 function FunctionBind(this_arg) { // Length is 1. | 1111 function FunctionBind(this_arg) { // Length is 1. |
| 1112 if (!IS_FUNCTION(this)) { | 1112 if (!IS_FUNCTION(this)) { |
| 1113 throw new $TypeError('Bind must be called on a function'); | 1113 throw new $TypeError('Bind must be called on a function'); |
| 1114 } | 1114 } |
| 1115 // this_arg is not an argument that should be bound. | 1115 // this_arg is not an argument that should be bound. |
| 1116 var argc_bound = (%_ArgumentsLength() || 1) - 1; | 1116 var argc_bound = (%_ArgumentsLength() || 1) - 1; |
| 1117 if (argc_bound > 0) { | 1117 if (argc_bound > 0) { |
| 1118 var bound_args = new $Array(argc_bound); | 1118 var bound_args = new $Array(argc_bound); |
| 1119 for(var i = 0; i < argc_bound; i++) { | 1119 for(var i = 0; i < argc_bound; i++) { |
| 1120 bound_args[i] = %_Arguments(i+1); | 1120 bound_args[i] = %_Arguments(i+1); |
| 1121 } | 1121 } |
| 1122 } | 1122 } |
| 1123 var fn = this; | 1123 var fn = this; |
| 1124 var result = function() { | 1124 var result = function() { |
| 1125 // Combine the args we got from the bind call with the args | 1125 // Combine the args we got from the bind call with the args |
| 1126 // given as argument to the invocation. | 1126 // given as argument to the invocation. |
| 1127 var argc = %_ArgumentsLength(); | 1127 var argc = %_ArgumentsLength(); |
| 1128 var args = new $Array(argc + argc_bound); | 1128 var args = new $Array(argc + argc_bound); |
| 1129 // Add bound arguments. | 1129 // Add bound arguments. |
| 1130 for (var i = 0; i < argc_bound; i++) { | 1130 for (var i = 0; i < argc_bound; i++) { |
| 1131 args[i] = bound_args[i]; | 1131 args[i] = bound_args[i]; |
| 1132 } | 1132 } |
| 1133 // Add arguments from call. | 1133 // Add arguments from call. |
| 1134 for (var i = 0; i < argc; i++) { | 1134 for (var i = 0; i < argc; i++) { |
| 1135 args[argc_bound + i] = %_Arguments(i); | 1135 args[argc_bound + i] = %_Arguments(i); |
| 1136 } | 1136 } |
| 1137 // If this is a construct call we use a special runtime method | 1137 // If this is a construct call we use a special runtime method |
| 1138 // to generate the actual object using the bound function. | 1138 // to generate the actual object using the bound function. |
| 1139 if (%_IsConstructCall()) { | 1139 if (%_IsConstructCall()) { |
| 1140 return %NewObjectFromBound(fn, args); | 1140 return %NewObjectFromBound(fn, args); |
| 1141 } | 1141 } |
| 1142 return fn.apply(this_arg, args); | 1142 return fn.apply(this_arg, args); |
| 1143 }; | 1143 }; |
| 1144 | 1144 |
| 1145 // We already have caller and arguments properties on functions, | 1145 // We already have caller and arguments properties on functions, |
| 1146 // which are non-configurable. It therefore makes no sence to | 1146 // which are non-configurable. It therefore makes no sence to |
| 1147 // try to redefine these as defined by the spec. The spec says | 1147 // try to redefine these as defined by the spec. The spec says |
| 1148 // that bind should make these throw a TypeError if get or set | 1148 // that bind should make these throw a TypeError if get or set |
| 1149 // is called and make them non-enumerable and non-configurable. | 1149 // is called and make them non-enumerable and non-configurable. |
| 1150 // To be consistent with our normal functions we leave this as it is. | 1150 // To be consistent with our normal functions we leave this as it is. |
| 1151 | 1151 |
| 1152 // Set the correct length. | 1152 // Set the correct length. |
| 1153 var length = (this.length - argc_bound) > 0 ? this.length - argc_bound : 0; | 1153 var length = (this.length - argc_bound) > 0 ? this.length - argc_bound : 0; |
| 1154 %FunctionSetLength(result, length); | 1154 %FunctionSetLength(result, length); |
| 1155 | 1155 |
| 1156 return result; | 1156 return result; |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 | 1159 |
| 1160 function NewFunction(arg1) { // length == 1 | 1160 function NewFunction(arg1) { // length == 1 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1187 // ---------------------------------------------------------------------------- | 1187 // ---------------------------------------------------------------------------- |
| 1188 | 1188 |
| 1189 function SetupFunction() { | 1189 function SetupFunction() { |
| 1190 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1190 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1191 "bind", FunctionBind, | 1191 "bind", FunctionBind, |
| 1192 "toString", FunctionToString | 1192 "toString", FunctionToString |
| 1193 )); | 1193 )); |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 SetupFunction(); | 1196 SetupFunction(); |
| OLD | NEW |