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/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/debug.h" | 10 #include "src/debug.h" |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info, | 854 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info, |
855 Handle<String> parameter_name) { | 855 Handle<String> parameter_name) { |
856 VariableMode mode; | 856 VariableMode mode; |
857 InitializationFlag init_flag; | 857 InitializationFlag init_flag; |
858 MaybeAssignedFlag maybe_assigned_flag; | 858 MaybeAssignedFlag maybe_assigned_flag; |
859 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag, | 859 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag, |
860 &maybe_assigned_flag) != -1; | 860 &maybe_assigned_flag) != -1; |
861 } | 861 } |
862 | 862 |
863 | 863 |
864 static Handle<Context> MaterializeReceiver(Isolate* isolate, | 864 MUST_USE_RESULT |
865 Handle<Context> target, | 865 static MaybeHandle<Context> MaterializeReceiver(Isolate* isolate, |
866 Handle<JSFunction> function, | 866 Handle<Context> target, |
867 JavaScriptFrame* frame) { | 867 Handle<JSFunction> function, |
| 868 JavaScriptFrame* frame) { |
868 Handle<SharedFunctionInfo> shared(function->shared()); | 869 Handle<SharedFunctionInfo> shared(function->shared()); |
869 Handle<ScopeInfo> scope_info(shared->scope_info()); | 870 Handle<ScopeInfo> scope_info(shared->scope_info()); |
870 Handle<Object> receiver; | 871 Handle<Object> receiver; |
871 switch (scope_info->scope_type()) { | 872 switch (scope_info->scope_type()) { |
872 case FUNCTION_SCOPE: { | 873 case FUNCTION_SCOPE: { |
873 VariableMode variable_mode; | 874 VariableMode variable_mode; |
874 InitializationFlag init_flag; | 875 InitializationFlag init_flag; |
875 MaybeAssignedFlag maybe_assigned_flag; | 876 MaybeAssignedFlag maybe_assigned_flag; |
876 | 877 |
877 // Don't bother creating a fake context node if "this" is in the context | 878 // Don't bother creating a fake context node if "this" is in the context |
878 // already. | 879 // already. |
879 if (ScopeInfo::ContextSlotIndex( | 880 if (ScopeInfo::ContextSlotIndex( |
880 scope_info, isolate->factory()->this_string(), &variable_mode, | 881 scope_info, isolate->factory()->this_string(), &variable_mode, |
881 &init_flag, &maybe_assigned_flag) >= 0) { | 882 &init_flag, &maybe_assigned_flag) >= 0) { |
882 return target; | 883 return target; |
883 } | 884 } |
884 receiver = handle(frame->receiver(), isolate); | 885 receiver = Handle<Object>(frame->receiver(), isolate); |
885 break; | 886 break; |
886 } | 887 } |
887 case MODULE_SCOPE: | 888 case MODULE_SCOPE: |
888 receiver = isolate->factory()->undefined_value(); | 889 receiver = isolate->factory()->undefined_value(); |
889 break; | 890 break; |
890 case SCRIPT_SCOPE: | 891 case SCRIPT_SCOPE: |
891 receiver = handle(function->global_proxy(), isolate); | 892 receiver = Handle<Object>(function->global_proxy(), isolate); |
892 break; | 893 break; |
893 default: | 894 default: |
894 // For eval code, arrow functions, and the like, there's no "this" binding | 895 // For eval code, arrow functions, and the like, there's no "this" binding |
895 // to materialize. | 896 // to materialize. |
896 return target; | 897 return target; |
897 } | 898 } |
898 | 899 |
899 return isolate->factory()->NewCatchContext( | 900 return isolate->factory()->NewCatchContext( |
900 function, target, isolate->factory()->this_string(), receiver); | 901 function, target, isolate->factory()->this_string(), receiver); |
901 } | 902 } |
902 | 903 |
903 | 904 |
904 // Create a plain JSObject which materializes the local scope for the specified | 905 // Create a plain JSObject which materializes the local scope for the specified |
905 // frame. | 906 // frame. |
906 static void MaterializeStackLocalsWithFrameInspector( | 907 MUST_USE_RESULT |
| 908 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( |
907 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, | 909 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, |
908 FrameInspector* frame_inspector) { | 910 FrameInspector* frame_inspector) { |
909 // First fill all parameters. | 911 // First fill all parameters. |
910 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 912 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
911 // Do not materialize the parameter if it is shadowed by a context local. | 913 // Do not materialize the parameter if it is shadowed by a context local. |
912 Handle<String> name(scope_info->ParameterName(i)); | 914 Handle<String> name(scope_info->ParameterName(i)); |
913 if (ParameterIsShadowedByContextLocal(scope_info, name)) continue; | 915 if (ParameterIsShadowedByContextLocal(scope_info, name)) continue; |
914 | 916 |
915 DCHECK_NOT_NULL(frame_inspector); | 917 DCHECK_NOT_NULL(frame_inspector); |
916 | 918 |
917 HandleScope scope(isolate); | 919 HandleScope scope(isolate); |
918 Handle<Object> value(i < frame_inspector->GetParametersCount() | 920 Handle<Object> value(i < frame_inspector->GetParametersCount() |
919 ? frame_inspector->GetParameter(i) | 921 ? frame_inspector->GetParameter(i) |
920 : isolate->heap()->undefined_value(), | 922 : isolate->heap()->undefined_value(), |
921 isolate); | 923 isolate); |
922 DCHECK(!value->IsTheHole()); | 924 DCHECK(!value->IsTheHole()); |
923 | 925 |
924 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check(); | 926 RETURN_ON_EXCEPTION(isolate, Runtime::SetObjectProperty( |
| 927 isolate, target, name, value, SLOPPY), |
| 928 JSObject); |
925 } | 929 } |
926 | 930 |
927 // Second fill all stack locals. | 931 // Second fill all stack locals. |
928 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 932 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
929 if (scope_info->LocalIsSynthetic(i)) continue; | 933 if (scope_info->LocalIsSynthetic(i)) continue; |
930 Handle<String> name(scope_info->StackLocalName(i)); | 934 Handle<String> name(scope_info->StackLocalName(i)); |
931 Handle<Object> value( | 935 Handle<Object> value( |
932 frame_inspector->GetExpression(scope_info->StackLocalIndex(i)), | 936 frame_inspector->GetExpression(scope_info->StackLocalIndex(i)), |
933 isolate); | 937 isolate); |
934 if (value->IsTheHole()) { | 938 if (value->IsTheHole()) { |
935 value = isolate->factory()->undefined_value(); | 939 value = isolate->factory()->undefined_value(); |
936 } | 940 } |
937 | 941 |
938 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check(); | 942 RETURN_ON_EXCEPTION(isolate, Runtime::SetObjectProperty( |
| 943 isolate, target, name, value, SLOPPY), |
| 944 JSObject); |
939 } | 945 } |
| 946 |
| 947 return target; |
940 } | 948 } |
941 | 949 |
942 static void MaterializeStackLocalsWithFrameInspector( | 950 MUST_USE_RESULT |
| 951 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( |
943 Isolate* isolate, Handle<JSObject> target, Handle<JSFunction> function, | 952 Isolate* isolate, Handle<JSObject> target, Handle<JSFunction> function, |
944 FrameInspector* frame_inspector) { | 953 FrameInspector* frame_inspector) { |
945 Handle<SharedFunctionInfo> shared(function->shared()); | 954 Handle<SharedFunctionInfo> shared(function->shared()); |
946 Handle<ScopeInfo> scope_info(shared->scope_info()); | 955 Handle<ScopeInfo> scope_info(shared->scope_info()); |
947 | 956 |
948 MaterializeStackLocalsWithFrameInspector(isolate, target, scope_info, | 957 return MaterializeStackLocalsWithFrameInspector(isolate, target, scope_info, |
949 frame_inspector); | 958 frame_inspector); |
950 } | 959 } |
951 | 960 |
952 | 961 |
953 static void UpdateStackLocalsFromMaterializedObject( | 962 static void UpdateStackLocalsFromMaterializedObject( |
954 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, | 963 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, |
955 JavaScriptFrame* frame, int inlined_jsframe_index) { | 964 JavaScriptFrame* frame, int inlined_jsframe_index) { |
956 if (inlined_jsframe_index != 0 || frame->is_optimized()) { | 965 if (inlined_jsframe_index != 0 || frame->is_optimized()) { |
957 // Optimized frames are not supported. | 966 // Optimized frames are not supported. |
958 // TODO(yangguo): make sure all code deoptimized when debugger is active | 967 // TODO(yangguo): make sure all code deoptimized when debugger is active |
959 // and assert that this cannot happen. | 968 // and assert that this cannot happen. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 JavaScriptFrame* frame) { | 1001 JavaScriptFrame* frame) { |
993 HandleScope scope(isolate); | 1002 HandleScope scope(isolate); |
994 Handle<SharedFunctionInfo> shared(function->shared()); | 1003 Handle<SharedFunctionInfo> shared(function->shared()); |
995 Handle<ScopeInfo> scope_info(shared->scope_info()); | 1004 Handle<ScopeInfo> scope_info(shared->scope_info()); |
996 | 1005 |
997 if (!scope_info->HasContext()) return target; | 1006 if (!scope_info->HasContext()) return target; |
998 | 1007 |
999 // Third fill all context locals. | 1008 // Third fill all context locals. |
1000 Handle<Context> frame_context(Context::cast(frame->context())); | 1009 Handle<Context> frame_context(Context::cast(frame->context())); |
1001 Handle<Context> function_context(frame_context->declaration_context()); | 1010 Handle<Context> function_context(frame_context->declaration_context()); |
1002 ScopeInfo::CopyContextLocalsToScopeObject(scope_info, function_context, | 1011 if (!ScopeInfo::CopyContextLocalsToScopeObject(scope_info, function_context, |
1003 target); | 1012 target)) { |
| 1013 return MaybeHandle<JSObject>(); |
| 1014 } |
1004 | 1015 |
1005 // Finally copy any properties from the function context extension. | 1016 // Finally copy any properties from the function context extension. |
1006 // These will be variables introduced by eval. | 1017 // These will be variables introduced by eval. |
1007 if (function_context->closure() == *function) { | 1018 if (function_context->closure() == *function) { |
1008 if (function_context->has_extension() && | 1019 if (function_context->has_extension() && |
1009 !function_context->IsNativeContext()) { | 1020 !function_context->IsNativeContext()) { |
1010 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 1021 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
1011 Handle<FixedArray> keys; | 1022 Handle<FixedArray> keys; |
1012 ASSIGN_RETURN_ON_EXCEPTION( | 1023 ASSIGN_RETURN_ON_EXCEPTION( |
1013 isolate, keys, JSReceiver::GetKeys(ext, JSReceiver::INCLUDE_PROTOS), | 1024 isolate, keys, JSReceiver::GetKeys(ext, JSReceiver::INCLUDE_PROTOS), |
(...skipping 24 matching lines...) Expand all Loading... |
1038 global->native_context()->script_context_table()); | 1049 global->native_context()->script_context_table()); |
1039 | 1050 |
1040 Handle<JSObject> script_scope = | 1051 Handle<JSObject> script_scope = |
1041 isolate->factory()->NewJSObject(isolate->object_function()); | 1052 isolate->factory()->NewJSObject(isolate->object_function()); |
1042 | 1053 |
1043 for (int context_index = 0; context_index < script_contexts->used(); | 1054 for (int context_index = 0; context_index < script_contexts->used(); |
1044 context_index++) { | 1055 context_index++) { |
1045 Handle<Context> context = | 1056 Handle<Context> context = |
1046 ScriptContextTable::GetContext(script_contexts, context_index); | 1057 ScriptContextTable::GetContext(script_contexts, context_index); |
1047 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 1058 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
1048 ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, | 1059 if (!ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, |
1049 script_scope); | 1060 script_scope)) { |
| 1061 return MaybeHandle<JSObject>(); |
| 1062 } |
1050 } | 1063 } |
1051 return script_scope; | 1064 return script_scope; |
1052 } | 1065 } |
1053 | 1066 |
1054 | 1067 |
1055 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalScope( | 1068 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalScope( |
1056 Isolate* isolate, JavaScriptFrame* frame, int inlined_jsframe_index) { | 1069 Isolate* isolate, JavaScriptFrame* frame, int inlined_jsframe_index) { |
1057 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 1070 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
1058 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); | 1071 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); |
1059 | 1072 |
1060 Handle<JSObject> local_scope = | 1073 Handle<JSObject> local_scope = |
1061 isolate->factory()->NewJSObject(isolate->object_function()); | 1074 isolate->factory()->NewJSObject(isolate->object_function()); |
1062 MaterializeStackLocalsWithFrameInspector(isolate, local_scope, function, | 1075 ASSIGN_RETURN_ON_EXCEPTION( |
1063 &frame_inspector); | 1076 isolate, local_scope, |
| 1077 MaterializeStackLocalsWithFrameInspector(isolate, local_scope, function, |
| 1078 &frame_inspector), |
| 1079 JSObject); |
1064 | 1080 |
1065 return MaterializeLocalContext(isolate, local_scope, function, frame); | 1081 return MaterializeLocalContext(isolate, local_scope, function, frame); |
1066 } | 1082 } |
1067 | 1083 |
1068 | 1084 |
1069 // Set the context local variable value. | 1085 // Set the context local variable value. |
1070 static bool SetContextLocalValue(Isolate* isolate, Handle<ScopeInfo> scope_info, | 1086 static bool SetContextLocalValue(Isolate* isolate, Handle<ScopeInfo> scope_info, |
1071 Handle<Context> context, | 1087 Handle<Context> context, |
1072 Handle<String> variable_name, | 1088 Handle<String> variable_name, |
1073 Handle<Object> new_value) { | 1089 Handle<Object> new_value) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 if (!block_context.is_null()) { | 1189 if (!block_context.is_null()) { |
1174 return SetContextLocalValue(block_context->GetIsolate(), scope_info, | 1190 return SetContextLocalValue(block_context->GetIsolate(), scope_info, |
1175 block_context, variable_name, new_value); | 1191 block_context, variable_name, new_value); |
1176 } | 1192 } |
1177 return false; | 1193 return false; |
1178 } | 1194 } |
1179 | 1195 |
1180 | 1196 |
1181 // Create a plain JSObject which materializes the closure content for the | 1197 // Create a plain JSObject which materializes the closure content for the |
1182 // context. | 1198 // context. |
1183 static Handle<JSObject> MaterializeClosure(Isolate* isolate, | 1199 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeClosure( |
1184 Handle<Context> context) { | 1200 Isolate* isolate, Handle<Context> context) { |
1185 DCHECK(context->IsFunctionContext()); | 1201 DCHECK(context->IsFunctionContext()); |
1186 | 1202 |
1187 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 1203 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
1188 Handle<ScopeInfo> scope_info(shared->scope_info()); | 1204 Handle<ScopeInfo> scope_info(shared->scope_info()); |
1189 | 1205 |
1190 // Allocate and initialize a JSObject with all the content of this function | 1206 // Allocate and initialize a JSObject with all the content of this function |
1191 // closure. | 1207 // closure. |
1192 Handle<JSObject> closure_scope = | 1208 Handle<JSObject> closure_scope = |
1193 isolate->factory()->NewJSObject(isolate->object_function()); | 1209 isolate->factory()->NewJSObject(isolate->object_function()); |
1194 | 1210 |
1195 // Fill all context locals to the context extension. | 1211 // Fill all context locals to the context extension. |
1196 ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, closure_scope); | 1212 if (!ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, |
| 1213 closure_scope)) { |
| 1214 return MaybeHandle<JSObject>(); |
| 1215 } |
1197 | 1216 |
1198 // Finally copy any properties from the function context extension. This will | 1217 // Finally copy any properties from the function context extension. This will |
1199 // be variables introduced by eval. | 1218 // be variables introduced by eval. |
1200 if (context->has_extension()) { | 1219 if (context->has_extension()) { |
1201 Handle<JSObject> ext(JSObject::cast(context->extension())); | 1220 Handle<JSObject> ext(JSObject::cast(context->extension())); |
1202 DCHECK(ext->IsJSContextExtensionObject()); | 1221 Handle<FixedArray> keys; |
1203 Handle<FixedArray> keys = | 1222 ASSIGN_RETURN_ON_EXCEPTION( |
1204 JSReceiver::GetKeys(ext, JSReceiver::OWN_ONLY).ToHandleChecked(); | 1223 isolate, keys, JSReceiver::GetKeys(ext, JSReceiver::INCLUDE_PROTOS), |
| 1224 JSObject); |
1205 | 1225 |
1206 for (int i = 0; i < keys->length(); i++) { | 1226 for (int i = 0; i < keys->length(); i++) { |
1207 HandleScope scope(isolate); | 1227 HandleScope scope(isolate); |
1208 // Names of variables introduced by eval are strings. | 1228 // Names of variables introduced by eval are strings. |
1209 DCHECK(keys->get(i)->IsString()); | 1229 DCHECK(keys->get(i)->IsString()); |
1210 Handle<String> key(String::cast(keys->get(i))); | 1230 Handle<String> key(String::cast(keys->get(i))); |
1211 Handle<Object> value = Object::GetProperty(ext, key).ToHandleChecked(); | 1231 Handle<Object> value; |
1212 JSObject::SetOwnPropertyIgnoreAttributes(closure_scope, key, value, NONE) | 1232 ASSIGN_RETURN_ON_EXCEPTION( |
1213 .Check(); | 1233 isolate, value, Object::GetPropertyOrElement(ext, key), JSObject); |
| 1234 RETURN_ON_EXCEPTION(isolate, Runtime::DefineObjectProperty( |
| 1235 closure_scope, key, value, NONE), |
| 1236 JSObject); |
1214 } | 1237 } |
1215 } | 1238 } |
1216 | 1239 |
1217 return closure_scope; | 1240 return closure_scope; |
1218 } | 1241 } |
1219 | 1242 |
1220 | 1243 |
1221 // This method copies structure of MaterializeClosure method above. | 1244 // This method copies structure of MaterializeClosure method above. |
1222 static bool SetClosureVariableValue(Isolate* isolate, Handle<Context> context, | 1245 static bool SetClosureVariableValue(Isolate* isolate, Handle<Context> context, |
1223 Handle<String> variable_name, | 1246 Handle<String> variable_name, |
1224 Handle<Object> new_value) { | 1247 Handle<Object> new_value) { |
1225 DCHECK(context->IsFunctionContext()); | 1248 DCHECK(context->IsFunctionContext()); |
1226 | 1249 |
1227 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 1250 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
1228 Handle<ScopeInfo> scope_info(shared->scope_info()); | 1251 Handle<ScopeInfo> scope_info(shared->scope_info()); |
1229 | 1252 |
1230 // Context locals to the context extension. | 1253 // Context locals to the context extension. |
1231 if (SetContextLocalValue(isolate, scope_info, context, variable_name, | 1254 if (SetContextLocalValue(isolate, scope_info, context, variable_name, |
1232 new_value)) { | 1255 new_value)) { |
1233 return true; | 1256 return true; |
1234 } | 1257 } |
1235 | 1258 |
1236 // Properties from the function context extension. This will | 1259 // Properties from the function context extension. This will |
1237 // be variables introduced by eval. | 1260 // be variables introduced by eval. |
1238 if (context->has_extension()) { | 1261 if (context->has_extension()) { |
1239 Handle<JSObject> ext(JSObject::cast(context->extension())); | 1262 Handle<JSObject> ext(JSObject::cast(context->extension())); |
1240 DCHECK(ext->IsJSContextExtensionObject()); | 1263 Maybe<bool> maybe = JSReceiver::HasProperty(ext, variable_name); |
1241 Maybe<bool> maybe = JSReceiver::HasOwnProperty(ext, variable_name); | |
1242 DCHECK(maybe.IsJust()); | 1264 DCHECK(maybe.IsJust()); |
1243 if (maybe.FromJust()) { | 1265 if (maybe.FromJust()) { |
1244 // We don't expect this to do anything except replacing property value. | 1266 // We don't expect this to do anything except replacing property value. |
1245 JSObject::SetOwnPropertyIgnoreAttributes(ext, variable_name, new_value, | 1267 Runtime::DefineObjectProperty(ext, variable_name, new_value, NONE) |
1246 NONE).Check(); | 1268 .Assert(); |
1247 return true; | 1269 return true; |
1248 } | 1270 } |
1249 } | 1271 } |
1250 | 1272 |
1251 return false; | 1273 return false; |
1252 } | 1274 } |
1253 | 1275 |
1254 | 1276 |
1255 static bool SetScriptVariableValue(Handle<Context> context, | 1277 static bool SetScriptVariableValue(Handle<Context> context, |
1256 Handle<String> variable_name, | 1278 Handle<String> variable_name, |
1257 Handle<Object> new_value) { | 1279 Handle<Object> new_value) { |
1258 Handle<ScriptContextTable> script_contexts( | 1280 Handle<ScriptContextTable> script_contexts( |
1259 context->global_object()->native_context()->script_context_table()); | 1281 context->global_object()->native_context()->script_context_table()); |
1260 ScriptContextTable::LookupResult lookup_result; | 1282 ScriptContextTable::LookupResult lookup_result; |
1261 if (ScriptContextTable::Lookup(script_contexts, variable_name, | 1283 if (ScriptContextTable::Lookup(script_contexts, variable_name, |
1262 &lookup_result)) { | 1284 &lookup_result)) { |
1263 Handle<Context> script_context = ScriptContextTable::GetContext( | 1285 Handle<Context> script_context = ScriptContextTable::GetContext( |
1264 script_contexts, lookup_result.context_index); | 1286 script_contexts, lookup_result.context_index); |
1265 script_context->set(lookup_result.slot_index, *new_value); | 1287 script_context->set(lookup_result.slot_index, *new_value); |
1266 return true; | 1288 return true; |
1267 } | 1289 } |
1268 | 1290 |
1269 return false; | 1291 return false; |
1270 } | 1292 } |
1271 | 1293 |
1272 | 1294 |
1273 // Create a plain JSObject which materializes the scope for the specified | 1295 // Create a plain JSObject which materializes the scope for the specified |
1274 // catch context. | 1296 // catch context. |
1275 static Handle<JSObject> MaterializeCatchScope(Isolate* isolate, | 1297 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeCatchScope( |
1276 Handle<Context> context) { | 1298 Isolate* isolate, Handle<Context> context) { |
1277 DCHECK(context->IsCatchContext()); | 1299 DCHECK(context->IsCatchContext()); |
1278 Handle<String> name(String::cast(context->extension())); | 1300 Handle<String> name(String::cast(context->extension())); |
1279 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), | 1301 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), |
1280 isolate); | 1302 isolate); |
1281 Handle<JSObject> catch_scope = | 1303 Handle<JSObject> catch_scope = |
1282 isolate->factory()->NewJSObject(isolate->object_function()); | 1304 isolate->factory()->NewJSObject(isolate->object_function()); |
1283 JSObject::SetOwnPropertyIgnoreAttributes(catch_scope, name, thrown_object, | 1305 RETURN_ON_EXCEPTION(isolate, Runtime::DefineObjectProperty( |
1284 NONE).Check(); | 1306 catch_scope, name, thrown_object, NONE), |
| 1307 JSObject); |
1285 return catch_scope; | 1308 return catch_scope; |
1286 } | 1309 } |
1287 | 1310 |
1288 | 1311 |
1289 static bool SetCatchVariableValue(Isolate* isolate, Handle<Context> context, | 1312 static bool SetCatchVariableValue(Isolate* isolate, Handle<Context> context, |
1290 Handle<String> variable_name, | 1313 Handle<String> variable_name, |
1291 Handle<Object> new_value) { | 1314 Handle<Object> new_value) { |
1292 DCHECK(context->IsCatchContext()); | 1315 DCHECK(context->IsCatchContext()); |
1293 Handle<String> name(String::cast(context->extension())); | 1316 Handle<String> name(String::cast(context->extension())); |
1294 if (!String::Equals(name, variable_name)) { | 1317 if (!String::Equals(name, variable_name)) { |
1295 return false; | 1318 return false; |
1296 } | 1319 } |
1297 context->set(Context::THROWN_OBJECT_INDEX, *new_value); | 1320 context->set(Context::THROWN_OBJECT_INDEX, *new_value); |
1298 return true; | 1321 return true; |
1299 } | 1322 } |
1300 | 1323 |
1301 | 1324 |
1302 // Create a plain JSObject which materializes the block scope for the specified | 1325 // Create a plain JSObject which materializes the block scope for the specified |
1303 // block context. | 1326 // block context. |
1304 static Handle<JSObject> MaterializeBlockScope(Isolate* isolate, | 1327 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeBlockScope( |
1305 Handle<ScopeInfo> scope_info, | 1328 Isolate* isolate, Handle<ScopeInfo> scope_info, Handle<Context> context, |
1306 Handle<Context> context, | 1329 JavaScriptFrame* frame, int inlined_jsframe_index) { |
1307 JavaScriptFrame* frame, | |
1308 int inlined_jsframe_index) { | |
1309 Handle<JSObject> block_scope = | 1330 Handle<JSObject> block_scope = |
1310 isolate->factory()->NewJSObject(isolate->object_function()); | 1331 isolate->factory()->NewJSObject(isolate->object_function()); |
1311 | 1332 |
1312 if (frame != nullptr) { | 1333 if (frame != nullptr) { |
1313 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 1334 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
1314 MaterializeStackLocalsWithFrameInspector(isolate, block_scope, scope_info, | 1335 RETURN_ON_EXCEPTION(isolate, |
1315 &frame_inspector); | 1336 MaterializeStackLocalsWithFrameInspector( |
| 1337 isolate, block_scope, scope_info, &frame_inspector), |
| 1338 JSObject); |
1316 } | 1339 } |
1317 | 1340 |
1318 if (!context.is_null()) { | 1341 if (!context.is_null()) { |
1319 Handle<ScopeInfo> scope_info_from_context( | 1342 Handle<ScopeInfo> scope_info_from_context( |
1320 ScopeInfo::cast(context->extension())); | 1343 ScopeInfo::cast(context->extension())); |
1321 // Fill all context locals. | 1344 // Fill all context locals. |
1322 ScopeInfo::CopyContextLocalsToScopeObject(scope_info_from_context, context, | 1345 if (!ScopeInfo::CopyContextLocalsToScopeObject(scope_info_from_context, |
1323 block_scope); | 1346 context, block_scope)) { |
| 1347 return MaybeHandle<JSObject>(); |
| 1348 } |
1324 } | 1349 } |
1325 | 1350 |
1326 return block_scope; | 1351 return block_scope; |
1327 } | 1352 } |
1328 | 1353 |
1329 | 1354 |
1330 // Create a plain JSObject which materializes the module scope for the specified | 1355 // Create a plain JSObject which materializes the module scope for the specified |
1331 // module context. | 1356 // module context. |
1332 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeModuleScope( | 1357 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeModuleScope( |
1333 Isolate* isolate, Handle<Context> context) { | 1358 Isolate* isolate, Handle<Context> context) { |
1334 DCHECK(context->IsModuleContext()); | 1359 DCHECK(context->IsModuleContext()); |
1335 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 1360 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
1336 | 1361 |
1337 // Allocate and initialize a JSObject with all the members of the debugged | 1362 // Allocate and initialize a JSObject with all the members of the debugged |
1338 // module. | 1363 // module. |
1339 Handle<JSObject> module_scope = | 1364 Handle<JSObject> module_scope = |
1340 isolate->factory()->NewJSObject(isolate->object_function()); | 1365 isolate->factory()->NewJSObject(isolate->object_function()); |
1341 | 1366 |
1342 // Fill all context locals. | 1367 // Fill all context locals. |
1343 ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, module_scope); | 1368 if (!ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, |
| 1369 module_scope)) { |
| 1370 return MaybeHandle<JSObject>(); |
| 1371 } |
1344 | 1372 |
1345 return module_scope; | 1373 return module_scope; |
1346 } | 1374 } |
1347 | 1375 |
1348 | 1376 |
1349 // Iterate over the actual scopes visible from a stack frame or from a closure. | 1377 // Iterate over the actual scopes visible from a stack frame or from a closure. |
1350 // The iteration proceeds from the innermost visible nested scope outwards. | 1378 // The iteration proceeds from the innermost visible nested scope outwards. |
1351 // All scopes are backed by an actual context except the local scope, | 1379 // All scopes are backed by an actual context except the local scope, |
1352 // which is inserted "artificially" in the context chain. | 1380 // which is inserted "artificially" in the context chain. |
1353 class ScopeIterator { | 1381 class ScopeIterator { |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 RUNTIME_FUNCTION(Runtime_ClearStepping) { | 2389 RUNTIME_FUNCTION(Runtime_ClearStepping) { |
2362 HandleScope scope(isolate); | 2390 HandleScope scope(isolate); |
2363 DCHECK(args.length() == 0); | 2391 DCHECK(args.length() == 0); |
2364 isolate->debug()->ClearStepping(); | 2392 isolate->debug()->ClearStepping(); |
2365 return isolate->heap()->undefined_value(); | 2393 return isolate->heap()->undefined_value(); |
2366 } | 2394 } |
2367 | 2395 |
2368 | 2396 |
2369 // Helper function to find or create the arguments object for | 2397 // Helper function to find or create the arguments object for |
2370 // Runtime_DebugEvaluate. | 2398 // Runtime_DebugEvaluate. |
2371 static void MaterializeArgumentsObject(Isolate* isolate, | 2399 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeArgumentsObject( |
2372 Handle<JSObject> target, | 2400 Isolate* isolate, Handle<JSObject> target, Handle<JSFunction> function) { |
2373 Handle<JSFunction> function) { | |
2374 // Do not materialize the arguments object for eval or top-level code. | 2401 // Do not materialize the arguments object for eval or top-level code. |
2375 // Skip if "arguments" is already taken. | 2402 // Skip if "arguments" is already taken. |
2376 if (!function->shared()->is_function()) return; | 2403 if (!function->shared()->is_function()) return target; |
2377 Maybe<bool> maybe = JSReceiver::HasOwnProperty( | 2404 Maybe<bool> maybe = JSReceiver::HasOwnProperty( |
2378 target, isolate->factory()->arguments_string()); | 2405 target, isolate->factory()->arguments_string()); |
2379 DCHECK(maybe.IsJust()); | 2406 if (!maybe.IsJust()) return MaybeHandle<JSObject>(); |
2380 if (maybe.FromJust()) return; | 2407 if (maybe.FromJust()) return target; |
2381 | 2408 |
2382 // FunctionGetArguments can't throw an exception. | 2409 // FunctionGetArguments can't throw an exception. |
2383 Handle<JSObject> arguments = | 2410 Handle<JSObject> arguments = |
2384 Handle<JSObject>::cast(Accessors::FunctionGetArguments(function)); | 2411 Handle<JSObject>::cast(Accessors::FunctionGetArguments(function)); |
2385 Handle<String> arguments_str = isolate->factory()->arguments_string(); | 2412 Handle<String> arguments_str = isolate->factory()->arguments_string(); |
2386 JSObject::SetOwnPropertyIgnoreAttributes(target, arguments_str, arguments, | 2413 RETURN_ON_EXCEPTION(isolate, Runtime::DefineObjectProperty( |
2387 NONE).Check(); | 2414 target, arguments_str, arguments, NONE), |
| 2415 JSObject); |
| 2416 return target; |
2388 } | 2417 } |
2389 | 2418 |
2390 | 2419 |
2391 // Compile and evaluate source for the given context. | 2420 // Compile and evaluate source for the given context. |
2392 static MaybeHandle<Object> DebugEvaluate(Isolate* isolate, | 2421 static MaybeHandle<Object> DebugEvaluate(Isolate* isolate, |
2393 Handle<SharedFunctionInfo> outer_info, | 2422 Handle<SharedFunctionInfo> outer_info, |
2394 Handle<Context> context, | 2423 Handle<Context> context, |
2395 Handle<Object> context_extension, | 2424 Handle<Object> context_extension, |
2396 Handle<Object> receiver, | 2425 Handle<Object> receiver, |
2397 Handle<String> source) { | 2426 Handle<String> source) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2474 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); | 2503 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); |
2475 !it.Failed() && !it.Done() && !stop; it.Next()) { | 2504 !it.Failed() && !it.Done() && !stop; it.Next()) { |
2476 ScopeIterator::ScopeType scope_type = it.Type(); | 2505 ScopeIterator::ScopeType scope_type = it.Type(); |
2477 | 2506 |
2478 if (scope_type == ScopeIterator::ScopeTypeLocal) { | 2507 if (scope_type == ScopeIterator::ScopeTypeLocal) { |
2479 Handle<Context> parent_context = | 2508 Handle<Context> parent_context = |
2480 it.HasContext() ? it.CurrentContext() : outer_context; | 2509 it.HasContext() ? it.CurrentContext() : outer_context; |
2481 | 2510 |
2482 // The "this" binding, if any, can't be bound via "with". If we need | 2511 // The "this" binding, if any, can't be bound via "with". If we need |
2483 // to, add another node onto the outer context to bind "this". | 2512 // to, add another node onto the outer context to bind "this". |
2484 parent_context = | 2513 if (!MaterializeReceiver(isolate, parent_context, function, frame) |
2485 MaterializeReceiver(isolate, parent_context, function, frame); | 2514 .ToHandle(&parent_context)) |
| 2515 return; |
2486 | 2516 |
2487 Handle<JSObject> materialized_function = | 2517 Handle<JSObject> materialized_function = |
2488 NewJSObjectWithNullProto(isolate); | 2518 NewJSObjectWithNullProto(isolate); |
2489 | 2519 |
2490 MaterializeStackLocalsWithFrameInspector(isolate, materialized_function, | 2520 if (!MaterializeStackLocalsWithFrameInspector( |
2491 function, &frame_inspector); | 2521 isolate, materialized_function, function, &frame_inspector) |
| 2522 .ToHandle(&materialized_function)) |
| 2523 return; |
2492 | 2524 |
2493 MaterializeArgumentsObject(isolate, materialized_function, function); | 2525 if (!MaterializeArgumentsObject(isolate, materialized_function, |
| 2526 function) |
| 2527 .ToHandle(&materialized_function)) |
| 2528 return; |
2494 | 2529 |
2495 Handle<Context> with_context = isolate->factory()->NewWithContext( | 2530 Handle<Context> with_context = isolate->factory()->NewWithContext( |
2496 function, parent_context, materialized_function); | 2531 function, parent_context, materialized_function); |
2497 | 2532 |
2498 ContextChainElement context_chain_element; | 2533 ContextChainElement context_chain_element; |
2499 context_chain_element.original_context = it.CurrentContext(); | 2534 context_chain_element.original_context = it.CurrentContext(); |
2500 context_chain_element.materialized_object = materialized_function; | 2535 context_chain_element.materialized_object = materialized_function; |
2501 context_chain_element.scope_info = it.CurrentScopeInfo(); | 2536 context_chain_element.scope_info = it.CurrentScopeInfo(); |
2502 context_chain_.Add(context_chain_element); | 2537 context_chain_.Add(context_chain_element); |
2503 | 2538 |
2504 stop = true; | 2539 stop = true; |
2505 RecordContextsInChain(&inner_context, with_context, with_context); | 2540 RecordContextsInChain(&inner_context, with_context, with_context); |
2506 } else if (scope_type == ScopeIterator::ScopeTypeCatch || | 2541 } else if (scope_type == ScopeIterator::ScopeTypeCatch || |
2507 scope_type == ScopeIterator::ScopeTypeWith) { | 2542 scope_type == ScopeIterator::ScopeTypeWith) { |
2508 Handle<Context> cloned_context = | 2543 Handle<Context> cloned_context = |
2509 Handle<Context>::cast(FixedArray::CopySize( | 2544 Handle<Context>::cast(FixedArray::CopySize( |
2510 it.CurrentContext(), it.CurrentContext()->length())); | 2545 it.CurrentContext(), it.CurrentContext()->length())); |
2511 | 2546 |
2512 ContextChainElement context_chain_element; | 2547 ContextChainElement context_chain_element; |
2513 context_chain_element.original_context = it.CurrentContext(); | 2548 context_chain_element.original_context = it.CurrentContext(); |
2514 context_chain_element.cloned_context = cloned_context; | 2549 context_chain_element.cloned_context = cloned_context; |
2515 context_chain_.Add(context_chain_element); | 2550 context_chain_.Add(context_chain_element); |
2516 | 2551 |
2517 RecordContextsInChain(&inner_context, cloned_context, cloned_context); | 2552 RecordContextsInChain(&inner_context, cloned_context, cloned_context); |
2518 } else if (scope_type == ScopeIterator::ScopeTypeBlock) { | 2553 } else if (scope_type == ScopeIterator::ScopeTypeBlock) { |
2519 Handle<JSObject> materialized_object = | 2554 Handle<JSObject> materialized_object = |
2520 NewJSObjectWithNullProto(isolate); | 2555 NewJSObjectWithNullProto(isolate); |
2521 MaterializeStackLocalsWithFrameInspector(isolate, materialized_object, | 2556 if (!MaterializeStackLocalsWithFrameInspector( |
2522 it.CurrentScopeInfo(), | 2557 isolate, materialized_object, it.CurrentScopeInfo(), |
2523 &frame_inspector); | 2558 &frame_inspector).ToHandle(&materialized_object)) |
| 2559 return; |
2524 if (it.HasContext()) { | 2560 if (it.HasContext()) { |
2525 Handle<Context> cloned_context = | 2561 Handle<Context> cloned_context = |
2526 Handle<Context>::cast(FixedArray::CopySize( | 2562 Handle<Context>::cast(FixedArray::CopySize( |
2527 it.CurrentContext(), it.CurrentContext()->length())); | 2563 it.CurrentContext(), it.CurrentContext()->length())); |
2528 Handle<Context> with_context = isolate->factory()->NewWithContext( | 2564 Handle<Context> with_context = isolate->factory()->NewWithContext( |
2529 function, cloned_context, materialized_object); | 2565 function, cloned_context, materialized_object); |
2530 | 2566 |
2531 ContextChainElement context_chain_element; | 2567 ContextChainElement context_chain_element; |
2532 context_chain_element.original_context = it.CurrentContext(); | 2568 context_chain_element.original_context = it.CurrentContext(); |
2533 context_chain_element.cloned_context = cloned_context; | 2569 context_chain_element.cloned_context = cloned_context; |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3178 return Smi::FromInt(isolate->debug()->is_active()); | 3214 return Smi::FromInt(isolate->debug()->is_active()); |
3179 } | 3215 } |
3180 | 3216 |
3181 | 3217 |
3182 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 3218 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
3183 UNIMPLEMENTED(); | 3219 UNIMPLEMENTED(); |
3184 return NULL; | 3220 return NULL; |
3185 } | 3221 } |
3186 } // namespace internal | 3222 } // namespace internal |
3187 } // namespace v8 | 3223 } // namespace v8 |
OLD | NEW |