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

Side by Side Diff: src/runtime.cc

Issue 7230047: Remove the fcontext field from all contexts. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) { 1229 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) {
1230 HandleScope scope(isolate); 1230 HandleScope scope(isolate);
1231 ASSERT(args.length() == 4); 1231 ASSERT(args.length() == 4);
1232 1232
1233 CONVERT_ARG_CHECKED(Context, context, 0); 1233 CONVERT_ARG_CHECKED(Context, context, 0);
1234 Handle<String> name(String::cast(args[1])); 1234 Handle<String> name(String::cast(args[1]));
1235 PropertyAttributes mode = static_cast<PropertyAttributes>(args.smi_at(2)); 1235 PropertyAttributes mode = static_cast<PropertyAttributes>(args.smi_at(2));
1236 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE); 1236 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE);
1237 Handle<Object> initial_value(args[3], isolate); 1237 Handle<Object> initial_value(args[3], isolate);
1238 1238
1239 // Declarations are always done in the function context. 1239 // Declarations are always done in a function or global context.
1240 context = Handle<Context>(context->fcontext()); 1240 context = Handle<Context>(context->declaration_context());
1241 ASSERT(context->IsFunctionContext() || context->IsGlobalContext());
1242 1241
1243 int index; 1242 int index;
1244 PropertyAttributes attributes; 1243 PropertyAttributes attributes;
1245 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; 1244 ContextLookupFlags flags = DONT_FOLLOW_CHAINS;
1246 Handle<Object> holder = 1245 Handle<Object> holder =
1247 context->Lookup(name, flags, &index, &attributes); 1246 context->Lookup(name, flags, &index, &attributes);
1248 1247
1249 if (attributes != ABSENT) { 1248 if (attributes != ABSENT) {
1250 // The name was declared before; check for conflicting 1249 // The name was declared before; check for conflicting
1251 // re-declarations: This is similar to the code in parser.cc in 1250 // re-declarations: This is similar to the code in parser.cc in
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 1517
1519 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstContextSlot) { 1518 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstContextSlot) {
1520 HandleScope scope(isolate); 1519 HandleScope scope(isolate);
1521 ASSERT(args.length() == 3); 1520 ASSERT(args.length() == 3);
1522 1521
1523 Handle<Object> value(args[0], isolate); 1522 Handle<Object> value(args[0], isolate);
1524 ASSERT(!value->IsTheHole()); 1523 ASSERT(!value->IsTheHole());
1525 CONVERT_ARG_CHECKED(Context, context, 1); 1524 CONVERT_ARG_CHECKED(Context, context, 1);
1526 Handle<String> name(String::cast(args[2])); 1525 Handle<String> name(String::cast(args[2]));
1527 1526
1528 // Initializations are always done in the function context. 1527 // Initializations are always done in a function or global context.
1529 context = Handle<Context>(context->fcontext()); 1528 context = Handle<Context>(context->declaration_context());
1530 1529
1531 int index; 1530 int index;
1532 PropertyAttributes attributes; 1531 PropertyAttributes attributes;
1533 ContextLookupFlags flags = FOLLOW_CHAINS; 1532 ContextLookupFlags flags = FOLLOW_CHAINS;
1534 Handle<Object> holder = 1533 Handle<Object> holder =
1535 context->Lookup(name, flags, &index, &attributes); 1534 context->Lookup(name, flags, &index, &attributes);
1536 1535
1537 // In most situations, the property introduced by the const 1536 // In most situations, the property introduced by the const
1538 // declaration should be present in the context extension object. 1537 // declaration should be present in the context extension object.
1539 // However, because declaration and initialization are separate, the 1538 // However, because declaration and initialization are separate, the
1540 // property might have been deleted (if it was introduced by eval) 1539 // property might have been deleted (if it was introduced by eval)
1541 // before we reach the initialization point. 1540 // before we reach the initialization point.
1542 // 1541 //
1543 // Example: 1542 // Example:
1544 // 1543 //
1545 // function f() { eval("delete x; const x;"); } 1544 // function f() { eval("delete x; const x;"); }
1546 // 1545 //
1547 // In that case, the initialization behaves like a normal assignment 1546 // In that case, the initialization behaves like a normal assignment
1548 // to property 'x'. 1547 // to property 'x'.
1549 if (index >= 0) { 1548 if (index >= 0) {
1550 // Property was found in a context.
1551 if (holder->IsContext()) { 1549 if (holder->IsContext()) {
1552 // The holder cannot be the function context. If it is, there 1550 // Property was found in a context. Perform the assignment if we
1553 // should have been a const redeclaration error when declaring 1551 // found some non-constant or an uninitialized constant.
1554 // the const property. 1552 Handle<Context> context = Handle<Context>::cast(holder);
1555 ASSERT(!holder.is_identical_to(context)); 1553 if ((attributes & READ_ONLY) == 0 || context->get(index)->IsTheHole()) {
1556 if ((attributes & READ_ONLY) == 0) { 1554 context->set(index, *value);
1557 Handle<Context>::cast(holder)->set(index, *value);
1558 } 1555 }
1559 } else { 1556 } else {
1560 // The holder is an arguments object. 1557 // The holder is an arguments object.
1561 ASSERT((attributes & READ_ONLY) == 0); 1558 ASSERT((attributes & READ_ONLY) == 0);
1562 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); 1559 Handle<JSObject> arguments(Handle<JSObject>::cast(holder));
1563 RETURN_IF_EMPTY_HANDLE( 1560 RETURN_IF_EMPTY_HANDLE(
1564 isolate, 1561 isolate,
1565 SetElement(arguments, index, value, kNonStrictMode)); 1562 SetElement(arguments, index, value, kNonStrictMode));
1566 } 1563 }
1567 return *value; 1564 return *value;
(...skipping 8411 matching lines...) Expand 10 before | Expand all | Expand 10 after
9979 it.frame()->LookupCode()->SourcePosition(it.frame()->pc()); 9976 it.frame()->LookupCode()->SourcePosition(it.frame()->pc());
9980 9977
9981 // Check for constructor frame. 9978 // Check for constructor frame.
9982 bool constructor = it.frame()->IsConstructor(); 9979 bool constructor = it.frame()->IsConstructor();
9983 9980
9984 // Get scope info and read from it for local variable information. 9981 // Get scope info and read from it for local variable information.
9985 Handle<JSFunction> function(JSFunction::cast(it.frame()->function())); 9982 Handle<JSFunction> function(JSFunction::cast(it.frame()->function()));
9986 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); 9983 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info());
9987 ScopeInfo<> info(*scope_info); 9984 ScopeInfo<> info(*scope_info);
9988 9985
9989 // Get the nearest enclosing function context.
9990 Handle<Context> context(Context::cast(it.frame()->context())->fcontext());
9991
9992 // Get the locals names and values into a temporary array. 9986 // Get the locals names and values into a temporary array.
9993 // 9987 //
9994 // TODO(1240907): Hide compiler-introduced stack variables 9988 // TODO(1240907): Hide compiler-introduced stack variables
9995 // (e.g. .result)? For users of the debugger, they will probably be 9989 // (e.g. .result)? For users of the debugger, they will probably be
9996 // confusing. 9990 // confusing.
9997 Handle<FixedArray> locals = 9991 Handle<FixedArray> locals =
9998 isolate->factory()->NewFixedArray(info.NumberOfLocals() * 2); 9992 isolate->factory()->NewFixedArray(info.NumberOfLocals() * 2);
9999 9993
10000 // Fill in the names of the locals.
10001 for (int i = 0; i < info.NumberOfLocals(); i++) {
10002 locals->set(i * 2, *info.LocalName(i));
10003 }
10004
10005 // Fill in the values of the locals. 9994 // Fill in the values of the locals.
10006 if (is_optimized_frame) { 9995 if (is_optimized_frame) {
10007 // If we are inspecting an optimized frame use undefined as the 9996 // If we are inspecting an optimized frame use undefined as the
10008 // value for all locals. 9997 // value for all locals.
10009 // 9998 //
10010 // TODO(1140): We should be able to get the correct values 9999 // TODO(1140): We should be able to get the correct values
10011 // for locals in optimized frames. 10000 // for locals in optimized frames.
10012 for (int i = 0; i < info.NumberOfLocals(); i++) { 10001 for (int i = 0; i < info.NumberOfLocals(); i++) {
10002 locals->set(i * 2, *info.LocalName(i));
10013 locals->set(i * 2 + 1, isolate->heap()->undefined_value()); 10003 locals->set(i * 2 + 1, isolate->heap()->undefined_value());
10014 } 10004 }
10015 } else { 10005 } else {
10016 for (int i = 0; i < info.number_of_stack_slots(); i++) { 10006 int i = 0;
10017 // Get the value from the stack. 10007 while (i < info.number_of_stack_slots()) {
10008 // Use the value from the stack.
10009 locals->set(i * 2, *info.LocalName(i));
10018 locals->set(i * 2 + 1, it.frame()->GetExpression(i)); 10010 locals->set(i * 2 + 1, it.frame()->GetExpression(i));
10011 ++i;
10019 } 10012 }
10020 for (int i = info.number_of_stack_slots(); i < info.NumberOfLocals(); i++) { 10013 if (i < info.NumberOfLocals()) {
10021 Handle<String> name = info.LocalName(i); 10014 // Get the function containing declarations.
10022 locals->set(i * 2 + 1, 10015 Handle<Context> context(
10023 context->get(scope_info->ContextSlotIndex(*name, NULL))); 10016 Context::cast(it.frame()->context())->declaration_context());
10017 do {
10018 Handle<String> name = info.LocalName(i);
10019 locals->set(i * 2, *name);
10020 locals->set(i * 2 + 1,
10021 context->get(scope_info->ContextSlotIndex(*name, NULL)));
10022 } while (++i < info.NumberOfLocals());
10024 } 10023 }
10025 } 10024 }
10026 10025
10027 // Check whether this frame is positioned at return. If not top 10026 // Check whether this frame is positioned at return. If not top
10028 // frame or if the frame is optimized it cannot be at a return. 10027 // frame or if the frame is optimized it cannot be at a return.
10029 bool at_return = false; 10028 bool at_return = false;
10030 if (!is_optimized_frame && index == 0) { 10029 if (!is_optimized_frame && index == 0) {
10031 at_return = isolate->debug()->IsBreakAtReturn(it.frame()); 10030 at_return = isolate->debug()->IsBreakAtReturn(it.frame());
10032 } 10031 }
10033 10032
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
10232 SetProperty(local_scope, 10231 SetProperty(local_scope,
10233 scope_info.stack_slot_name(i), 10232 scope_info.stack_slot_name(i),
10234 Handle<Object>(frame->GetExpression(i), isolate), 10233 Handle<Object>(frame->GetExpression(i), isolate),
10235 NONE, 10234 NONE,
10236 kNonStrictMode), 10235 kNonStrictMode),
10237 Handle<JSObject>()); 10236 Handle<JSObject>());
10238 } 10237 }
10239 10238
10240 // Third fill all context locals. 10239 // Third fill all context locals.
10241 Handle<Context> frame_context(Context::cast(frame->context())); 10240 Handle<Context> frame_context(Context::cast(frame->context()));
10242 Handle<Context> function_context(frame_context->fcontext()); 10241 Handle<Context> function_context(frame_context->declaration_context());
10243 if (!CopyContextLocalsToScopeObject(isolate, 10242 if (!CopyContextLocalsToScopeObject(isolate,
10244 serialized_scope_info, scope_info, 10243 serialized_scope_info, scope_info,
10245 function_context, local_scope)) { 10244 function_context, local_scope)) {
10246 return Handle<JSObject>(); 10245 return Handle<JSObject>();
10247 } 10246 }
10248 10247
10249 // Finally copy any properties from the function context extension. This will 10248 // Finally copy any properties from the function context extension. This will
10250 // be variables introduced by eval. 10249 // be variables introduced by eval.
10251 if (function_context->closure() == *function) { 10250 if (function_context->closure() == *function) {
10252 if (function_context->has_extension() && 10251 if (function_context->has_extension() &&
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
11114 RETURN_IF_EMPTY_HANDLE(isolate, local_scope); 11113 RETURN_IF_EMPTY_HANDLE(isolate, local_scope);
11115 11114
11116 // Allocate a new context for the debug evaluation and set the extension 11115 // Allocate a new context for the debug evaluation and set the extension
11117 // object build. 11116 // object build.
11118 Handle<Context> context = 11117 Handle<Context> context =
11119 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, 11118 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS,
11120 go_between); 11119 go_between);
11121 context->set_extension(*local_scope); 11120 context->set_extension(*local_scope);
11122 // Copy any with contexts present and chain them in front of this context. 11121 // Copy any with contexts present and chain them in front of this context.
11123 Handle<Context> frame_context(Context::cast(frame->context())); 11122 Handle<Context> frame_context(Context::cast(frame->context()));
11124 Handle<Context> function_context(frame_context->fcontext()); 11123 Handle<Context> function_context(frame_context->declaration_context());
11125 context = CopyWithContextChain(isolate, frame_context, context); 11124 context = CopyWithContextChain(isolate, frame_context, context);
11126 11125
11127 if (additional_context->IsJSObject()) { 11126 if (additional_context->IsJSObject()) {
11128 Handle<JSObject> extension = Handle<JSObject>::cast(additional_context); 11127 Handle<JSObject> extension = Handle<JSObject>::cast(additional_context);
11129 context = isolate->factory()->NewWithContext(context, extension); 11128 context = isolate->factory()->NewWithContext(context, extension);
11130 } 11129 }
11131 11130
11132 // Wrap the evaluation statement in a new function compiled in the newly 11131 // Wrap the evaluation statement in a new function compiled in the newly
11133 // created context. The function has one parameter which has to be called 11132 // created context. The function has one parameter which has to be called
11134 // 'arguments'. This it to have access to what would have been 'arguments' in 11133 // 'arguments'. This it to have access to what would have been 'arguments' in
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
12481 } else { 12480 } else {
12482 // Handle last resort GC and make sure to allow future allocations 12481 // Handle last resort GC and make sure to allow future allocations
12483 // to grow the heap without causing GCs (if possible). 12482 // to grow the heap without causing GCs (if possible).
12484 isolate->counters()->gc_last_resort_from_js()->Increment(); 12483 isolate->counters()->gc_last_resort_from_js()->Increment();
12485 isolate->heap()->CollectAllGarbage(false); 12484 isolate->heap()->CollectAllGarbage(false);
12486 } 12485 }
12487 } 12486 }
12488 12487
12489 12488
12490 } } // namespace v8::internal 12489 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698