| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 static Object* Runtime_CloneObjectLiteralBoilerplate(Arguments args) { | 95 static Object* Runtime_CloneObjectLiteralBoilerplate(Arguments args) { |
| 96 CONVERT_CHECKED(JSObject, boilerplate, args[0]); | 96 CONVERT_CHECKED(JSObject, boilerplate, args[0]); |
| 97 return Heap::CopyJSObject(boilerplate); | 97 return Heap::CopyJSObject(boilerplate); |
| 98 } | 98 } |
| 99 | 99 |
| 100 | 100 |
| 101 static Handle<Map> ComputeObjectLiteralMap( | 101 static Handle<Map> ComputeObjectLiteralMap( |
| 102 Handle<Context> context, | 102 Handle<Context> context, |
| 103 Handle<FixedArray> constant_properties, | 103 Handle<FixedArray> constant_properties, |
| 104 bool* is_result_from_cache) { | 104 bool* is_result_from_cache) { |
| 105 int number_of_properties = constant_properties->length() / 2; |
| 105 if (FLAG_canonicalize_object_literal_maps) { | 106 if (FLAG_canonicalize_object_literal_maps) { |
| 106 // First find prefix of consecutive symbol keys. | 107 // First find prefix of consecutive symbol keys. |
| 107 int number_of_properties = constant_properties->length()/2; | |
| 108 int number_of_symbol_keys = 0; | 108 int number_of_symbol_keys = 0; |
| 109 while ((number_of_symbol_keys < number_of_properties) && | 109 while ((number_of_symbol_keys < number_of_properties) && |
| 110 (constant_properties->get(number_of_symbol_keys*2)->IsSymbol())) { | 110 (constant_properties->get(number_of_symbol_keys*2)->IsSymbol())) { |
| 111 number_of_symbol_keys++; | 111 number_of_symbol_keys++; |
| 112 } | 112 } |
| 113 // Based on the number of prefix symbols key we decide whether | 113 // Based on the number of prefix symbols key we decide whether |
| 114 // to use the map cache in the global context. | 114 // to use the map cache in the global context. |
| 115 const int kMaxKeys = 10; | 115 const int kMaxKeys = 10; |
| 116 if ((number_of_symbol_keys == number_of_properties) && | 116 if ((number_of_symbol_keys == number_of_properties) && |
| 117 (number_of_symbol_keys < kMaxKeys)) { | 117 (number_of_symbol_keys < kMaxKeys)) { |
| 118 // Create the fixed array with the key. | 118 // Create the fixed array with the key. |
| 119 Handle<FixedArray> keys = Factory::NewFixedArray(number_of_symbol_keys); | 119 Handle<FixedArray> keys = Factory::NewFixedArray(number_of_symbol_keys); |
| 120 for (int i = 0; i < number_of_symbol_keys; i++) { | 120 for (int i = 0; i < number_of_symbol_keys; i++) { |
| 121 keys->set(i, constant_properties->get(i*2)); | 121 keys->set(i, constant_properties->get(i*2)); |
| 122 } | 122 } |
| 123 *is_result_from_cache = true; | 123 *is_result_from_cache = true; |
| 124 return Factory::ObjectLiteralMapFromCache(context, keys); | 124 return Factory::ObjectLiteralMapFromCache(context, keys); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 *is_result_from_cache = false; | 127 *is_result_from_cache = false; |
| 128 return Handle<Map>(context->object_function()->initial_map()); | 128 return Factory::CopyMap( |
| 129 Handle<Map>(context->object_function()->initial_map()), |
| 130 number_of_properties); |
| 129 } | 131 } |
| 130 | 132 |
| 131 | 133 |
| 132 static Object* Runtime_CreateObjectLiteralBoilerplate(Arguments args) { | 134 static Object* Runtime_CreateObjectLiteralBoilerplate(Arguments args) { |
| 133 HandleScope scope; | 135 HandleScope scope; |
| 134 ASSERT(args.length() == 3); | 136 ASSERT(args.length() == 3); |
| 135 // Copy the arguments. | 137 // Copy the arguments. |
| 136 Handle<FixedArray> literals = args.at<FixedArray>(0); | 138 Handle<FixedArray> literals = args.at<FixedArray>(0); |
| 137 int literals_index = Smi::cast(args[1])->value(); | 139 int literals_index = Smi::cast(args[1])->value(); |
| 138 Handle<FixedArray> constant_properties = args.at<FixedArray>(2); | 140 Handle<FixedArray> constant_properties = args.at<FixedArray>(2); |
| (...skipping 5757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5896 } else { | 5898 } else { |
| 5897 // Handle last resort GC and make sure to allow future allocations | 5899 // Handle last resort GC and make sure to allow future allocations |
| 5898 // to grow the heap without causing GCs (if possible). | 5900 // to grow the heap without causing GCs (if possible). |
| 5899 Counters::gc_last_resort_from_js.Increment(); | 5901 Counters::gc_last_resort_from_js.Increment(); |
| 5900 Heap::CollectAllGarbage(); | 5902 Heap::CollectAllGarbage(); |
| 5901 } | 5903 } |
| 5902 } | 5904 } |
| 5903 | 5905 |
| 5904 | 5906 |
| 5905 } } // namespace v8::internal | 5907 } } // namespace v8::internal |
| OLD | NEW |