| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // and store it in a LanguageMode variable with the given name. | 130 // and store it in a LanguageMode variable with the given name. |
| 131 #define CONVERT_LANGUAGE_MODE_ARG(name, index) \ | 131 #define CONVERT_LANGUAGE_MODE_ARG(name, index) \ |
| 132 ASSERT(args[index]->IsSmi()); \ | 132 ASSERT(args[index]->IsSmi()); \ |
| 133 ASSERT(args.smi_at(index) == CLASSIC_MODE || \ | 133 ASSERT(args.smi_at(index) == CLASSIC_MODE || \ |
| 134 args.smi_at(index) == STRICT_MODE || \ | 134 args.smi_at(index) == STRICT_MODE || \ |
| 135 args.smi_at(index) == EXTENDED_MODE); \ | 135 args.smi_at(index) == EXTENDED_MODE); \ |
| 136 LanguageMode name = \ | 136 LanguageMode name = \ |
| 137 static_cast<LanguageMode>(args.smi_at(index)); | 137 static_cast<LanguageMode>(args.smi_at(index)); |
| 138 | 138 |
| 139 | 139 |
| 140 MUST_USE_RESULT static MaybeObject* DeepCopyBoilerplate(Isolate* isolate, | 140 MUST_USE_RESULT static MaybeObject* DeepCopyBoilerplateInternal( |
| 141 JSObject* boilerplate) { | 141 Isolate* isolate, |
| 142 JSObject* boilerplate) { |
| 142 StackLimitCheck check(isolate); | 143 StackLimitCheck check(isolate); |
| 143 if (check.HasOverflowed()) return isolate->StackOverflow(); | 144 if (check.HasOverflowed()) return isolate->StackOverflow(); |
| 144 | 145 |
| 145 Heap* heap = isolate->heap(); | 146 Heap* heap = isolate->heap(); |
| 146 Object* result; | 147 Object* result; |
| 147 { MaybeObject* maybe_result = heap->CopyJSObject(boilerplate); | 148 { MaybeObject* maybe_result = heap->CopyJSObject(boilerplate); |
| 148 if (!maybe_result->ToObject(&result)) return maybe_result; | 149 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 149 } | 150 } |
| 150 JSObject* copy = JSObject::cast(result); | 151 JSObject* copy = JSObject::cast(result); |
| 151 | 152 |
| 152 // Deep copy local properties. | 153 // Deep copy local properties. |
| 153 if (copy->HasFastProperties()) { | 154 if (copy->HasFastProperties()) { |
| 154 FixedArray* properties = copy->properties(); | 155 FixedArray* properties = copy->properties(); |
| 155 for (int i = 0; i < properties->length(); i++) { | 156 for (int i = 0; i < properties->length(); i++) { |
| 156 Object* value = properties->get(i); | 157 Object* value = properties->get(i); |
| 157 if (value->IsJSObject()) { | 158 if (value->IsJSObject()) { |
| 158 JSObject* js_object = JSObject::cast(value); | 159 JSObject* js_object = JSObject::cast(value); |
| 159 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, js_object); | 160 { MaybeObject* maybe_result = DeepCopyBoilerplateInternal( |
| 161 isolate, js_object); |
| 160 if (!maybe_result->ToObject(&result)) return maybe_result; | 162 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 161 } | 163 } |
| 162 properties->set(i, result); | 164 properties->set(i, result); |
| 163 } | 165 } |
| 164 } | 166 } |
| 165 int nof = copy->map()->inobject_properties(); | 167 int nof = copy->map()->inobject_properties(); |
| 166 for (int i = 0; i < nof; i++) { | 168 for (int i = 0; i < nof; i++) { |
| 167 Object* value = copy->InObjectPropertyAt(i); | 169 Object* value = copy->InObjectPropertyAt(i); |
| 168 if (value->IsJSObject()) { | 170 if (value->IsJSObject()) { |
| 169 JSObject* js_object = JSObject::cast(value); | 171 JSObject* js_object = JSObject::cast(value); |
| 170 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, js_object); | 172 { MaybeObject* maybe_result = DeepCopyBoilerplateInternal( |
| 173 isolate, js_object); |
| 171 if (!maybe_result->ToObject(&result)) return maybe_result; | 174 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 172 } | 175 } |
| 173 copy->InObjectPropertyAtPut(i, result); | 176 copy->InObjectPropertyAtPut(i, result); |
| 174 } | 177 } |
| 175 } | 178 } |
| 176 } else { | 179 } else { |
| 177 { MaybeObject* maybe_result = | 180 { MaybeObject* maybe_result = |
| 178 heap->AllocateFixedArray(copy->NumberOfLocalProperties()); | 181 heap->AllocateFixedArray(copy->NumberOfLocalProperties()); |
| 179 if (!maybe_result->ToObject(&result)) return maybe_result; | 182 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 180 } | 183 } |
| 181 FixedArray* names = FixedArray::cast(result); | 184 FixedArray* names = FixedArray::cast(result); |
| 182 copy->GetLocalPropertyNames(names, 0); | 185 copy->GetLocalPropertyNames(names, 0); |
| 183 for (int i = 0; i < names->length(); i++) { | 186 for (int i = 0; i < names->length(); i++) { |
| 184 ASSERT(names->get(i)->IsString()); | 187 ASSERT(names->get(i)->IsString()); |
| 185 String* key_string = String::cast(names->get(i)); | 188 String* key_string = String::cast(names->get(i)); |
| 186 PropertyAttributes attributes = | 189 PropertyAttributes attributes = |
| 187 copy->GetLocalPropertyAttribute(key_string); | 190 copy->GetLocalPropertyAttribute(key_string); |
| 188 // Only deep copy fields from the object literal expression. | 191 // Only deep copy fields from the object literal expression. |
| 189 // In particular, don't try to copy the length attribute of | 192 // In particular, don't try to copy the length attribute of |
| 190 // an array. | 193 // an array. |
| 191 if (attributes != NONE) continue; | 194 if (attributes != NONE) continue; |
| 192 Object* value = | 195 Object* value = |
| 193 copy->GetProperty(key_string, &attributes)->ToObjectUnchecked(); | 196 copy->GetProperty(key_string, &attributes)->ToObjectUnchecked(); |
| 194 if (value->IsJSObject()) { | 197 if (value->IsJSObject()) { |
| 195 JSObject* js_object = JSObject::cast(value); | 198 JSObject* js_object = JSObject::cast(value); |
| 196 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, js_object); | 199 { MaybeObject* maybe_result = DeepCopyBoilerplateInternal( |
| 200 isolate, js_object); |
| 197 if (!maybe_result->ToObject(&result)) return maybe_result; | 201 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 198 } | 202 } |
| 199 { MaybeObject* maybe_result = | 203 { MaybeObject* maybe_result = |
| 200 // Creating object copy for literals. No strict mode needed. | 204 // Creating object copy for literals. No strict mode needed. |
| 201 copy->SetProperty(key_string, result, NONE, kNonStrictMode); | 205 copy->SetProperty(key_string, result, NONE, kNonStrictMode); |
| 202 if (!maybe_result->ToObject(&result)) return maybe_result; | 206 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 } | 209 } |
| 206 } | 210 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 222 } | 226 } |
| 223 #endif | 227 #endif |
| 224 } else { | 228 } else { |
| 225 for (int i = 0; i < elements->length(); i++) { | 229 for (int i = 0; i < elements->length(); i++) { |
| 226 Object* value = elements->get(i); | 230 Object* value = elements->get(i); |
| 227 ASSERT(value->IsSmi() || | 231 ASSERT(value->IsSmi() || |
| 228 value->IsTheHole() || | 232 value->IsTheHole() || |
| 229 (IsFastObjectElementsKind(copy->GetElementsKind()))); | 233 (IsFastObjectElementsKind(copy->GetElementsKind()))); |
| 230 if (value->IsJSObject()) { | 234 if (value->IsJSObject()) { |
| 231 JSObject* js_object = JSObject::cast(value); | 235 JSObject* js_object = JSObject::cast(value); |
| 232 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, | 236 { MaybeObject* maybe_result = DeepCopyBoilerplateInternal(isolate, |
| 233 js_object); | 237 js_object); |
| 234 if (!maybe_result->ToObject(&result)) return maybe_result; | 238 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 235 } | 239 } |
| 236 elements->set(i, result); | 240 elements->set(i, result); |
| 237 } | 241 } |
| 238 } | 242 } |
| 239 } | 243 } |
| 240 break; | 244 break; |
| 241 } | 245 } |
| 242 case DICTIONARY_ELEMENTS: { | 246 case DICTIONARY_ELEMENTS: { |
| 243 SeededNumberDictionary* element_dictionary = copy->element_dictionary(); | 247 SeededNumberDictionary* element_dictionary = copy->element_dictionary(); |
| 244 int capacity = element_dictionary->Capacity(); | 248 int capacity = element_dictionary->Capacity(); |
| 245 for (int i = 0; i < capacity; i++) { | 249 for (int i = 0; i < capacity; i++) { |
| 246 Object* k = element_dictionary->KeyAt(i); | 250 Object* k = element_dictionary->KeyAt(i); |
| 247 if (element_dictionary->IsKey(k)) { | 251 if (element_dictionary->IsKey(k)) { |
| 248 Object* value = element_dictionary->ValueAt(i); | 252 Object* value = element_dictionary->ValueAt(i); |
| 249 if (value->IsJSObject()) { | 253 if (value->IsJSObject()) { |
| 250 JSObject* js_object = JSObject::cast(value); | 254 JSObject* js_object = JSObject::cast(value); |
| 251 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, | 255 { MaybeObject* maybe_result = DeepCopyBoilerplateInternal(isolate, |
| 252 js_object); | 256 js_object); |
| 253 if (!maybe_result->ToObject(&result)) return maybe_result; | 257 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 254 } | 258 } |
| 255 element_dictionary->ValueAtPut(i, result); | 259 element_dictionary->ValueAtPut(i, result); |
| 256 } | 260 } |
| 257 } | 261 } |
| 258 } | 262 } |
| 259 break; | 263 break; |
| 260 } | 264 } |
| 261 case NON_STRICT_ARGUMENTS_ELEMENTS: | 265 case NON_STRICT_ARGUMENTS_ELEMENTS: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 272 case EXTERNAL_DOUBLE_ELEMENTS: | 276 case EXTERNAL_DOUBLE_ELEMENTS: |
| 273 case FAST_DOUBLE_ELEMENTS: | 277 case FAST_DOUBLE_ELEMENTS: |
| 274 case FAST_HOLEY_DOUBLE_ELEMENTS: | 278 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 275 // No contained objects, nothing to do. | 279 // No contained objects, nothing to do. |
| 276 break; | 280 break; |
| 277 } | 281 } |
| 278 return copy; | 282 return copy; |
| 279 } | 283 } |
| 280 | 284 |
| 281 | 285 |
| 286 Handle<JSObject> Runtime::DeepCopyBoilerplate(Isolate* isolate, |
| 287 Handle<JSObject> boilerplate) { |
| 288 // MaybeObject* mo = DeepCopyBoilerplateInternal(isolate, *boilerplate); |
| 289 CALL_HEAP_FUNCTION(isolate, |
| 290 DeepCopyBoilerplateInternal(isolate, *boilerplate), |
| 291 JSObject); |
| 292 } |
| 293 |
| 294 |
| 282 static Handle<Map> ComputeObjectLiteralMap( | 295 static Handle<Map> ComputeObjectLiteralMap( |
| 283 Handle<Context> context, | 296 Handle<Context> context, |
| 284 Handle<FixedArray> constant_properties, | 297 Handle<FixedArray> constant_properties, |
| 285 bool* is_result_from_cache) { | 298 bool* is_result_from_cache) { |
| 286 Isolate* isolate = context->GetIsolate(); | 299 Isolate* isolate = context->GetIsolate(); |
| 287 int properties_length = constant_properties->length(); | 300 int properties_length = constant_properties->length(); |
| 288 int number_of_properties = properties_length / 2; | 301 int number_of_properties = properties_length / 2; |
| 289 // Check that there are only symbols and array indices among keys. | 302 // Check that there are only symbols and array indices among keys. |
| 290 int number_of_symbol_keys = 0; | 303 int number_of_symbol_keys = 0; |
| 291 for (int p = 0; p != properties_length; p += 2) { | 304 for (int p = 0; p != properties_length; p += 2) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 if (*boilerplate == isolate->heap()->undefined_value()) { | 602 if (*boilerplate == isolate->heap()->undefined_value()) { |
| 590 boilerplate = CreateObjectLiteralBoilerplate(isolate, | 603 boilerplate = CreateObjectLiteralBoilerplate(isolate, |
| 591 literals, | 604 literals, |
| 592 constant_properties, | 605 constant_properties, |
| 593 should_have_fast_elements, | 606 should_have_fast_elements, |
| 594 has_function_literal); | 607 has_function_literal); |
| 595 if (boilerplate.is_null()) return Failure::Exception(); | 608 if (boilerplate.is_null()) return Failure::Exception(); |
| 596 // Update the functions literal and return the boilerplate. | 609 // Update the functions literal and return the boilerplate. |
| 597 literals->set(literals_index, *boilerplate); | 610 literals->set(literals_index, *boilerplate); |
| 598 } | 611 } |
| 599 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate)); | 612 return DeepCopyBoilerplateInternal(isolate, JSObject::cast(*boilerplate)); |
| 600 } | 613 } |
| 601 | 614 |
| 602 | 615 |
| 603 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateObjectLiteralShallow) { | 616 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateObjectLiteralShallow) { |
| 604 HandleScope scope(isolate); | 617 HandleScope scope(isolate); |
| 605 ASSERT(args.length() == 4); | 618 ASSERT(args.length() == 4); |
| 606 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 619 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 607 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 620 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 608 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); | 621 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); |
| 609 CONVERT_SMI_ARG_CHECKED(flags, 3); | 622 CONVERT_SMI_ARG_CHECKED(flags, 3); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 636 // Check if boilerplate exists. If not, create it first. | 649 // Check if boilerplate exists. If not, create it first. |
| 637 Handle<Object> boilerplate(literals->get(literals_index), isolate); | 650 Handle<Object> boilerplate(literals->get(literals_index), isolate); |
| 638 if (*boilerplate == isolate->heap()->undefined_value()) { | 651 if (*boilerplate == isolate->heap()->undefined_value()) { |
| 639 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 652 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 640 boilerplate = | 653 boilerplate = |
| 641 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 654 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 642 if (boilerplate.is_null()) return Failure::Exception(); | 655 if (boilerplate.is_null()) return Failure::Exception(); |
| 643 // Update the functions literal and return the boilerplate. | 656 // Update the functions literal and return the boilerplate. |
| 644 literals->set(literals_index, *boilerplate); | 657 literals->set(literals_index, *boilerplate); |
| 645 } | 658 } |
| 646 return DeepCopyBoilerplate(isolate, JSObject::cast(*boilerplate)); | 659 return DeepCopyBoilerplateInternal(isolate, JSObject::cast(*boilerplate)); |
| 647 } | 660 } |
| 648 | 661 |
| 649 | 662 |
| 650 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { | 663 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { |
| 651 HandleScope scope(isolate); | 664 HandleScope scope(isolate); |
| 652 ASSERT(args.length() == 3); | 665 ASSERT(args.length() == 3); |
| 653 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 666 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 654 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 667 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 655 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); | 668 CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); |
| 656 | 669 |
| (...skipping 12847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13504 // Handle last resort GC and make sure to allow future allocations | 13517 // Handle last resort GC and make sure to allow future allocations |
| 13505 // to grow the heap without causing GCs (if possible). | 13518 // to grow the heap without causing GCs (if possible). |
| 13506 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13519 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13507 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13520 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13508 "Runtime::PerformGC"); | 13521 "Runtime::PerformGC"); |
| 13509 } | 13522 } |
| 13510 } | 13523 } |
| 13511 | 13524 |
| 13512 | 13525 |
| 13513 } } // namespace v8::internal | 13526 } } // namespace v8::internal |
| OLD | NEW |