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

Side by Side Diff: src/runtime/runtime-debug.cc

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

Powered by Google App Engine
This is Rietveld 408576698