OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 4802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4813 } | 4813 } |
4814 return instance_size; | 4814 return instance_size; |
4815 } | 4815 } |
4816 | 4816 |
4817 | 4817 |
4818 int SharedFunctionInfo::CalculateInObjectProperties() { | 4818 int SharedFunctionInfo::CalculateInObjectProperties() { |
4819 return (CalculateInstanceSize() - JSObject::kHeaderSize) / kPointerSize; | 4819 return (CalculateInstanceSize() - JSObject::kHeaderSize) / kPointerSize; |
4820 } | 4820 } |
4821 | 4821 |
4822 | 4822 |
4823 bool SharedFunctionInfo::CanGenerateInlineConstructor(Object* prototype) { | |
4824 // Check the basic conditions for generating inline constructor code. | |
4825 if (!FLAG_inline_new | |
4826 || !has_only_simple_this_property_assignments() | |
4827 || !this_property_assignments_count() > 0) { | |
4828 return false; | |
4829 } | |
4830 | |
4831 // If the prototype is null inline constructors cause no problems. | |
4832 if (!prototype->IsJSObject()) { | |
4833 ASSERT(prototype->IsNull()); | |
4834 return true; | |
4835 } | |
4836 | |
4837 // Traverse the proposed prototype chain looking for setters for properties of | |
4838 // the same names as are set by the inline constructor.. | |
Mads Ager (chromium)
2010/02/18 09:19:35
.. -> .
Søren Thygesen Gjesse
2010/02/18 09:42:52
http://codereview.chromium.org/647007
| |
4839 for (Object* obj = prototype; | |
4840 obj != Heap::null_value(); | |
4841 obj = obj->GetPrototype()) { | |
4842 JSObject* js_object = JSObject::cast(obj); | |
4843 if (!js_object->HasFastProperties()) { | |
4844 // Only allow fast case objects, as the map check in the inline | |
4845 // constructor which check for changes to the prototype chain cannot | |
4846 // handle dictionary case objects. | |
4847 return false; | |
4848 } | |
4849 for (int i = 0; i < this_property_assignments_count(); i++) { | |
4850 LookupResult result; | |
4851 String* name = GetThisPropertyAssignmentName(i); | |
4852 js_object->LocalLookupRealNamedProperty(name, &result); | |
4853 if (result.IsValid() && result.type() == CALLBACKS) { | |
4854 return false; | |
4855 } | |
4856 } | |
4857 } | |
4858 | |
4859 return true; | |
4860 } | |
4861 | |
4862 | |
4823 void SharedFunctionInfo::SetThisPropertyAssignmentsInfo( | 4863 void SharedFunctionInfo::SetThisPropertyAssignmentsInfo( |
4824 bool only_simple_this_property_assignments, | 4864 bool only_simple_this_property_assignments, |
4825 FixedArray* assignments) { | 4865 FixedArray* assignments) { |
4826 set_compiler_hints(BooleanBit::set(compiler_hints(), | 4866 set_compiler_hints(BooleanBit::set(compiler_hints(), |
4827 kHasOnlySimpleThisPropertyAssignments, | 4867 kHasOnlySimpleThisPropertyAssignments, |
4828 only_simple_this_property_assignments)); | 4868 only_simple_this_property_assignments)); |
4829 set_this_property_assignments(assignments); | 4869 set_this_property_assignments(assignments); |
4830 set_this_property_assignments_count(assignments->length() / 3); | 4870 set_this_property_assignments_count(assignments->length() / 3); |
4831 } | 4871 } |
4832 | 4872 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4868 | 4908 |
4869 | 4909 |
4870 Object* SharedFunctionInfo::GetThisPropertyAssignmentConstant(int index) { | 4910 Object* SharedFunctionInfo::GetThisPropertyAssignmentConstant(int index) { |
4871 ASSERT(!IsThisPropertyAssignmentArgument(index)); | 4911 ASSERT(!IsThisPropertyAssignmentArgument(index)); |
4872 Object* obj = | 4912 Object* obj = |
4873 FixedArray::cast(this_property_assignments())->get(index * 3 + 2); | 4913 FixedArray::cast(this_property_assignments())->get(index * 3 + 2); |
4874 return obj; | 4914 return obj; |
4875 } | 4915 } |
4876 | 4916 |
4877 | 4917 |
4878 | |
4879 // Support function for printing the source code to a StringStream | 4918 // Support function for printing the source code to a StringStream |
4880 // without any allocation in the heap. | 4919 // without any allocation in the heap. |
4881 void SharedFunctionInfo::SourceCodePrint(StringStream* accumulator, | 4920 void SharedFunctionInfo::SourceCodePrint(StringStream* accumulator, |
4882 int max_length) { | 4921 int max_length) { |
4883 // For some native functions there is no source. | 4922 // For some native functions there is no source. |
4884 if (script()->IsUndefined() || | 4923 if (script()->IsUndefined() || |
4885 Script::cast(script())->source()->IsUndefined()) { | 4924 Script::cast(script())->source()->IsUndefined()) { |
4886 accumulator->Add("<No Source>"); | 4925 accumulator->Add("<No Source>"); |
4887 return; | 4926 return; |
4888 } | 4927 } |
(...skipping 2334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7223 | 7262 |
7224 if (result <= static_cast<uint32_t>(Smi::kMaxValue)) { | 7263 if (result <= static_cast<uint32_t>(Smi::kMaxValue)) { |
7225 return Smi::FromInt(static_cast<int>(result)); | 7264 return Smi::FromInt(static_cast<int>(result)); |
7226 } | 7265 } |
7227 ASSERT_NE(NULL, result_double); | 7266 ASSERT_NE(NULL, result_double); |
7228 result_double->set_value(static_cast<double>(result)); | 7267 result_double->set_value(static_cast<double>(result)); |
7229 return result_double; | 7268 return result_double; |
7230 } | 7269 } |
7231 | 7270 |
7232 | 7271 |
7233 static bool CallbacksObjectHasSetter(Object* callbacks) { | |
7234 if (!callbacks->IsFixedArray()) { | |
7235 ASSERT(callbacks->IsAccessorInfo() || callbacks->IsProxy()); | |
7236 return true; | |
7237 } else { | |
7238 Object* setter = (FixedArray::cast(callbacks))->get(kSetterIndex); | |
7239 if (setter->IsJSFunction()) { | |
7240 return true; | |
7241 } | |
7242 } | |
7243 | |
7244 return false; | |
7245 } | |
7246 | |
7247 | |
7248 bool JSObject::HasSetter() { | |
7249 for (Object* obj = this; | |
7250 obj != Heap::null_value(); | |
7251 obj = JSObject::cast(obj)->GetPrototype()) { | |
7252 JSObject* js_object = JSObject::cast(obj); | |
7253 if (js_object->HasFastProperties()) { | |
7254 DescriptorArray* descs = js_object->map()->instance_descriptors(); | |
7255 for (int i = 0; i < descs->number_of_descriptors(); i++) { | |
7256 PropertyDetails details = descs->GetDetails(i); | |
7257 if (details.type() == CALLBACKS) { | |
7258 Object* callbacks = descs->GetCallbacksObject(i); | |
7259 if (CallbacksObjectHasSetter(callbacks)) { | |
7260 return true; | |
7261 } | |
7262 } | |
7263 } | |
7264 } else { | |
7265 StringDictionary* dict = js_object->property_dictionary(); | |
7266 int capacity = dict->Capacity(); | |
7267 for (int i = 0; i < capacity; i++) { | |
7268 Object* k = dict->KeyAt(i); | |
7269 if (dict->IsKey(k)) { | |
7270 PropertyType type = dict->DetailsAt(i).type(); | |
7271 ASSERT(type != FIELD); | |
7272 if (type == CALLBACKS) { | |
7273 Object* callbacks = dict->ValueAt(i); | |
7274 if (CallbacksObjectHasSetter(callbacks)) { | |
7275 return true; | |
7276 } | |
7277 } | |
7278 } | |
7279 } | |
7280 } | |
7281 } | |
7282 | |
7283 return false; | |
7284 } | |
7285 | |
7286 | |
7287 | |
7288 Object* PixelArray::SetValue(uint32_t index, Object* value) { | 7272 Object* PixelArray::SetValue(uint32_t index, Object* value) { |
7289 uint8_t clamped_value = 0; | 7273 uint8_t clamped_value = 0; |
7290 if (index < static_cast<uint32_t>(length())) { | 7274 if (index < static_cast<uint32_t>(length())) { |
7291 if (value->IsSmi()) { | 7275 if (value->IsSmi()) { |
7292 int int_value = Smi::cast(value)->value(); | 7276 int int_value = Smi::cast(value)->value(); |
7293 if (int_value < 0) { | 7277 if (int_value < 0) { |
7294 clamped_value = 0; | 7278 clamped_value = 0; |
7295 } else if (int_value > 255) { | 7279 } else if (int_value > 255) { |
7296 clamped_value = 255; | 7280 clamped_value = 255; |
7297 } else { | 7281 } else { |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8397 if (break_point_objects()->IsUndefined()) return 0; | 8381 if (break_point_objects()->IsUndefined()) return 0; |
8398 // Single beak point. | 8382 // Single beak point. |
8399 if (!break_point_objects()->IsFixedArray()) return 1; | 8383 if (!break_point_objects()->IsFixedArray()) return 1; |
8400 // Multiple break points. | 8384 // Multiple break points. |
8401 return FixedArray::cast(break_point_objects())->length(); | 8385 return FixedArray::cast(break_point_objects())->length(); |
8402 } | 8386 } |
8403 #endif | 8387 #endif |
8404 | 8388 |
8405 | 8389 |
8406 } } // namespace v8::internal | 8390 } } // namespace v8::internal |
OLD | NEW |