Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
| 9 #include "src/debug.h" | 9 #include "src/debug.h" |
| 10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 isolate, target, key, value, SLOPPY), | 794 isolate, target, key, value, SLOPPY), |
| 795 JSObject); | 795 JSObject); |
| 796 } | 796 } |
| 797 } | 797 } |
| 798 } | 798 } |
| 799 | 799 |
| 800 return target; | 800 return target; |
| 801 } | 801 } |
| 802 | 802 |
| 803 | 803 |
| 804 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeScriptScope( | |
| 805 Handle<GlobalObject> global) { | |
| 806 Isolate* isolate = global->GetIsolate(); | |
| 807 Handle<ScriptContextTable> script_contexts( | |
| 808 global->native_context()->script_context_table()); | |
| 809 | |
| 810 Handle<JSObject> script_scope = | |
| 811 isolate->factory()->NewJSObject(isolate->object_function()); | |
| 812 | |
| 813 for (int context_index = 0; context_index < script_contexts->used(); | |
| 814 context_index++) { | |
| 815 Handle<Context> context = | |
| 816 ScriptContextTable::GetContext(script_contexts, context_index); | |
| 817 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | |
| 818 if (!ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, | |
| 819 script_scope)) { | |
| 820 return MaybeHandle<JSObject>(); | |
| 821 } | |
| 822 } | |
| 823 return script_scope; | |
| 824 } | |
| 825 | |
| 826 | |
| 804 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalScope( | 827 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalScope( |
| 805 Isolate* isolate, JavaScriptFrame* frame, int inlined_jsframe_index) { | 828 Isolate* isolate, JavaScriptFrame* frame, int inlined_jsframe_index) { |
| 806 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 829 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
| 807 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); | 830 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); |
| 808 | 831 |
| 809 Handle<JSObject> local_scope = | 832 Handle<JSObject> local_scope = |
| 810 isolate->factory()->NewJSObject(isolate->object_function()); | 833 isolate->factory()->NewJSObject(isolate->object_function()); |
| 811 ASSIGN_RETURN_ON_EXCEPTION( | 834 ASSIGN_RETURN_ON_EXCEPTION( |
| 812 isolate, local_scope, | 835 isolate, local_scope, |
| 813 MaterializeStackLocalsWithFrameInspector(isolate, local_scope, function, | 836 MaterializeStackLocalsWithFrameInspector(isolate, local_scope, function, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 Runtime::DefineObjectProperty(ext, variable_name, new_value, NONE) | 1002 Runtime::DefineObjectProperty(ext, variable_name, new_value, NONE) |
| 980 .Assert(); | 1003 .Assert(); |
| 981 return true; | 1004 return true; |
| 982 } | 1005 } |
| 983 } | 1006 } |
| 984 | 1007 |
| 985 return false; | 1008 return false; |
| 986 } | 1009 } |
| 987 | 1010 |
| 988 | 1011 |
| 1012 static bool SetScriptVariableValue(Handle<Context> context, | |
| 1013 Handle<String> variable_name, | |
| 1014 Handle<Object> new_value) { | |
| 1015 Handle<ScriptContextTable> script_contexts( | |
| 1016 context->global_object()->native_context()->script_context_table()); | |
| 1017 ScriptContextTable::LookupResult lookup_result; | |
| 1018 if (ScriptContextTable::Lookup(script_contexts, variable_name, | |
| 1019 &lookup_result)) { | |
| 1020 Handle<Context> script_context = ScriptContextTable::GetContext( | |
| 1021 script_contexts, lookup_result.context_index); | |
| 1022 script_context->set(lookup_result.slot_index, *new_value); | |
| 1023 return true; | |
| 1024 } | |
| 1025 | |
| 1026 return false; | |
| 1027 } | |
| 1028 | |
| 1029 | |
| 989 // Create a plain JSObject which materializes the scope for the specified | 1030 // Create a plain JSObject which materializes the scope for the specified |
| 990 // catch context. | 1031 // catch context. |
| 991 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeCatchScope( | 1032 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeCatchScope( |
| 992 Isolate* isolate, Handle<Context> context) { | 1033 Isolate* isolate, Handle<Context> context) { |
| 993 DCHECK(context->IsCatchContext()); | 1034 DCHECK(context->IsCatchContext()); |
| 994 Handle<String> name(String::cast(context->extension())); | 1035 Handle<String> name(String::cast(context->extension())); |
| 995 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), | 1036 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), |
| 996 isolate); | 1037 isolate); |
| 997 Handle<JSObject> catch_scope = | 1038 Handle<JSObject> catch_scope = |
| 998 isolate->factory()->NewJSObject(isolate->object_function()); | 1039 isolate->factory()->NewJSObject(isolate->object_function()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 | 1102 |
| 1062 | 1103 |
| 1063 // Iterate over the actual scopes visible from a stack frame or from a closure. | 1104 // Iterate over the actual scopes visible from a stack frame or from a closure. |
| 1064 // The iteration proceeds from the innermost visible nested scope outwards. | 1105 // The iteration proceeds from the innermost visible nested scope outwards. |
| 1065 // All scopes are backed by an actual context except the local scope, | 1106 // All scopes are backed by an actual context except the local scope, |
| 1066 // which is inserted "artificially" in the context chain. | 1107 // which is inserted "artificially" in the context chain. |
| 1067 class ScopeIterator { | 1108 class ScopeIterator { |
| 1068 public: | 1109 public: |
| 1069 enum ScopeType { | 1110 enum ScopeType { |
| 1070 ScopeTypeGlobal = 0, | 1111 ScopeTypeGlobal = 0, |
| 1112 ScopeTypeScript, | |
| 1071 ScopeTypeLocal, | 1113 ScopeTypeLocal, |
| 1072 ScopeTypeWith, | 1114 ScopeTypeWith, |
| 1073 ScopeTypeClosure, | 1115 ScopeTypeClosure, |
| 1074 ScopeTypeCatch, | 1116 ScopeTypeCatch, |
| 1075 ScopeTypeBlock, | 1117 ScopeTypeBlock, |
| 1076 ScopeTypeModule | 1118 ScopeTypeModule |
| 1077 }; | 1119 }; |
| 1078 | 1120 |
| 1079 ScopeIterator(Isolate* isolate, JavaScriptFrame* frame, | 1121 ScopeIterator(Isolate* isolate, JavaScriptFrame* frame, |
| 1080 int inlined_jsframe_index, bool ignore_nested_scopes = false) | 1122 int inlined_jsframe_index, bool ignore_nested_scopes = false) |
| 1081 : isolate_(isolate), | 1123 : isolate_(isolate), |
| 1082 frame_(frame), | 1124 frame_(frame), |
| 1083 inlined_jsframe_index_(inlined_jsframe_index), | 1125 inlined_jsframe_index_(inlined_jsframe_index), |
| 1084 function_(frame->function()), | 1126 function_(frame->function()), |
| 1085 context_(Context::cast(frame->context())), | 1127 context_(Context::cast(frame->context())), |
| 1086 nested_scope_chain_(4), | 1128 nested_scope_chain_(4), |
| 1129 seen_script_scope_(false), | |
| 1087 failed_(false) { | 1130 failed_(false) { |
| 1088 // Catch the case when the debugger stops in an internal function. | 1131 // Catch the case when the debugger stops in an internal function. |
| 1089 Handle<SharedFunctionInfo> shared_info(function_->shared()); | 1132 Handle<SharedFunctionInfo> shared_info(function_->shared()); |
| 1090 Handle<ScopeInfo> scope_info(shared_info->scope_info()); | 1133 Handle<ScopeInfo> scope_info(shared_info->scope_info()); |
| 1091 if (shared_info->script() == isolate->heap()->undefined_value()) { | 1134 if (shared_info->script() == isolate->heap()->undefined_value()) { |
| 1092 while (context_->closure() == *function_) { | 1135 while (context_->closure() == *function_) { |
| 1093 context_ = Handle<Context>(context_->previous(), isolate_); | 1136 context_ = Handle<Context>(context_->previous(), isolate_); |
| 1094 } | 1137 } |
| 1095 return; | 1138 return; |
| 1096 } | 1139 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 } | 1211 } |
| 1169 } | 1212 } |
| 1170 } | 1213 } |
| 1171 | 1214 |
| 1172 ScopeIterator(Isolate* isolate, Handle<JSFunction> function) | 1215 ScopeIterator(Isolate* isolate, Handle<JSFunction> function) |
| 1173 : isolate_(isolate), | 1216 : isolate_(isolate), |
| 1174 frame_(NULL), | 1217 frame_(NULL), |
| 1175 inlined_jsframe_index_(0), | 1218 inlined_jsframe_index_(0), |
| 1176 function_(function), | 1219 function_(function), |
| 1177 context_(function->context()), | 1220 context_(function->context()), |
| 1221 seen_script_scope_(false), | |
| 1178 failed_(false) { | 1222 failed_(false) { |
| 1179 if (function->IsBuiltin()) { | 1223 if (function->IsBuiltin()) { |
| 1180 context_ = Handle<Context>(); | 1224 context_ = Handle<Context>(); |
| 1181 } | 1225 } |
| 1182 } | 1226 } |
| 1183 | 1227 |
| 1184 // More scopes? | 1228 // More scopes? |
| 1185 bool Done() { | 1229 bool Done() { |
| 1186 DCHECK(!failed_); | 1230 DCHECK(!failed_); |
| 1187 return context_.is_null(); | 1231 return context_.is_null(); |
| 1188 } | 1232 } |
| 1189 | 1233 |
| 1190 bool Failed() { return failed_; } | 1234 bool Failed() { return failed_; } |
| 1191 | 1235 |
| 1192 // Move to the next scope. | 1236 // Move to the next scope. |
| 1193 void Next() { | 1237 void Next() { |
| 1194 DCHECK(!failed_); | 1238 DCHECK(!failed_); |
| 1195 ScopeType scope_type = Type(); | 1239 ScopeType scope_type = Type(); |
| 1196 if (scope_type == ScopeTypeGlobal) { | 1240 if (scope_type == ScopeTypeGlobal) { |
| 1197 // The global scope is always the last in the chain. | 1241 // The global scope is always the last in the chain. |
| 1198 DCHECK(context_->IsNativeContext()); | 1242 DCHECK(context_->IsNativeContext()); |
| 1199 context_ = Handle<Context>(); | 1243 context_ = Handle<Context>(); |
| 1200 return; | 1244 return; |
| 1201 } | 1245 } |
| 1202 if (nested_scope_chain_.is_empty()) { | 1246 if (nested_scope_chain_.is_empty()) { |
| 1203 context_ = Handle<Context>(context_->previous(), isolate_); | 1247 if (scope_type == ScopeTypeScript) { |
| 1248 seen_script_scope_ = true; // Our current context was script context. | |
| 1249 if (context_->IsScriptContext()) { | |
| 1250 context_ = Handle<Context>(context_->previous(), isolate_); | |
| 1251 } | |
| 1252 CHECK(context_->IsNativeContext()); | |
| 1253 } else { | |
| 1254 context_ = Handle<Context>(context_->previous(), isolate_); | |
| 1255 } | |
| 1204 } else { | 1256 } else { |
| 1257 seen_script_scope_ = scope_type == ScopeTypeScript; | |
| 1205 if (nested_scope_chain_.last()->HasContext()) { | 1258 if (nested_scope_chain_.last()->HasContext()) { |
| 1206 DCHECK(context_->previous() != NULL); | 1259 DCHECK(context_->previous() != NULL); |
| 1207 context_ = Handle<Context>(context_->previous(), isolate_); | 1260 context_ = Handle<Context>(context_->previous(), isolate_); |
| 1208 } | 1261 } |
| 1209 nested_scope_chain_.RemoveLast(); | 1262 nested_scope_chain_.RemoveLast(); |
| 1210 } | 1263 } |
| 1211 } | 1264 } |
| 1212 | 1265 |
| 1213 // Return the type of the current scope. | 1266 // Return the type of the current scope. |
| 1214 ScopeType Type() { | 1267 ScopeType Type() { |
| 1215 DCHECK(!failed_); | 1268 DCHECK(!failed_); |
| 1216 if (!nested_scope_chain_.is_empty()) { | 1269 if (!nested_scope_chain_.is_empty()) { |
| 1217 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); | 1270 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); |
| 1218 switch (scope_info->scope_type()) { | 1271 switch (scope_info->scope_type()) { |
| 1219 case FUNCTION_SCOPE: | 1272 case FUNCTION_SCOPE: |
| 1220 case ARROW_SCOPE: | 1273 case ARROW_SCOPE: |
| 1221 DCHECK(context_->IsFunctionContext() || !scope_info->HasContext()); | 1274 DCHECK(context_->IsFunctionContext() || !scope_info->HasContext()); |
| 1222 return ScopeTypeLocal; | 1275 return ScopeTypeLocal; |
| 1223 case MODULE_SCOPE: | 1276 case MODULE_SCOPE: |
| 1224 DCHECK(context_->IsModuleContext()); | 1277 DCHECK(context_->IsModuleContext()); |
| 1225 return ScopeTypeModule; | 1278 return ScopeTypeModule; |
| 1226 case SCRIPT_SCOPE: | 1279 case SCRIPT_SCOPE: |
| 1227 DCHECK(context_->IsNativeContext()); | 1280 DCHECK(context_->IsScriptContext() || context_->IsNativeContext()); |
|
yurys
2014/11/14 12:25:32
Why not return ScopeTypeScript only in case contex
| |
| 1228 return ScopeTypeGlobal; | 1281 return ScopeTypeScript; |
| 1229 case WITH_SCOPE: | 1282 case WITH_SCOPE: |
| 1230 DCHECK(context_->IsWithContext()); | 1283 DCHECK(context_->IsWithContext()); |
| 1231 return ScopeTypeWith; | 1284 return ScopeTypeWith; |
| 1232 case CATCH_SCOPE: | 1285 case CATCH_SCOPE: |
| 1233 DCHECK(context_->IsCatchContext()); | 1286 DCHECK(context_->IsCatchContext()); |
| 1234 return ScopeTypeCatch; | 1287 return ScopeTypeCatch; |
| 1235 case BLOCK_SCOPE: | 1288 case BLOCK_SCOPE: |
| 1236 DCHECK(!scope_info->HasContext() || context_->IsBlockContext()); | 1289 DCHECK(!scope_info->HasContext() || context_->IsBlockContext()); |
| 1237 return ScopeTypeBlock; | 1290 return ScopeTypeBlock; |
| 1238 case EVAL_SCOPE: | 1291 case EVAL_SCOPE: |
| 1239 UNREACHABLE(); | 1292 UNREACHABLE(); |
| 1240 } | 1293 } |
| 1241 } | 1294 } |
| 1242 if (context_->IsNativeContext()) { | 1295 if (context_->IsNativeContext()) { |
| 1243 DCHECK(context_->global_object()->IsGlobalObject()); | 1296 DCHECK(context_->global_object()->IsGlobalObject()); |
| 1244 return ScopeTypeGlobal; | 1297 // If we are at the native context and have not yet seen script scope, |
|
yurys
2014/11/14 12:25:32
Can you educate me on how this works, I thought th
Dmitry Lomov (no reviews)
2014/11/14 13:56:51
No. I tried to explain this in CL description but
yurys
2014/11/14 15:02:02
Gotcha, thanks for explaining!
| |
| 1298 // fake it. | |
| 1299 return seen_script_scope_ ? ScopeTypeGlobal : ScopeTypeScript; | |
| 1245 } | 1300 } |
| 1246 if (context_->IsFunctionContext()) { | 1301 if (context_->IsFunctionContext()) { |
| 1247 return ScopeTypeClosure; | 1302 return ScopeTypeClosure; |
| 1248 } | 1303 } |
| 1249 if (context_->IsCatchContext()) { | 1304 if (context_->IsCatchContext()) { |
| 1250 return ScopeTypeCatch; | 1305 return ScopeTypeCatch; |
| 1251 } | 1306 } |
| 1252 if (context_->IsBlockContext()) { | 1307 if (context_->IsBlockContext()) { |
| 1253 return ScopeTypeBlock; | 1308 return ScopeTypeBlock; |
| 1254 } | 1309 } |
| 1255 if (context_->IsModuleContext()) { | 1310 if (context_->IsModuleContext()) { |
| 1256 return ScopeTypeModule; | 1311 return ScopeTypeModule; |
| 1257 } | 1312 } |
| 1313 if (context_->IsScriptContext()) { | |
| 1314 return ScopeTypeScript; | |
| 1315 } | |
| 1258 DCHECK(context_->IsWithContext()); | 1316 DCHECK(context_->IsWithContext()); |
| 1259 return ScopeTypeWith; | 1317 return ScopeTypeWith; |
| 1260 } | 1318 } |
| 1261 | 1319 |
| 1262 // Return the JavaScript object with the content of the current scope. | 1320 // Return the JavaScript object with the content of the current scope. |
| 1263 MaybeHandle<JSObject> ScopeObject() { | 1321 MaybeHandle<JSObject> ScopeObject() { |
| 1264 DCHECK(!failed_); | 1322 DCHECK(!failed_); |
| 1265 switch (Type()) { | 1323 switch (Type()) { |
| 1266 case ScopeIterator::ScopeTypeGlobal: | 1324 case ScopeIterator::ScopeTypeGlobal: |
| 1267 return Handle<JSObject>(CurrentContext()->global_object()); | 1325 return Handle<JSObject>(CurrentContext()->global_object()); |
| 1326 case ScopeIterator::ScopeTypeScript: | |
| 1327 return MaterializeScriptScope( | |
| 1328 Handle<GlobalObject>(CurrentContext()->global_object())); | |
| 1268 case ScopeIterator::ScopeTypeLocal: | 1329 case ScopeIterator::ScopeTypeLocal: |
| 1269 // Materialize the content of the local scope into a JSObject. | 1330 // Materialize the content of the local scope into a JSObject. |
| 1270 DCHECK(nested_scope_chain_.length() == 1); | 1331 DCHECK(nested_scope_chain_.length() == 1); |
| 1271 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); | 1332 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); |
| 1272 case ScopeIterator::ScopeTypeWith: | 1333 case ScopeIterator::ScopeTypeWith: |
| 1273 // Return the with object. | 1334 // Return the with object. |
| 1274 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); | 1335 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); |
| 1275 case ScopeIterator::ScopeTypeCatch: | 1336 case ScopeIterator::ScopeTypeCatch: |
| 1276 return MaterializeCatchScope(isolate_, CurrentContext()); | 1337 return MaterializeCatchScope(isolate_, CurrentContext()); |
| 1277 case ScopeIterator::ScopeTypeClosure: | 1338 case ScopeIterator::ScopeTypeClosure: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1296 return SetLocalVariableValue(isolate_, frame_, inlined_jsframe_index_, | 1357 return SetLocalVariableValue(isolate_, frame_, inlined_jsframe_index_, |
| 1297 variable_name, new_value); | 1358 variable_name, new_value); |
| 1298 case ScopeIterator::ScopeTypeWith: | 1359 case ScopeIterator::ScopeTypeWith: |
| 1299 break; | 1360 break; |
| 1300 case ScopeIterator::ScopeTypeCatch: | 1361 case ScopeIterator::ScopeTypeCatch: |
| 1301 return SetCatchVariableValue(isolate_, CurrentContext(), variable_name, | 1362 return SetCatchVariableValue(isolate_, CurrentContext(), variable_name, |
| 1302 new_value); | 1363 new_value); |
| 1303 case ScopeIterator::ScopeTypeClosure: | 1364 case ScopeIterator::ScopeTypeClosure: |
| 1304 return SetClosureVariableValue(isolate_, CurrentContext(), | 1365 return SetClosureVariableValue(isolate_, CurrentContext(), |
| 1305 variable_name, new_value); | 1366 variable_name, new_value); |
| 1367 case ScopeIterator::ScopeTypeScript: | |
| 1368 return SetScriptVariableValue(CurrentContext(), variable_name, | |
| 1369 new_value); | |
| 1306 case ScopeIterator::ScopeTypeBlock: | 1370 case ScopeIterator::ScopeTypeBlock: |
| 1307 // TODO(2399): should we implement it? | 1371 // TODO(2399): should we implement it? |
| 1308 break; | 1372 break; |
| 1309 case ScopeIterator::ScopeTypeModule: | 1373 case ScopeIterator::ScopeTypeModule: |
| 1310 // TODO(2399): should we implement it? | 1374 // TODO(2399): should we implement it? |
| 1311 break; | 1375 break; |
| 1312 } | 1376 } |
| 1313 return false; | 1377 return false; |
| 1314 } | 1378 } |
| 1315 | 1379 |
| 1316 Handle<ScopeInfo> CurrentScopeInfo() { | 1380 Handle<ScopeInfo> CurrentScopeInfo() { |
| 1317 DCHECK(!failed_); | 1381 DCHECK(!failed_); |
| 1318 if (!nested_scope_chain_.is_empty()) { | 1382 if (!nested_scope_chain_.is_empty()) { |
| 1319 return nested_scope_chain_.last(); | 1383 return nested_scope_chain_.last(); |
| 1320 } else if (context_->IsBlockContext()) { | 1384 } else if (context_->IsBlockContext()) { |
| 1321 return Handle<ScopeInfo>(ScopeInfo::cast(context_->extension())); | 1385 return Handle<ScopeInfo>(ScopeInfo::cast(context_->extension())); |
| 1322 } else if (context_->IsFunctionContext()) { | 1386 } else if (context_->IsFunctionContext()) { |
| 1323 return Handle<ScopeInfo>(context_->closure()->shared()->scope_info()); | 1387 return Handle<ScopeInfo>(context_->closure()->shared()->scope_info()); |
| 1324 } | 1388 } |
| 1325 return Handle<ScopeInfo>::null(); | 1389 return Handle<ScopeInfo>::null(); |
| 1326 } | 1390 } |
| 1327 | 1391 |
| 1328 // Return the context for this scope. For the local context there might not | 1392 // Return the context for this scope. For the local context there might not |
| 1329 // be an actual context. | 1393 // be an actual context. |
| 1330 Handle<Context> CurrentContext() { | 1394 Handle<Context> CurrentContext() { |
| 1331 DCHECK(!failed_); | 1395 DCHECK(!failed_); |
| 1332 if (Type() == ScopeTypeGlobal || nested_scope_chain_.is_empty()) { | 1396 if (Type() == ScopeTypeGlobal || Type() == ScopeTypeScript || |
| 1397 nested_scope_chain_.is_empty()) { | |
| 1333 return context_; | 1398 return context_; |
| 1334 } else if (nested_scope_chain_.last()->HasContext()) { | 1399 } else if (nested_scope_chain_.last()->HasContext()) { |
| 1335 return context_; | 1400 return context_; |
| 1336 } else { | 1401 } else { |
| 1337 return Handle<Context>(); | 1402 return Handle<Context>(); |
| 1338 } | 1403 } |
| 1339 } | 1404 } |
| 1340 | 1405 |
| 1341 #ifdef DEBUG | 1406 #ifdef DEBUG |
| 1342 // Debug print of the content of the current scope. | 1407 // Debug print of the content of the current scope. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1379 os << "Closure:\n"; | 1444 os << "Closure:\n"; |
| 1380 CurrentContext()->Print(os); | 1445 CurrentContext()->Print(os); |
| 1381 if (CurrentContext()->has_extension()) { | 1446 if (CurrentContext()->has_extension()) { |
| 1382 Handle<Object> extension(CurrentContext()->extension(), isolate_); | 1447 Handle<Object> extension(CurrentContext()->extension(), isolate_); |
| 1383 if (extension->IsJSContextExtensionObject()) { | 1448 if (extension->IsJSContextExtensionObject()) { |
| 1384 extension->Print(os); | 1449 extension->Print(os); |
| 1385 } | 1450 } |
| 1386 } | 1451 } |
| 1387 break; | 1452 break; |
| 1388 | 1453 |
| 1454 case ScopeIterator::ScopeTypeScript: | |
| 1455 os << "Script:\n"; | |
| 1456 CurrentContext() | |
| 1457 ->global_object() | |
| 1458 ->native_context() | |
| 1459 ->script_context_table() | |
| 1460 ->Print(os); | |
| 1461 break; | |
| 1462 | |
| 1389 default: | 1463 default: |
| 1390 UNREACHABLE(); | 1464 UNREACHABLE(); |
| 1391 } | 1465 } |
| 1392 PrintF("\n"); | 1466 PrintF("\n"); |
| 1393 } | 1467 } |
| 1394 #endif | 1468 #endif |
| 1395 | 1469 |
| 1396 private: | 1470 private: |
| 1397 Isolate* isolate_; | 1471 Isolate* isolate_; |
| 1398 JavaScriptFrame* frame_; | 1472 JavaScriptFrame* frame_; |
| 1399 int inlined_jsframe_index_; | 1473 int inlined_jsframe_index_; |
| 1400 Handle<JSFunction> function_; | 1474 Handle<JSFunction> function_; |
| 1401 Handle<Context> context_; | 1475 Handle<Context> context_; |
| 1402 List<Handle<ScopeInfo> > nested_scope_chain_; | 1476 List<Handle<ScopeInfo> > nested_scope_chain_; |
| 1477 bool seen_script_scope_; | |
| 1403 bool failed_; | 1478 bool failed_; |
| 1404 | 1479 |
| 1405 void RetrieveScopeChain(Scope* scope, | 1480 void RetrieveScopeChain(Scope* scope, |
| 1406 Handle<SharedFunctionInfo> shared_info) { | 1481 Handle<SharedFunctionInfo> shared_info) { |
| 1407 if (scope != NULL) { | 1482 if (scope != NULL) { |
| 1408 int source_position = shared_info->code()->SourcePosition(frame_->pc()); | 1483 int source_position = shared_info->code()->SourcePosition(frame_->pc()); |
| 1409 scope->GetNestedScopeChain(&nested_scope_chain_, source_position); | 1484 scope->GetNestedScopeChain(&nested_scope_chain_, source_position); |
| 1410 } else { | 1485 } else { |
| 1411 // A failed reparse indicates that the preparser has diverged from the | 1486 // A failed reparse indicates that the preparser has diverged from the |
| 1412 // parser or that the preparse data given to the initial parse has been | 1487 // parser or that the preparse data given to the initial parse has been |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2157 // uses this temporary context chain. | 2232 // uses this temporary context chain. |
| 2158 | 2233 |
| 2159 Handle<Context> eval_context(Context::cast(frame_inspector.GetContext())); | 2234 Handle<Context> eval_context(Context::cast(frame_inspector.GetContext())); |
| 2160 DCHECK(!eval_context.is_null()); | 2235 DCHECK(!eval_context.is_null()); |
| 2161 Handle<Context> function_context = eval_context; | 2236 Handle<Context> function_context = eval_context; |
| 2162 Handle<Context> outer_context(function->context(), isolate); | 2237 Handle<Context> outer_context(function->context(), isolate); |
| 2163 Handle<Context> inner_context; | 2238 Handle<Context> inner_context; |
| 2164 // We iterate to find the function's context. If the function has no | 2239 // We iterate to find the function's context. If the function has no |
| 2165 // context-allocated variables, we iterate until we hit the outer context. | 2240 // context-allocated variables, we iterate until we hit the outer context. |
| 2166 while (!function_context->IsFunctionContext() && | 2241 while (!function_context->IsFunctionContext() && |
| 2242 !function_context->IsScriptContext() && | |
| 2167 !function_context.is_identical_to(outer_context)) { | 2243 !function_context.is_identical_to(outer_context)) { |
| 2168 inner_context = function_context; | 2244 inner_context = function_context; |
| 2169 function_context = Handle<Context>(function_context->previous(), isolate); | 2245 function_context = Handle<Context>(function_context->previous(), isolate); |
| 2170 } | 2246 } |
| 2171 | 2247 |
| 2172 Handle<Context> materialized_context = isolate->factory()->NewWithContext( | 2248 Handle<Context> materialized_context = isolate->factory()->NewWithContext( |
| 2173 function, function_context, materialized); | 2249 function, function_context, materialized); |
| 2174 | 2250 |
| 2175 if (inner_context.is_null()) { | 2251 if (inner_context.is_null()) { |
| 2176 // No inner context. The with-context is now inner-most. | 2252 // No inner context. The with-context is now inner-most. |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2722 return Smi::FromInt(isolate->debug()->is_active()); | 2798 return Smi::FromInt(isolate->debug()->is_active()); |
| 2723 } | 2799 } |
| 2724 | 2800 |
| 2725 | 2801 |
| 2726 RUNTIME_FUNCTION(RuntimeReference_DebugBreakInOptimizedCode) { | 2802 RUNTIME_FUNCTION(RuntimeReference_DebugBreakInOptimizedCode) { |
| 2727 UNIMPLEMENTED(); | 2803 UNIMPLEMENTED(); |
| 2728 return NULL; | 2804 return NULL; |
| 2729 } | 2805 } |
| 2730 } | 2806 } |
| 2731 } // namespace v8::internal | 2807 } // namespace v8::internal |
| OLD | NEW |