| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 740 |
| 741 | 741 |
| 742 OptimizedObjectForAddingMultipleProperties:: | 742 OptimizedObjectForAddingMultipleProperties:: |
| 743 ~OptimizedObjectForAddingMultipleProperties() { | 743 ~OptimizedObjectForAddingMultipleProperties() { |
| 744 // Reoptimize the object to allow fast property access. | 744 // Reoptimize the object to allow fast property access. |
| 745 if (has_been_transformed_) { | 745 if (has_been_transformed_) { |
| 746 TransformToFastProperties(object_, unused_property_fields_); | 746 TransformToFastProperties(object_, unused_property_fields_); |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 | 749 |
| 750 | |
| 751 void LoadLazy(Handle<JSObject> obj, bool* pending_exception) { | |
| 752 HandleScope scope; | |
| 753 Handle<FixedArray> info(FixedArray::cast(obj->map()->constructor())); | |
| 754 int index = Smi::cast(info->get(0))->value(); | |
| 755 ASSERT(index >= 0); | |
| 756 Handle<Context> compile_context(Context::cast(info->get(1))); | |
| 757 Handle<Context> function_context(Context::cast(info->get(2))); | |
| 758 Handle<Object> receiver(compile_context->global()->builtins()); | |
| 759 | |
| 760 Vector<const char> name = Natives::GetScriptName(index); | |
| 761 | |
| 762 Handle<JSFunction> boilerplate; | |
| 763 | |
| 764 if (!Bootstrapper::NativesCacheLookup(name, &boilerplate)) { | |
| 765 Handle<String> source_code = Bootstrapper::NativesSourceLookup(index); | |
| 766 Handle<String> script_name = Factory::NewStringFromAscii(name); | |
| 767 bool allow_natives_syntax = FLAG_allow_natives_syntax; | |
| 768 FLAG_allow_natives_syntax = true; | |
| 769 boilerplate = Compiler::Compile(source_code, script_name, 0, 0, NULL, NULL); | |
| 770 FLAG_allow_natives_syntax = allow_natives_syntax; | |
| 771 // If the compilation failed (possibly due to stack overflows), we | |
| 772 // should never enter the result in the natives cache. Instead we | |
| 773 // return from the function without marking the function as having | |
| 774 // been lazily loaded. | |
| 775 if (boilerplate.is_null()) { | |
| 776 *pending_exception = true; | |
| 777 return; | |
| 778 } | |
| 779 Bootstrapper::NativesCacheAdd(name, boilerplate); | |
| 780 } | |
| 781 | |
| 782 // We shouldn't get here if compiling the script failed. | |
| 783 ASSERT(!boilerplate.is_null()); | |
| 784 | |
| 785 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 786 // When the debugger running in its own context touches lazy loaded | |
| 787 // functions loading can be triggered. In that case ensure that the | |
| 788 // execution of the boilerplate is in the correct context. | |
| 789 SaveContext save; | |
| 790 if (!Debug::debug_context().is_null() && | |
| 791 Top::context() == *Debug::debug_context()) { | |
| 792 Top::set_context(*compile_context); | |
| 793 } | |
| 794 #endif | |
| 795 | |
| 796 // Reset the lazy load data before running the script to make sure | |
| 797 // not to get recursive lazy loading. | |
| 798 obj->map()->set_needs_loading(false); | |
| 799 obj->map()->set_constructor(info->get(3)); | |
| 800 | |
| 801 // Run the script. | |
| 802 Handle<JSFunction> script_fun( | |
| 803 Factory::NewFunctionFromBoilerplate(boilerplate, function_context)); | |
| 804 Execution::Call(script_fun, receiver, 0, NULL, pending_exception); | |
| 805 | |
| 806 // If lazy loading failed, restore the unloaded state of obj. | |
| 807 if (*pending_exception) { | |
| 808 obj->map()->set_needs_loading(true); | |
| 809 obj->map()->set_constructor(*info); | |
| 810 } | |
| 811 } | |
| 812 | |
| 813 | |
| 814 void SetupLazy(Handle<JSObject> obj, | |
| 815 int index, | |
| 816 Handle<Context> compile_context, | |
| 817 Handle<Context> function_context) { | |
| 818 Handle<FixedArray> arr = Factory::NewFixedArray(4); | |
| 819 arr->set(0, Smi::FromInt(index)); | |
| 820 arr->set(1, *compile_context); // Compile in this context | |
| 821 arr->set(2, *function_context); // Set function context to this | |
| 822 arr->set(3, obj->map()->constructor()); // Remember the constructor | |
| 823 Handle<Map> old_map(obj->map()); | |
| 824 Handle<Map> new_map = Factory::CopyMapDropTransitions(old_map); | |
| 825 obj->set_map(*new_map); | |
| 826 new_map->set_needs_loading(true); | |
| 827 // Store the lazy loading info in the constructor field. We'll | |
| 828 // reestablish the constructor from the fixed array after loading. | |
| 829 new_map->set_constructor(*arr); | |
| 830 ASSERT(!obj->IsLoaded()); | |
| 831 } | |
| 832 | |
| 833 } } // namespace v8::internal | 750 } } // namespace v8::internal |
| OLD | NEW |