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

Side by Side Diff: src/runtime.cc

Issue 7275022: Explicitly pass the closure when allocating a catch or with context. (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
« no previous file with comments | « src/runtime.h ('k') | src/x64/full-codegen-x64.cc » ('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 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 8031 matching lines...) Expand 10 before | Expand all | Expand 10 after
8042 } 8042 }
8043 8043
8044 isolate->set_context(Context::cast(result)); 8044 isolate->set_context(Context::cast(result));
8045 8045
8046 return result; // non-failure 8046 return result; // non-failure
8047 } 8047 }
8048 8048
8049 8049
8050 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushWithContext) { 8050 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushWithContext) {
8051 NoHandleAllocation ha; 8051 NoHandleAllocation ha;
8052 ASSERT(args.length() == 1); 8052 ASSERT(args.length() == 2);
8053 JSObject* extension_object; 8053 JSObject* extension_object;
8054 if (args[0]->IsJSObject()) { 8054 if (args[0]->IsJSObject()) {
8055 extension_object = JSObject::cast(args[0]); 8055 extension_object = JSObject::cast(args[0]);
8056 } else { 8056 } else {
8057 // Convert the object to a proper JavaScript object. 8057 // Convert the object to a proper JavaScript object.
8058 MaybeObject* maybe_js_object = args[0]->ToObject(); 8058 MaybeObject* maybe_js_object = args[0]->ToObject();
8059 if (!maybe_js_object->To(&extension_object)) { 8059 if (!maybe_js_object->To(&extension_object)) {
8060 if (Failure::cast(maybe_js_object)->IsInternalError()) { 8060 if (Failure::cast(maybe_js_object)->IsInternalError()) {
8061 HandleScope scope(isolate); 8061 HandleScope scope(isolate);
8062 Handle<Object> handle = args.at<Object>(0); 8062 Handle<Object> handle = args.at<Object>(0);
8063 Handle<Object> result = 8063 Handle<Object> result =
8064 isolate->factory()->NewTypeError("with_expression", 8064 isolate->factory()->NewTypeError("with_expression",
8065 HandleVector(&handle, 1)); 8065 HandleVector(&handle, 1));
8066 return isolate->Throw(*result); 8066 return isolate->Throw(*result);
8067 } else { 8067 } else {
8068 return maybe_js_object; 8068 return maybe_js_object;
8069 } 8069 }
8070 } 8070 }
8071 } 8071 }
8072 8072
8073 JSFunction* function;
8074 if (args[1]->IsSmi()) {
8075 // A smi sentinel indicates a context nested inside global code rather
8076 // than some function. There is a canonical empty function that can be
8077 // gotten from the global context.
8078 function = isolate->context()->global_context()->closure();
8079 } else {
8080 function = JSFunction::cast(args[1]);
8081 }
8082
8073 Context* context; 8083 Context* context;
8074 MaybeObject* maybe_context = 8084 MaybeObject* maybe_context =
8075 isolate->heap()->AllocateWithContext(isolate->context(), 8085 isolate->heap()->AllocateWithContext(function,
8086 isolate->context(),
8076 extension_object); 8087 extension_object);
8077 if (!maybe_context->To(&context)) return maybe_context; 8088 if (!maybe_context->To(&context)) return maybe_context;
8078 isolate->set_context(context); 8089 isolate->set_context(context);
8079 return context; 8090 return context;
8080 } 8091 }
8081 8092
8082 8093
8083 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) { 8094 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) {
8084 NoHandleAllocation ha; 8095 NoHandleAllocation ha;
8085 ASSERT(args.length() == 2); 8096 ASSERT(args.length() == 3);
8086 String* name = String::cast(args[0]); 8097 String* name = String::cast(args[0]);
8087 Object* thrown_object = args[1]; 8098 Object* thrown_object = args[1];
8099 JSFunction* function;
8100 if (args[2]->IsSmi()) {
8101 // A smi sentinel indicates a context nested inside global code rather
8102 // than some function. There is a canonical empty function that can be
8103 // gotten from the global context.
8104 function = isolate->context()->global_context()->closure();
8105 } else {
8106 function = JSFunction::cast(args[2]);
8107 }
8088 Context* context; 8108 Context* context;
8089 MaybeObject* maybe_context = 8109 MaybeObject* maybe_context =
8090 isolate->heap()->AllocateCatchContext(isolate->context(), 8110 isolate->heap()->AllocateCatchContext(function,
8111 isolate->context(),
8091 name, 8112 name,
8092 thrown_object); 8113 thrown_object);
8093 if (!maybe_context->To(&context)) return maybe_context; 8114 if (!maybe_context->To(&context)) return maybe_context;
8094 isolate->set_context(context); 8115 isolate->set_context(context);
8095 return context; 8116 return context;
8096 } 8117 }
8097 8118
8098 8119
8099 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { 8120 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) {
8100 HandleScope scope(isolate); 8121 HandleScope scope(isolate);
(...skipping 2859 matching lines...) Expand 10 before | Expand all | Expand 10 after
10960 HandleScope scope(isolate); 10981 HandleScope scope(isolate);
10961 ASSERT(args.length() == 0); 10982 ASSERT(args.length() == 0);
10962 isolate->debug()->ClearStepping(); 10983 isolate->debug()->ClearStepping();
10963 return isolate->heap()->undefined_value(); 10984 return isolate->heap()->undefined_value();
10964 } 10985 }
10965 10986
10966 10987
10967 // Creates a copy of the with context chain. The copy of the context chain is 10988 // Creates a copy of the with context chain. The copy of the context chain is
10968 // is linked to the function context supplied. 10989 // is linked to the function context supplied.
10969 static Handle<Context> CopyWithContextChain(Isolate* isolate, 10990 static Handle<Context> CopyWithContextChain(Isolate* isolate,
10991 Handle<JSFunction> function,
10970 Handle<Context> current, 10992 Handle<Context> current,
10971 Handle<Context> base) { 10993 Handle<Context> base) {
10972 // At the end of the chain. Return the base context to link to. 10994 // At the end of the chain. Return the base context to link to.
10973 if (current->IsFunctionContext() || current->IsGlobalContext()) { 10995 if (current->IsFunctionContext() || current->IsGlobalContext()) {
10974 return base; 10996 return base;
10975 } 10997 }
10976 10998
10977 // Recursively copy the with and catch contexts. 10999 // Recursively copy the with and catch contexts.
10978 HandleScope scope(isolate); 11000 HandleScope scope(isolate);
10979 Handle<Context> previous(current->previous()); 11001 Handle<Context> previous(current->previous());
10980 Handle<Context> new_previous = CopyWithContextChain(isolate, previous, base); 11002 Handle<Context> new_previous =
11003 CopyWithContextChain(isolate, function, previous, base);
10981 Handle<Context> new_current; 11004 Handle<Context> new_current;
10982 if (current->IsCatchContext()) { 11005 if (current->IsCatchContext()) {
10983 Handle<String> name(String::cast(current->extension())); 11006 Handle<String> name(String::cast(current->extension()));
10984 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX)); 11007 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX));
10985 new_current = 11008 new_current =
10986 isolate->factory()->NewCatchContext(new_previous, name, thrown_object); 11009 isolate->factory()->NewCatchContext(function,
11010 new_previous,
11011 name,
11012 thrown_object);
10987 } else { 11013 } else {
10988 Handle<JSObject> extension(JSObject::cast(current->extension())); 11014 Handle<JSObject> extension(JSObject::cast(current->extension()));
10989 new_current = 11015 new_current =
10990 isolate->factory()->NewWithContext(new_previous, extension); 11016 isolate->factory()->NewWithContext(function, new_previous, extension);
10991 } 11017 }
10992 return scope.CloseAndEscape(new_current); 11018 return scope.CloseAndEscape(new_current);
10993 } 11019 }
10994 11020
10995 11021
10996 // Helper function to find or create the arguments object for 11022 // Helper function to find or create the arguments object for
10997 // Runtime_DebugEvaluate. 11023 // Runtime_DebugEvaluate.
10998 static Handle<Object> GetArgumentsObject(Isolate* isolate, 11024 static Handle<Object> GetArgumentsObject(Isolate* isolate,
10999 JavaScriptFrame* frame, 11025 JavaScriptFrame* frame,
11000 Handle<JSFunction> function, 11026 Handle<JSFunction> function,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
11111 11137
11112 // Allocate a new context for the debug evaluation and set the extension 11138 // Allocate a new context for the debug evaluation and set the extension
11113 // object build. 11139 // object build.
11114 Handle<Context> context = 11140 Handle<Context> context =
11115 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, 11141 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS,
11116 go_between); 11142 go_between);
11117 context->set_extension(*local_scope); 11143 context->set_extension(*local_scope);
11118 // Copy any with contexts present and chain them in front of this context. 11144 // Copy any with contexts present and chain them in front of this context.
11119 Handle<Context> frame_context(Context::cast(frame->context())); 11145 Handle<Context> frame_context(Context::cast(frame->context()));
11120 Handle<Context> function_context(frame_context->declaration_context()); 11146 Handle<Context> function_context(frame_context->declaration_context());
11121 context = CopyWithContextChain(isolate, frame_context, context); 11147 context = CopyWithContextChain(isolate, go_between, frame_context, context);
11122 11148
11123 if (additional_context->IsJSObject()) { 11149 if (additional_context->IsJSObject()) {
11124 Handle<JSObject> extension = Handle<JSObject>::cast(additional_context); 11150 Handle<JSObject> extension = Handle<JSObject>::cast(additional_context);
11125 context = isolate->factory()->NewWithContext(context, extension); 11151 context = isolate->factory()->NewWithContext(go_between, context, extension) ;
11126 } 11152 }
11127 11153
11128 // Wrap the evaluation statement in a new function compiled in the newly 11154 // Wrap the evaluation statement in a new function compiled in the newly
11129 // created context. The function has one parameter which has to be called 11155 // created context. The function has one parameter which has to be called
11130 // 'arguments'. This it to have access to what would have been 'arguments' in 11156 // 'arguments'. This it to have access to what would have been 'arguments' in
11131 // the function being debugged. 11157 // the function being debugged.
11132 // function(arguments,__source__) {return eval(__source__);} 11158 // function(arguments,__source__) {return eval(__source__);}
11133 11159
11134 Handle<String> function_source = 11160 Handle<String> function_source =
11135 isolate->factory()->NewStringFromAscii( 11161 isolate->factory()->NewStringFromAscii(
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
12477 } else { 12503 } else {
12478 // Handle last resort GC and make sure to allow future allocations 12504 // Handle last resort GC and make sure to allow future allocations
12479 // to grow the heap without causing GCs (if possible). 12505 // to grow the heap without causing GCs (if possible).
12480 isolate->counters()->gc_last_resort_from_js()->Increment(); 12506 isolate->counters()->gc_last_resort_from_js()->Increment();
12481 isolate->heap()->CollectAllGarbage(false); 12507 isolate->heap()->CollectAllGarbage(false);
12482 } 12508 }
12483 } 12509 }
12484 12510
12485 12511
12486 } } // namespace v8::internal 12512 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698