Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: src/runtime.cc

Issue 2918001: Move serialized scope info from Code object to SharedFunctionInfo. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/profile-generator.cc ('k') | src/scopeinfo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 1599
1600 if (!code->IsNull()) { 1600 if (!code->IsNull()) {
1601 RUNTIME_ASSERT(code->IsJSFunction()); 1601 RUNTIME_ASSERT(code->IsJSFunction());
1602 Handle<JSFunction> fun = Handle<JSFunction>::cast(code); 1602 Handle<JSFunction> fun = Handle<JSFunction>::cast(code);
1603 Handle<SharedFunctionInfo> shared(fun->shared()); 1603 Handle<SharedFunctionInfo> shared(fun->shared());
1604 SetExpectedNofProperties(target, shared->expected_nof_properties()); 1604 SetExpectedNofProperties(target, shared->expected_nof_properties());
1605 1605
1606 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { 1606 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) {
1607 return Failure::Exception(); 1607 return Failure::Exception();
1608 } 1608 }
1609 // Set the code, formal parameter count, and the length of the target 1609 // Set the code, scope info, formal parameter count,
1610 // function. 1610 // and the length of the target function.
1611 target->set_code(fun->code()); 1611 target->set_code(fun->code());
1612 target->shared()->set_scope_info(shared->scope_info());
1612 target->shared()->set_length(shared->length()); 1613 target->shared()->set_length(shared->length());
1613 target->shared()->set_formal_parameter_count( 1614 target->shared()->set_formal_parameter_count(
1614 shared->formal_parameter_count()); 1615 shared->formal_parameter_count());
1615 // Set the source code of the target function to undefined. 1616 // Set the source code of the target function to undefined.
1616 // SetCode is only used for built-in constructors like String, 1617 // SetCode is only used for built-in constructors like String,
1617 // Array, and Object, and some web code 1618 // Array, and Object, and some web code
1618 // doesn't like seeing source code for constructors. 1619 // doesn't like seeing source code for constructors.
1619 target->shared()->set_script(Heap::undefined_value()); 1620 target->shared()->set_script(Heap::undefined_value());
1620 // Clear the optimization hints related to the compiled code as these are no 1621 // Clear the optimization hints related to the compiled code as these are no
1621 // longer valid when the code is overwritten. 1622 // longer valid when the code is overwritten.
(...skipping 5239 matching lines...) Expand 10 before | Expand all | Expand 10 after
6861 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 6862 RUNTIME_ASSERT(!args[0]->IsJSFunction());
6862 return *Execution::GetConstructorDelegate(args.at<Object>(0)); 6863 return *Execution::GetConstructorDelegate(args.at<Object>(0));
6863 } 6864 }
6864 6865
6865 6866
6866 static Object* Runtime_NewContext(Arguments args) { 6867 static Object* Runtime_NewContext(Arguments args) {
6867 NoHandleAllocation ha; 6868 NoHandleAllocation ha;
6868 ASSERT(args.length() == 1); 6869 ASSERT(args.length() == 1);
6869 6870
6870 CONVERT_CHECKED(JSFunction, function, args[0]); 6871 CONVERT_CHECKED(JSFunction, function, args[0]);
6871 int length = ScopeInfo<>::NumberOfContextSlots(function->code()); 6872 int length =
6873 ScopeInfo<>::NumberOfContextSlots(function->shared()->scope_info());
6872 Object* result = Heap::AllocateFunctionContext(length, function); 6874 Object* result = Heap::AllocateFunctionContext(length, function);
6873 if (result->IsFailure()) return result; 6875 if (result->IsFailure()) return result;
6874 6876
6875 Top::set_context(Context::cast(result)); 6877 Top::set_context(Context::cast(result));
6876 6878
6877 return result; // non-failure 6879 return result; // non-failure
6878 } 6880 }
6879 6881
6880 static Object* PushContextHelper(Object* object, bool is_catch_context) { 6882 static Object* PushContextHelper(Object* object, bool is_catch_context) {
6881 // Convert the object to a proper JavaScript object. 6883 // Convert the object to a proper JavaScript object.
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
8481 8483
8482 // Get the frame id. 8484 // Get the frame id.
8483 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); 8485 Handle<Object> frame_id(WrapFrameId(it.frame()->id()));
8484 8486
8485 // Find source position. 8487 // Find source position.
8486 int position = it.frame()->code()->SourcePosition(it.frame()->pc()); 8488 int position = it.frame()->code()->SourcePosition(it.frame()->pc());
8487 8489
8488 // Check for constructor frame. 8490 // Check for constructor frame.
8489 bool constructor = it.frame()->IsConstructor(); 8491 bool constructor = it.frame()->IsConstructor();
8490 8492
8491 // Get code and read scope info from it for local variable information. 8493 // Get scope info and read from it for local variable information.
8492 Handle<Code> code(it.frame()->code()); 8494 Handle<JSFunction> function(JSFunction::cast(it.frame()->function()));
8493 ScopeInfo<> info(*code); 8495 Handle<Object> scope_info(function->shared()->scope_info());
8496 ScopeInfo<> info(*scope_info);
8494 8497
8495 // Get the context. 8498 // Get the context.
8496 Handle<Context> context(Context::cast(it.frame()->context())); 8499 Handle<Context> context(Context::cast(it.frame()->context()));
8497 8500
8498 // Get the locals names and values into a temporary array. 8501 // Get the locals names and values into a temporary array.
8499 // 8502 //
8500 // TODO(1240907): Hide compiler-introduced stack variables 8503 // TODO(1240907): Hide compiler-introduced stack variables
8501 // (e.g. .result)? For users of the debugger, they will probably be 8504 // (e.g. .result)? For users of the debugger, they will probably be
8502 // confusing. 8505 // confusing.
8503 Handle<FixedArray> locals = Factory::NewFixedArray(info.NumberOfLocals() * 2); 8506 Handle<FixedArray> locals = Factory::NewFixedArray(info.NumberOfLocals() * 2);
8504 for (int i = 0; i < info.NumberOfLocals(); i++) { 8507 for (int i = 0; i < info.NumberOfLocals(); i++) {
8505 // Name of the local. 8508 // Name of the local.
8506 locals->set(i * 2, *info.LocalName(i)); 8509 locals->set(i * 2, *info.LocalName(i));
8507 8510
8508 // Fetch the value of the local - either from the stack or from a 8511 // Fetch the value of the local - either from the stack or from a
8509 // heap-allocated context. 8512 // heap-allocated context.
8510 if (i < info.number_of_stack_slots()) { 8513 if (i < info.number_of_stack_slots()) {
8511 locals->set(i * 2 + 1, it.frame()->GetExpression(i)); 8514 locals->set(i * 2 + 1, it.frame()->GetExpression(i));
8512 } else { 8515 } else {
8513 Handle<String> name = info.LocalName(i); 8516 Handle<String> name = info.LocalName(i);
8514 // Traverse the context chain to the function context as all local 8517 // Traverse the context chain to the function context as all local
8515 // variables stored in the context will be on the function context. 8518 // variables stored in the context will be on the function context.
8516 while (!context->is_function_context()) { 8519 while (!context->is_function_context()) {
8517 context = Handle<Context>(context->previous()); 8520 context = Handle<Context>(context->previous());
8518 } 8521 }
8519 ASSERT(context->is_function_context()); 8522 ASSERT(context->is_function_context());
8520 locals->set(i * 2 + 1, 8523 locals->set(i * 2 + 1,
8521 context->get(ScopeInfo<>::ContextSlotIndex(*code, *name, 8524 context->get(ScopeInfo<>::ContextSlotIndex(*scope_info,
8525 *name,
8522 NULL))); 8526 NULL)));
8523 } 8527 }
8524 } 8528 }
8525 8529
8526 // Check whether this frame is positioned at return. 8530 // Check whether this frame is positioned at return.
8527 int at_return = (index == 0) ? Debug::IsBreakAtReturn(it.frame()) : false; 8531 int at_return = (index == 0) ? Debug::IsBreakAtReturn(it.frame()) : false;
8528 8532
8529 // If positioned just before return find the value to be returned and add it 8533 // If positioned just before return find the value to be returned and add it
8530 // to the frame information. 8534 // to the frame information.
8531 Handle<Object> return_value = Factory::undefined_value(); 8535 Handle<Object> return_value = Factory::undefined_value();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
8652 receiver = Factory::ToObject(receiver, calling_frames_global_context); 8656 receiver = Factory::ToObject(receiver, calling_frames_global_context);
8653 } 8657 }
8654 details->set(kFrameDetailsReceiverIndex, *receiver); 8658 details->set(kFrameDetailsReceiverIndex, *receiver);
8655 8659
8656 ASSERT_EQ(details_size, details_index); 8660 ASSERT_EQ(details_size, details_index);
8657 return *Factory::NewJSArrayWithElements(details); 8661 return *Factory::NewJSArrayWithElements(details);
8658 } 8662 }
8659 8663
8660 8664
8661 // Copy all the context locals into an object used to materialize a scope. 8665 // Copy all the context locals into an object used to materialize a scope.
8662 static void CopyContextLocalsToScopeObject(Handle<Code> code, 8666 static void CopyContextLocalsToScopeObject(Handle<SharedFunctionInfo> shared,
8663 ScopeInfo<>& scope_info, 8667 ScopeInfo<>& scope_info,
8664 Handle<Context> context, 8668 Handle<Context> context,
8665 Handle<JSObject> scope_object) { 8669 Handle<JSObject> scope_object) {
8666 // Fill all context locals to the context extension. 8670 // Fill all context locals to the context extension.
8667 for (int i = Context::MIN_CONTEXT_SLOTS; 8671 for (int i = Context::MIN_CONTEXT_SLOTS;
8668 i < scope_info.number_of_context_slots(); 8672 i < scope_info.number_of_context_slots();
8669 i++) { 8673 i++) {
8670 int context_index = 8674 int context_index =
8671 ScopeInfo<>::ContextSlotIndex(*code, 8675 ScopeInfo<>::ContextSlotIndex(shared->scope_info(),
8672 *scope_info.context_slot_name(i), 8676 *scope_info.context_slot_name(i),
8673 NULL); 8677 NULL);
8674 8678
8675 // Don't include the arguments shadow (.arguments) context variable. 8679 // Don't include the arguments shadow (.arguments) context variable.
8676 if (*scope_info.context_slot_name(i) != Heap::arguments_shadow_symbol()) { 8680 if (*scope_info.context_slot_name(i) != Heap::arguments_shadow_symbol()) {
8677 SetProperty(scope_object, 8681 SetProperty(scope_object,
8678 scope_info.context_slot_name(i), 8682 scope_info.context_slot_name(i),
8679 Handle<Object>(context->get(context_index)), NONE); 8683 Handle<Object>(context->get(context_index)), NONE);
8680 } 8684 }
8681 } 8685 }
8682 } 8686 }
8683 8687
8684 8688
8685 // Create a plain JSObject which materializes the local scope for the specified 8689 // Create a plain JSObject which materializes the local scope for the specified
8686 // frame. 8690 // frame.
8687 static Handle<JSObject> MaterializeLocalScope(JavaScriptFrame* frame) { 8691 static Handle<JSObject> MaterializeLocalScope(JavaScriptFrame* frame) {
8688 Handle<JSFunction> function(JSFunction::cast(frame->function())); 8692 Handle<JSFunction> function(JSFunction::cast(frame->function()));
8689 Handle<Code> code(function->code()); 8693 Handle<SharedFunctionInfo> shared(function->shared());
8690 ScopeInfo<> scope_info(*code); 8694 ScopeInfo<> scope_info(shared->scope_info());
8691 8695
8692 // Allocate and initialize a JSObject with all the arguments, stack locals 8696 // Allocate and initialize a JSObject with all the arguments, stack locals
8693 // heap locals and extension properties of the debugged function. 8697 // heap locals and extension properties of the debugged function.
8694 Handle<JSObject> local_scope = Factory::NewJSObject(Top::object_function()); 8698 Handle<JSObject> local_scope = Factory::NewJSObject(Top::object_function());
8695 8699
8696 // First fill all parameters. 8700 // First fill all parameters.
8697 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { 8701 for (int i = 0; i < scope_info.number_of_parameters(); ++i) {
8698 SetProperty(local_scope, 8702 SetProperty(local_scope,
8699 scope_info.parameter_name(i), 8703 scope_info.parameter_name(i),
8700 Handle<Object>(frame->GetParameter(i)), NONE); 8704 Handle<Object>(frame->GetParameter(i)), NONE);
8701 } 8705 }
8702 8706
8703 // Second fill all stack locals. 8707 // Second fill all stack locals.
8704 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) { 8708 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) {
8705 SetProperty(local_scope, 8709 SetProperty(local_scope,
8706 scope_info.stack_slot_name(i), 8710 scope_info.stack_slot_name(i),
8707 Handle<Object>(frame->GetExpression(i)), NONE); 8711 Handle<Object>(frame->GetExpression(i)), NONE);
8708 } 8712 }
8709 8713
8710 // Third fill all context locals. 8714 // Third fill all context locals.
8711 Handle<Context> frame_context(Context::cast(frame->context())); 8715 Handle<Context> frame_context(Context::cast(frame->context()));
8712 Handle<Context> function_context(frame_context->fcontext()); 8716 Handle<Context> function_context(frame_context->fcontext());
8713 CopyContextLocalsToScopeObject(code, scope_info, 8717 CopyContextLocalsToScopeObject(shared, scope_info,
8714 function_context, local_scope); 8718 function_context, local_scope);
8715 8719
8716 // Finally copy any properties from the function context extension. This will 8720 // Finally copy any properties from the function context extension. This will
8717 // be variables introduced by eval. 8721 // be variables introduced by eval.
8718 if (function_context->closure() == *function) { 8722 if (function_context->closure() == *function) {
8719 if (function_context->has_extension() && 8723 if (function_context->has_extension() &&
8720 !function_context->IsGlobalContext()) { 8724 !function_context->IsGlobalContext()) {
8721 Handle<JSObject> ext(JSObject::cast(function_context->extension())); 8725 Handle<JSObject> ext(JSObject::cast(function_context->extension()));
8722 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); 8726 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS);
8723 for (int i = 0; i < keys->length(); i++) { 8727 for (int i = 0; i < keys->length(); i++) {
8724 // Names of variables introduced by eval are strings. 8728 // Names of variables introduced by eval are strings.
8725 ASSERT(keys->get(i)->IsString()); 8729 ASSERT(keys->get(i)->IsString());
8726 Handle<String> key(String::cast(keys->get(i))); 8730 Handle<String> key(String::cast(keys->get(i)));
8727 SetProperty(local_scope, key, GetProperty(ext, key), NONE); 8731 SetProperty(local_scope, key, GetProperty(ext, key), NONE);
8728 } 8732 }
8729 } 8733 }
8730 } 8734 }
8731 return local_scope; 8735 return local_scope;
8732 } 8736 }
8733 8737
8734 8738
8735 // Create a plain JSObject which materializes the closure content for the 8739 // Create a plain JSObject which materializes the closure content for the
8736 // context. 8740 // context.
8737 static Handle<JSObject> MaterializeClosure(Handle<Context> context) { 8741 static Handle<JSObject> MaterializeClosure(Handle<Context> context) {
8738 ASSERT(context->is_function_context()); 8742 ASSERT(context->is_function_context());
8739 8743
8740 Handle<Code> code(context->closure()->code()); 8744 Handle<SharedFunctionInfo> shared(context->closure()->shared());
8741 ScopeInfo<> scope_info(*code); 8745 ScopeInfo<> scope_info(shared->scope_info());
8742 8746
8743 // Allocate and initialize a JSObject with all the content of theis function 8747 // Allocate and initialize a JSObject with all the content of theis function
8744 // closure. 8748 // closure.
8745 Handle<JSObject> closure_scope = Factory::NewJSObject(Top::object_function()); 8749 Handle<JSObject> closure_scope = Factory::NewJSObject(Top::object_function());
8746 8750
8747 // Check whether the arguments shadow object exists. 8751 // Check whether the arguments shadow object exists.
8748 int arguments_shadow_index = 8752 int arguments_shadow_index =
8749 ScopeInfo<>::ContextSlotIndex(*code, 8753 ScopeInfo<>::ContextSlotIndex(shared->scope_info(),
8750 Heap::arguments_shadow_symbol(), 8754 Heap::arguments_shadow_symbol(),
8751 NULL); 8755 NULL);
8752 if (arguments_shadow_index >= 0) { 8756 if (arguments_shadow_index >= 0) {
8753 // In this case all the arguments are available in the arguments shadow 8757 // In this case all the arguments are available in the arguments shadow
8754 // object. 8758 // object.
8755 Handle<JSObject> arguments_shadow( 8759 Handle<JSObject> arguments_shadow(
8756 JSObject::cast(context->get(arguments_shadow_index))); 8760 JSObject::cast(context->get(arguments_shadow_index)));
8757 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { 8761 for (int i = 0; i < scope_info.number_of_parameters(); ++i) {
8758 SetProperty(closure_scope, 8762 SetProperty(closure_scope,
8759 scope_info.parameter_name(i), 8763 scope_info.parameter_name(i),
8760 Handle<Object>(arguments_shadow->GetElement(i)), NONE); 8764 Handle<Object>(arguments_shadow->GetElement(i)), NONE);
8761 } 8765 }
8762 } 8766 }
8763 8767
8764 // Fill all context locals to the context extension. 8768 // Fill all context locals to the context extension.
8765 CopyContextLocalsToScopeObject(code, scope_info, context, closure_scope); 8769 CopyContextLocalsToScopeObject(shared, scope_info, context, closure_scope);
8766 8770
8767 // Finally copy any properties from the function context extension. This will 8771 // Finally copy any properties from the function context extension. This will
8768 // be variables introduced by eval. 8772 // be variables introduced by eval.
8769 if (context->has_extension()) { 8773 if (context->has_extension()) {
8770 Handle<JSObject> ext(JSObject::cast(context->extension())); 8774 Handle<JSObject> ext(JSObject::cast(context->extension()));
8771 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); 8775 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS);
8772 for (int i = 0; i < keys->length(); i++) { 8776 for (int i = 0; i < keys->length(); i++) {
8773 // Names of variables introduced by eval are strings. 8777 // Names of variables introduced by eval are strings.
8774 ASSERT(keys->get(i)->IsString()); 8778 ASSERT(keys->get(i)->IsString());
8775 Handle<String> key(String::cast(keys->get(i))); 8779 Handle<String> key(String::cast(keys->get(i)));
(...skipping 28 matching lines...) Expand all
8804 context_(Context::cast(frame->context())), 8808 context_(Context::cast(frame->context())),
8805 local_done_(false), 8809 local_done_(false),
8806 at_local_(false) { 8810 at_local_(false) {
8807 8811
8808 // Check whether the first scope is actually a local scope. 8812 // Check whether the first scope is actually a local scope.
8809 if (context_->IsGlobalContext()) { 8813 if (context_->IsGlobalContext()) {
8810 // If there is a stack slot for .result then this local scope has been 8814 // If there is a stack slot for .result then this local scope has been
8811 // created for evaluating top level code and it is not a real local scope. 8815 // created for evaluating top level code and it is not a real local scope.
8812 // Checking for the existence of .result seems fragile, but the scope info 8816 // Checking for the existence of .result seems fragile, but the scope info
8813 // saved with the code object does not otherwise have that information. 8817 // saved with the code object does not otherwise have that information.
8814 Handle<Code> code(function_->code()); 8818 int index = ScopeInfo<>::StackSlotIndex(function_->shared()->scope_info(),
8815 int index = ScopeInfo<>::StackSlotIndex(*code, Heap::result_symbol()); 8819 Heap::result_symbol());
8816 at_local_ = index < 0; 8820 at_local_ = index < 0;
8817 } else if (context_->is_function_context()) { 8821 } else if (context_->is_function_context()) {
8818 at_local_ = true; 8822 at_local_ = true;
8819 } 8823 }
8820 } 8824 }
8821 8825
8822 // More scopes? 8826 // More scopes?
8823 bool Done() { return context_.is_null(); } 8827 bool Done() { return context_.is_null(); }
8824 8828
8825 // Move to the next scope. 8829 // Move to the next scope.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
8919 // Debug print of the content of the current scope. 8923 // Debug print of the content of the current scope.
8920 void DebugPrint() { 8924 void DebugPrint() {
8921 switch (Type()) { 8925 switch (Type()) {
8922 case ScopeIterator::ScopeTypeGlobal: 8926 case ScopeIterator::ScopeTypeGlobal:
8923 PrintF("Global:\n"); 8927 PrintF("Global:\n");
8924 CurrentContext()->Print(); 8928 CurrentContext()->Print();
8925 break; 8929 break;
8926 8930
8927 case ScopeIterator::ScopeTypeLocal: { 8931 case ScopeIterator::ScopeTypeLocal: {
8928 PrintF("Local:\n"); 8932 PrintF("Local:\n");
8929 Handle<Code> code(function_->code()); 8933 ScopeInfo<> scope_info(function_->shared()->scope_info());
8930 ScopeInfo<> scope_info(*code);
8931 scope_info.Print(); 8934 scope_info.Print();
8932 if (!CurrentContext().is_null()) { 8935 if (!CurrentContext().is_null()) {
8933 CurrentContext()->Print(); 8936 CurrentContext()->Print();
8934 if (CurrentContext()->has_extension()) { 8937 if (CurrentContext()->has_extension()) {
8935 Handle<JSObject> extension = 8938 Handle<JSObject> extension =
8936 Handle<JSObject>(CurrentContext()->extension()); 8939 Handle<JSObject>(CurrentContext()->extension());
8937 if (extension->IsJSContextExtensionObject()) { 8940 if (extension->IsJSContextExtensionObject()) {
8938 extension->Print(); 8941 extension->Print();
8939 } 8942 }
8940 } 8943 }
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
9444 CopyWithContextChain(function_context, previous), 9447 CopyWithContextChain(function_context, previous),
9445 extension, 9448 extension,
9446 context_chain->IsCatchContext()); 9449 context_chain->IsCatchContext());
9447 } 9450 }
9448 9451
9449 9452
9450 // Helper function to find or create the arguments object for 9453 // Helper function to find or create the arguments object for
9451 // Runtime_DebugEvaluate. 9454 // Runtime_DebugEvaluate.
9452 static Handle<Object> GetArgumentsObject(JavaScriptFrame* frame, 9455 static Handle<Object> GetArgumentsObject(JavaScriptFrame* frame,
9453 Handle<JSFunction> function, 9456 Handle<JSFunction> function,
9454 Handle<Code> code, 9457 Handle<Object> scope_info,
9455 const ScopeInfo<>* sinfo, 9458 const ScopeInfo<>* sinfo,
9456 Handle<Context> function_context) { 9459 Handle<Context> function_context) {
9457 // Try to find the value of 'arguments' to pass as parameter. If it is not 9460 // Try to find the value of 'arguments' to pass as parameter. If it is not
9458 // found (that is the debugged function does not reference 'arguments' and 9461 // found (that is the debugged function does not reference 'arguments' and
9459 // does not support eval) then create an 'arguments' object. 9462 // does not support eval) then create an 'arguments' object.
9460 int index; 9463 int index;
9461 if (sinfo->number_of_stack_slots() > 0) { 9464 if (sinfo->number_of_stack_slots() > 0) {
9462 index = ScopeInfo<>::StackSlotIndex(*code, Heap::arguments_symbol()); 9465 index = ScopeInfo<>::StackSlotIndex(*scope_info, Heap::arguments_symbol());
9463 if (index != -1) { 9466 if (index != -1) {
9464 return Handle<Object>(frame->GetExpression(index)); 9467 return Handle<Object>(frame->GetExpression(index));
9465 } 9468 }
9466 } 9469 }
9467 9470
9468 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { 9471 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) {
9469 index = ScopeInfo<>::ContextSlotIndex(*code, Heap::arguments_symbol(), 9472 index = ScopeInfo<>::ContextSlotIndex(*scope_info, Heap::arguments_symbol(),
9470 NULL); 9473 NULL);
9471 if (index != -1) { 9474 if (index != -1) {
9472 return Handle<Object>(function_context->get(index)); 9475 return Handle<Object>(function_context->get(index));
9473 } 9476 }
9474 } 9477 }
9475 9478
9476 const int length = frame->GetProvidedParametersCount(); 9479 const int length = frame->GetProvidedParametersCount();
9477 Handle<JSObject> arguments = Factory::NewArgumentsObject(function, length); 9480 Handle<JSObject> arguments = Factory::NewArgumentsObject(function, length);
9478 Handle<FixedArray> array = Factory::NewFixedArray(length); 9481 Handle<FixedArray> array = Factory::NewFixedArray(length);
9479 9482
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
9511 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); 9514 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]);
9512 9515
9513 // Handle the processing of break. 9516 // Handle the processing of break.
9514 DisableBreak disable_break_save(disable_break); 9517 DisableBreak disable_break_save(disable_break);
9515 9518
9516 // Get the frame where the debugging is performed. 9519 // Get the frame where the debugging is performed.
9517 StackFrame::Id id = UnwrapFrameId(wrapped_id); 9520 StackFrame::Id id = UnwrapFrameId(wrapped_id);
9518 JavaScriptFrameIterator it(id); 9521 JavaScriptFrameIterator it(id);
9519 JavaScriptFrame* frame = it.frame(); 9522 JavaScriptFrame* frame = it.frame();
9520 Handle<JSFunction> function(JSFunction::cast(frame->function())); 9523 Handle<JSFunction> function(JSFunction::cast(frame->function()));
9521 Handle<Code> code(function->code()); 9524 Handle<Object> scope_info(function->shared()->scope_info());
9522 ScopeInfo<> sinfo(*code); 9525 ScopeInfo<> sinfo(*scope_info);
9523 9526
9524 // Traverse the saved contexts chain to find the active context for the 9527 // Traverse the saved contexts chain to find the active context for the
9525 // selected frame. 9528 // selected frame.
9526 SaveContext* save = Top::save_context(); 9529 SaveContext* save = Top::save_context();
9527 while (save != NULL && !save->below(frame)) { 9530 while (save != NULL && !save->below(frame)) {
9528 save = save->prev(); 9531 save = save->prev();
9529 } 9532 }
9530 ASSERT(save != NULL); 9533 ASSERT(save != NULL);
9531 SaveContext savex; 9534 SaveContext savex;
9532 Top::set_context(*(save->context())); 9535 Top::set_context(*(save->context()));
9533 9536
9534 // Create the (empty) function replacing the function on the stack frame for 9537 // Create the (empty) function replacing the function on the stack frame for
9535 // the purpose of evaluating in the context created below. It is important 9538 // the purpose of evaluating in the context created below. It is important
9536 // that this function does not describe any parameters and local variables 9539 // that this function does not describe any parameters and local variables
9537 // in the context. If it does then this will cause problems with the lookup 9540 // in the context. If it does then this will cause problems with the lookup
9538 // in Context::Lookup, where context slots for parameters and local variables 9541 // in Context::Lookup, where context slots for parameters and local variables
9539 // are looked at before the extension object. 9542 // are looked at before the extension object.
9540 Handle<JSFunction> go_between = 9543 Handle<JSFunction> go_between =
9541 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value()); 9544 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value());
9542 go_between->set_context(function->context()); 9545 go_between->set_context(function->context());
9543 #ifdef DEBUG 9546 #ifdef DEBUG
9544 ScopeInfo<> go_between_sinfo(go_between->shared()->code()); 9547 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info());
9545 ASSERT(go_between_sinfo.number_of_parameters() == 0); 9548 ASSERT(go_between_sinfo.number_of_parameters() == 0);
9546 ASSERT(go_between_sinfo.number_of_context_slots() == 0); 9549 ASSERT(go_between_sinfo.number_of_context_slots() == 0);
9547 #endif 9550 #endif
9548 9551
9549 // Materialize the content of the local scope into a JSObject. 9552 // Materialize the content of the local scope into a JSObject.
9550 Handle<JSObject> local_scope = MaterializeLocalScope(frame); 9553 Handle<JSObject> local_scope = MaterializeLocalScope(frame);
9551 9554
9552 // Allocate a new context for the debug evaluation and set the extension 9555 // Allocate a new context for the debug evaluation and set the extension
9553 // object build. 9556 // object build.
9554 Handle<Context> context = 9557 Handle<Context> context =
(...skipping 25 matching lines...) Expand all
9580 Factory::NewFunctionFromSharedFunctionInfo(shared, context); 9583 Factory::NewFunctionFromSharedFunctionInfo(shared, context);
9581 9584
9582 // Invoke the result of the compilation to get the evaluation function. 9585 // Invoke the result of the compilation to get the evaluation function.
9583 bool has_pending_exception; 9586 bool has_pending_exception;
9584 Handle<Object> receiver(frame->receiver()); 9587 Handle<Object> receiver(frame->receiver());
9585 Handle<Object> evaluation_function = 9588 Handle<Object> evaluation_function =
9586 Execution::Call(compiled_function, receiver, 0, NULL, 9589 Execution::Call(compiled_function, receiver, 0, NULL,
9587 &has_pending_exception); 9590 &has_pending_exception);
9588 if (has_pending_exception) return Failure::Exception(); 9591 if (has_pending_exception) return Failure::Exception();
9589 9592
9590 Handle<Object> arguments = GetArgumentsObject(frame, function, code, &sinfo, 9593 Handle<Object> arguments = GetArgumentsObject(frame, function, scope_info,
9591 function_context); 9594 &sinfo, function_context);
9592 9595
9593 // Invoke the evaluation function and return the result. 9596 // Invoke the evaluation function and return the result.
9594 const int argc = 2; 9597 const int argc = 2;
9595 Object** argv[argc] = { arguments.location(), 9598 Object** argv[argc] = { arguments.location(),
9596 Handle<Object>::cast(source).location() }; 9599 Handle<Object>::cast(source).location() };
9597 Handle<Object> result = 9600 Handle<Object> result =
9598 Execution::Call(Handle<JSFunction>::cast(evaluation_function), receiver, 9601 Execution::Call(Handle<JSFunction>::cast(evaluation_function), receiver,
9599 argc, argv, &has_pending_exception); 9602 argc, argv, &has_pending_exception);
9600 if (has_pending_exception) return Failure::Exception(); 9603 if (has_pending_exception) return Failure::Exception();
9601 9604
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
10544 } else { 10547 } else {
10545 // Handle last resort GC and make sure to allow future allocations 10548 // Handle last resort GC and make sure to allow future allocations
10546 // to grow the heap without causing GCs (if possible). 10549 // to grow the heap without causing GCs (if possible).
10547 Counters::gc_last_resort_from_js.Increment(); 10550 Counters::gc_last_resort_from_js.Increment();
10548 Heap::CollectAllGarbage(false); 10551 Heap::CollectAllGarbage(false);
10549 } 10552 }
10550 } 10553 }
10551 10554
10552 10555
10553 } } // namespace v8::internal 10556 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/profile-generator.cc ('k') | src/scopeinfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698