| 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 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 CONVERT_ARG_CHECKED(FixedArray, pairs, 0); | 611 CONVERT_ARG_CHECKED(FixedArray, pairs, 0); |
| 612 Handle<Context> context = args.at<Context>(1); | 612 Handle<Context> context = args.at<Context>(1); |
| 613 bool is_eval = Smi::cast(args[2])->value() == 1; | 613 bool is_eval = Smi::cast(args[2])->value() == 1; |
| 614 | 614 |
| 615 // Compute the property attributes. According to ECMA-262, section | 615 // Compute the property attributes. According to ECMA-262, section |
| 616 // 13, page 71, the property must be read-only and | 616 // 13, page 71, the property must be read-only and |
| 617 // non-deletable. However, neither SpiderMonkey nor KJS creates the | 617 // non-deletable. However, neither SpiderMonkey nor KJS creates the |
| 618 // property as read-only, so we don't either. | 618 // property as read-only, so we don't either. |
| 619 PropertyAttributes base = is_eval ? NONE : DONT_DELETE; | 619 PropertyAttributes base = is_eval ? NONE : DONT_DELETE; |
| 620 | 620 |
| 621 // Only optimize the object if we intend to add more than 5 properties. | |
| 622 OptimizedObjectForAddingMultipleProperties ba(global, pairs->length()/2 > 5); | |
| 623 | |
| 624 // Traverse the name/value pairs and set the properties. | 621 // Traverse the name/value pairs and set the properties. |
| 625 int length = pairs->length(); | 622 int length = pairs->length(); |
| 626 for (int i = 0; i < length; i += 2) { | 623 for (int i = 0; i < length; i += 2) { |
| 627 HandleScope scope; | 624 HandleScope scope; |
| 628 Handle<String> name(String::cast(pairs->get(i))); | 625 Handle<String> name(String::cast(pairs->get(i))); |
| 629 Handle<Object> value(pairs->get(i + 1)); | 626 Handle<Object> value(pairs->get(i + 1)); |
| 630 | 627 |
| 631 // We have to declare a global const property. To capture we only | 628 // We have to declare a global const property. To capture we only |
| 632 // assign to it when evaluating the assignment for "const x = | 629 // assign to it when evaluating the assignment for "const x = |
| 633 // <expr>" the initial value is the hole. | 630 // <expr>" the initial value is the hole. |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 // constant. For now, we determine this by checking if the | 922 // constant. For now, we determine this by checking if the |
| 926 // current value is the hole. | 923 // current value is the hole. |
| 927 PropertyType type = lookup.type(); | 924 PropertyType type = lookup.type(); |
| 928 if (type == FIELD) { | 925 if (type == FIELD) { |
| 929 FixedArray* properties = global->properties(); | 926 FixedArray* properties = global->properties(); |
| 930 int index = lookup.GetFieldIndex(); | 927 int index = lookup.GetFieldIndex(); |
| 931 if (properties->get(index)->IsTheHole()) { | 928 if (properties->get(index)->IsTheHole()) { |
| 932 properties->set(index, *value); | 929 properties->set(index, *value); |
| 933 } | 930 } |
| 934 } else if (type == NORMAL) { | 931 } else if (type == NORMAL) { |
| 935 Dictionary* dictionary = global->property_dictionary(); | 932 if (global->GetNormalizedProperty(&lookup)->IsTheHole()) { |
| 936 int entry = lookup.GetDictionaryEntry(); | 933 global->SetNormalizedProperty(&lookup, *value); |
| 937 if (dictionary->ValueAt(entry)->IsTheHole()) { | |
| 938 dictionary->ValueAtPut(entry, *value); | |
| 939 } | 934 } |
| 940 } else { | 935 } else { |
| 941 // Ignore re-initialization of constants that have already been | 936 // Ignore re-initialization of constants that have already been |
| 942 // assigned a function value. | 937 // assigned a function value. |
| 943 ASSERT(lookup.IsReadOnly() && type == CONSTANT_FUNCTION); | 938 ASSERT(lookup.IsReadOnly() && type == CONSTANT_FUNCTION); |
| 944 } | 939 } |
| 945 | 940 |
| 946 // Use the set value as the result of the operation. | 941 // Use the set value as the result of the operation. |
| 947 return *value; | 942 return *value; |
| 948 } | 943 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 ASSERT(lookup.IsReadOnly()); // and it was declared as read-only | 1013 ASSERT(lookup.IsReadOnly()); // and it was declared as read-only |
| 1019 | 1014 |
| 1020 PropertyType type = lookup.type(); | 1015 PropertyType type = lookup.type(); |
| 1021 if (type == FIELD) { | 1016 if (type == FIELD) { |
| 1022 FixedArray* properties = context_ext->properties(); | 1017 FixedArray* properties = context_ext->properties(); |
| 1023 int index = lookup.GetFieldIndex(); | 1018 int index = lookup.GetFieldIndex(); |
| 1024 if (properties->get(index)->IsTheHole()) { | 1019 if (properties->get(index)->IsTheHole()) { |
| 1025 properties->set(index, *value); | 1020 properties->set(index, *value); |
| 1026 } | 1021 } |
| 1027 } else if (type == NORMAL) { | 1022 } else if (type == NORMAL) { |
| 1028 Dictionary* dictionary = context_ext->property_dictionary(); | 1023 if (context_ext->GetNormalizedProperty(&lookup)->IsTheHole()) { |
| 1029 int entry = lookup.GetDictionaryEntry(); | 1024 context_ext->SetNormalizedProperty(&lookup, *value); |
| 1030 if (dictionary->ValueAt(entry)->IsTheHole()) { | |
| 1031 dictionary->ValueAtPut(entry, *value); | |
| 1032 } | 1025 } |
| 1033 } else { | 1026 } else { |
| 1034 // We should not reach here. Any real, named property should be | 1027 // We should not reach here. Any real, named property should be |
| 1035 // either a field or a dictionary slot. | 1028 // either a field or a dictionary slot. |
| 1036 UNREACHABLE(); | 1029 UNREACHABLE(); |
| 1037 } | 1030 } |
| 1038 } else { | 1031 } else { |
| 1039 // The property was found in a different context extension object. | 1032 // The property was found in a different context extension object. |
| 1040 // Set it if it is not a read-only property. | 1033 // Set it if it is not a read-only property. |
| 1041 if ((attributes & READ_ONLY) == 0) { | 1034 if ((attributes & READ_ONLY) == 0) { |
| (...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2633 if (result.IsProperty() && result.IsLoaded() && result.type() == FIELD) { | 2626 if (result.IsProperty() && result.IsLoaded() && result.type() == FIELD) { |
| 2634 int offset = result.GetFieldIndex(); | 2627 int offset = result.GetFieldIndex(); |
| 2635 KeyedLookupCache::Update(receiver_map, key, offset); | 2628 KeyedLookupCache::Update(receiver_map, key, offset); |
| 2636 Object* value = receiver->FastPropertyAt(offset); | 2629 Object* value = receiver->FastPropertyAt(offset); |
| 2637 return value->IsTheHole() ? Heap::undefined_value() : value; | 2630 return value->IsTheHole() ? Heap::undefined_value() : value; |
| 2638 } | 2631 } |
| 2639 } else { | 2632 } else { |
| 2640 // Attempt dictionary lookup. | 2633 // Attempt dictionary lookup. |
| 2641 Dictionary* dictionary = receiver->property_dictionary(); | 2634 Dictionary* dictionary = receiver->property_dictionary(); |
| 2642 int entry = dictionary->FindStringEntry(key); | 2635 int entry = dictionary->FindStringEntry(key); |
| 2643 if ((entry != DescriptorArray::kNotFound) && | 2636 if ((entry != Dictionary::kNotFound) && |
| 2644 (dictionary->DetailsAt(entry).type() == NORMAL)) { | 2637 (dictionary->DetailsAt(entry).type() == NORMAL)) { |
| 2645 return dictionary->ValueAt(entry); | 2638 Object* value = dictionary->ValueAt(entry); |
| 2639 if (receiver->IsJSGlobalObject()) { |
| 2640 value = JSGlobalPropertyCell::cast(value)->value(); |
| 2641 } |
| 2642 return value; |
| 2646 } | 2643 } |
| 2647 } | 2644 } |
| 2648 } | 2645 } |
| 2649 | 2646 |
| 2650 // Fall back to GetObjectProperty. | 2647 // Fall back to GetObjectProperty. |
| 2651 return Runtime::GetObjectProperty(args.at<Object>(0), | 2648 return Runtime::GetObjectProperty(args.at<Object>(0), |
| 2652 args.at<Object>(1)); | 2649 args.at<Object>(1)); |
| 2653 } | 2650 } |
| 2654 | 2651 |
| 2655 | 2652 |
| (...skipping 2897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5553 } | 5550 } |
| 5554 return count; | 5551 return count; |
| 5555 } | 5552 } |
| 5556 | 5553 |
| 5557 | 5554 |
| 5558 static Object* DebugLookupResultValue(Object* receiver, String* name, | 5555 static Object* DebugLookupResultValue(Object* receiver, String* name, |
| 5559 LookupResult* result, | 5556 LookupResult* result, |
| 5560 bool* caught_exception) { | 5557 bool* caught_exception) { |
| 5561 Object* value; | 5558 Object* value; |
| 5562 switch (result->type()) { | 5559 switch (result->type()) { |
| 5563 case NORMAL: { | 5560 case NORMAL: |
| 5564 Dictionary* dict = | 5561 value = result->holder()->GetNormalizedProperty(result); |
| 5565 JSObject::cast(result->holder())->property_dictionary(); | |
| 5566 value = dict->ValueAt(result->GetDictionaryEntry()); | |
| 5567 if (value->IsTheHole()) { | 5562 if (value->IsTheHole()) { |
| 5568 return Heap::undefined_value(); | 5563 return Heap::undefined_value(); |
| 5569 } | 5564 } |
| 5570 return value; | 5565 return value; |
| 5571 } | |
| 5572 case FIELD: | 5566 case FIELD: |
| 5573 value = | 5567 value = |
| 5574 JSObject::cast( | 5568 JSObject::cast( |
| 5575 result->holder())->FastPropertyAt(result->GetFieldIndex()); | 5569 result->holder())->FastPropertyAt(result->GetFieldIndex()); |
| 5576 if (value->IsTheHole()) { | 5570 if (value->IsTheHole()) { |
| 5577 return Heap::undefined_value(); | 5571 return Heap::undefined_value(); |
| 5578 } | 5572 } |
| 5579 return value; | 5573 return value; |
| 5580 case CONSTANT_FUNCTION: | 5574 case CONSTANT_FUNCTION: |
| 5581 return result->GetConstantFunction(); | 5575 return result->GetConstantFunction(); |
| (...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7500 } else { | 7494 } else { |
| 7501 // Handle last resort GC and make sure to allow future allocations | 7495 // Handle last resort GC and make sure to allow future allocations |
| 7502 // to grow the heap without causing GCs (if possible). | 7496 // to grow the heap without causing GCs (if possible). |
| 7503 Counters::gc_last_resort_from_js.Increment(); | 7497 Counters::gc_last_resort_from_js.Increment(); |
| 7504 Heap::CollectAllGarbage(); | 7498 Heap::CollectAllGarbage(); |
| 7505 } | 7499 } |
| 7506 } | 7500 } |
| 7507 | 7501 |
| 7508 | 7502 |
| 7509 } } // namespace v8::internal | 7503 } } // namespace v8::internal |
| OLD | NEW |