OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 // that claims the property is absent. | 1082 // that claims the property is absent. |
1083 | 1083 |
1084 // Check for conflicting re-declarations. We cannot have | 1084 // Check for conflicting re-declarations. We cannot have |
1085 // conflicting types in case of intercepted properties because | 1085 // conflicting types in case of intercepted properties because |
1086 // they are absent. | 1086 // they are absent. |
1087 if (lookup.type() != INTERCEPTOR && | 1087 if (lookup.type() != INTERCEPTOR && |
1088 (lookup.IsReadOnly() || is_const_property)) { | 1088 (lookup.IsReadOnly() || is_const_property)) { |
1089 const char* type = (lookup.IsReadOnly()) ? "const" : "var"; | 1089 const char* type = (lookup.IsReadOnly()) ? "const" : "var"; |
1090 return ThrowRedeclarationError(type, name); | 1090 return ThrowRedeclarationError(type, name); |
1091 } | 1091 } |
1092 Handle<Object> result = SetProperty(global, name, value, attributes); | 1092 RETURN_IF_EMPTY_HANDLE(SetProperty(global, name, value, attributes)); |
1093 if (result.is_null()) { | |
1094 ASSERT(Top::has_pending_exception()); | |
1095 return Failure::Exception(); | |
1096 } | |
1097 } else { | 1093 } else { |
1098 // If a property with this name does not already exist on the | 1094 // If a property with this name does not already exist on the |
1099 // global object add the property locally. We take special | 1095 // global object add the property locally. We take special |
1100 // precautions to always add it as a local property even in case | 1096 // precautions to always add it as a local property even in case |
1101 // of callbacks in the prototype chain (this rules out using | 1097 // of callbacks in the prototype chain (this rules out using |
1102 // SetProperty). Also, we must use the handle-based version to | 1098 // SetProperty). Also, we must use the handle-based version to |
1103 // avoid GC issues. | 1099 // avoid GC issues. |
1104 Handle<Object> result = | 1100 RETURN_IF_EMPTY_HANDLE( |
1105 SetLocalPropertyIgnoreAttributes(global, name, value, attributes); | 1101 SetLocalPropertyIgnoreAttributes(global, name, value, attributes)); |
1106 if (result.is_null()) { | |
1107 ASSERT(Top::has_pending_exception()); | |
1108 return Failure::Exception(); | |
1109 } | |
1110 } | 1102 } |
1111 } | 1103 } |
1112 | 1104 |
1113 ASSERT(!Top::has_pending_exception()); | 1105 ASSERT(!Top::has_pending_exception()); |
1114 return Heap::undefined_value(); | 1106 return Heap::undefined_value(); |
1115 } | 1107 } |
1116 | 1108 |
1117 | 1109 |
1118 static MaybeObject* Runtime_DeclareContextSlot(Arguments args) { | 1110 static MaybeObject* Runtime_DeclareContextSlot(Arguments args) { |
1119 HandleScope scope; | 1111 HandleScope scope; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 } | 1151 } |
1160 } else { | 1152 } else { |
1161 // The holder is an arguments object. | 1153 // The holder is an arguments object. |
1162 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); | 1154 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); |
1163 Handle<Object> result = SetElement(arguments, index, initial_value); | 1155 Handle<Object> result = SetElement(arguments, index, initial_value); |
1164 if (result.is_null()) return Failure::Exception(); | 1156 if (result.is_null()) return Failure::Exception(); |
1165 } | 1157 } |
1166 } else { | 1158 } else { |
1167 // Slow case: The property is not in the FixedArray part of the context. | 1159 // Slow case: The property is not in the FixedArray part of the context. |
1168 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder); | 1160 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder); |
1169 Handle<Object> result = | 1161 RETURN_IF_EMPTY_HANDLE( |
1170 SetProperty(context_ext, name, initial_value, mode); | 1162 SetProperty(context_ext, name, initial_value, mode)); |
1171 if (result.is_null()) return Failure::Exception(); | |
1172 } | 1163 } |
1173 } | 1164 } |
1174 | 1165 |
1175 } else { | 1166 } else { |
1176 // The property is not in the function context. It needs to be | 1167 // The property is not in the function context. It needs to be |
1177 // "declared" in the function context's extension context, or in the | 1168 // "declared" in the function context's extension context, or in the |
1178 // global context. | 1169 // global context. |
1179 Handle<JSObject> context_ext; | 1170 Handle<JSObject> context_ext; |
1180 if (context->has_extension()) { | 1171 if (context->has_extension()) { |
1181 // The function context's extension context exists - use it. | 1172 // The function context's extension context exists - use it. |
1182 context_ext = Handle<JSObject>(context->extension()); | 1173 context_ext = Handle<JSObject>(context->extension()); |
1183 } else { | 1174 } else { |
1184 // The function context's extension context does not exists - allocate | 1175 // The function context's extension context does not exists - allocate |
1185 // it. | 1176 // it. |
1186 context_ext = Factory::NewJSObject(Top::context_extension_function()); | 1177 context_ext = Factory::NewJSObject(Top::context_extension_function()); |
1187 // And store it in the extension slot. | 1178 // And store it in the extension slot. |
1188 context->set_extension(*context_ext); | 1179 context->set_extension(*context_ext); |
1189 } | 1180 } |
1190 ASSERT(*context_ext != NULL); | 1181 ASSERT(*context_ext != NULL); |
1191 | 1182 |
1192 // Declare the property by setting it to the initial value if provided, | 1183 // Declare the property by setting it to the initial value if provided, |
1193 // or undefined, and use the correct mode (e.g. READ_ONLY attribute for | 1184 // or undefined, and use the correct mode (e.g. READ_ONLY attribute for |
1194 // constant declarations). | 1185 // constant declarations). |
1195 ASSERT(!context_ext->HasLocalProperty(*name)); | 1186 ASSERT(!context_ext->HasLocalProperty(*name)); |
1196 Handle<Object> value(Heap::undefined_value()); | 1187 Handle<Object> value(Heap::undefined_value()); |
1197 if (*initial_value != NULL) value = initial_value; | 1188 if (*initial_value != NULL) value = initial_value; |
1198 Handle<Object> result = SetProperty(context_ext, name, value, mode); | 1189 RETURN_IF_EMPTY_HANDLE(SetProperty(context_ext, name, value, mode)); |
1199 if (result.is_null()) return Failure::Exception(); | |
1200 } | 1190 } |
1201 | 1191 |
1202 return Heap::undefined_value(); | 1192 return Heap::undefined_value(); |
1203 } | 1193 } |
1204 | 1194 |
1205 | 1195 |
1206 static MaybeObject* Runtime_InitializeVarGlobal(Arguments args) { | 1196 static MaybeObject* Runtime_InitializeVarGlobal(Arguments args) { |
1207 NoHandleAllocation nha; | 1197 NoHandleAllocation nha; |
1208 | 1198 |
1209 // Determine if we need to assign to the variable if it already | 1199 // Determine if we need to assign to the variable if it already |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 // Throw re-declaration error if the intercepted property is present | 1328 // Throw re-declaration error if the intercepted property is present |
1339 // but not read-only. | 1329 // but not read-only. |
1340 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) { | 1330 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) { |
1341 return ThrowRedeclarationError("var", name); | 1331 return ThrowRedeclarationError("var", name); |
1342 } | 1332 } |
1343 | 1333 |
1344 // Restore global object from context (in case of GC) and continue | 1334 // Restore global object from context (in case of GC) and continue |
1345 // with setting the value because the property is either absent or | 1335 // with setting the value because the property is either absent or |
1346 // read-only. We also have to do redo the lookup. | 1336 // read-only. We also have to do redo the lookup. |
1347 HandleScope handle_scope; | 1337 HandleScope handle_scope; |
1348 Handle<GlobalObject>global(Top::context()->global()); | 1338 Handle<GlobalObject> global(Top::context()->global()); |
1349 | 1339 |
1350 // BUG 1213579: Handle the case where we have to set a read-only | 1340 // BUG 1213575: Handle the case where we have to set a read-only |
1351 // property through an interceptor and only do it if it's | 1341 // property through an interceptor and only do it if it's |
1352 // uninitialized, e.g. the hole. Nirk... | 1342 // uninitialized, e.g. the hole. Nirk... |
1353 SetProperty(global, name, value, attributes); | 1343 RETURN_IF_EMPTY_HANDLE(SetProperty(global, name, value, attributes)); |
1354 return *value; | 1344 return *value; |
1355 } | 1345 } |
1356 | 1346 |
1357 // Set the value, but only we're assigning the initial value to a | 1347 // Set the value, but only we're assigning the initial value to a |
1358 // constant. For now, we determine this by checking if the | 1348 // constant. For now, we determine this by checking if the |
1359 // current value is the hole. | 1349 // current value is the hole. |
1360 PropertyType type = lookup.type(); | 1350 PropertyType type = lookup.type(); |
1361 if (type == FIELD) { | 1351 if (type == FIELD) { |
1362 FixedArray* properties = global->properties(); | 1352 FixedArray* properties = global->properties(); |
1363 int index = lookup.GetFieldIndex(); | 1353 int index = lookup.GetFieldIndex(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1425 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); | 1415 Handle<JSObject> arguments(Handle<JSObject>::cast(holder)); |
1426 SetElement(arguments, index, value); | 1416 SetElement(arguments, index, value); |
1427 } | 1417 } |
1428 return *value; | 1418 return *value; |
1429 } | 1419 } |
1430 | 1420 |
1431 // The property could not be found, we introduce it in the global | 1421 // The property could not be found, we introduce it in the global |
1432 // context. | 1422 // context. |
1433 if (attributes == ABSENT) { | 1423 if (attributes == ABSENT) { |
1434 Handle<JSObject> global = Handle<JSObject>(Top::context()->global()); | 1424 Handle<JSObject> global = Handle<JSObject>(Top::context()->global()); |
1435 SetProperty(global, name, value, NONE); | 1425 RETURN_IF_EMPTY_HANDLE(SetProperty(global, name, value, NONE)); |
1436 return *value; | 1426 return *value; |
1437 } | 1427 } |
1438 | 1428 |
1439 // The property was present in a context extension object. | 1429 // The property was present in a context extension object. |
1440 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder); | 1430 Handle<JSObject> context_ext = Handle<JSObject>::cast(holder); |
1441 | 1431 |
1442 if (*context_ext == context->extension()) { | 1432 if (*context_ext == context->extension()) { |
1443 // This is the property that was introduced by the const | 1433 // This is the property that was introduced by the const |
1444 // declaration. Set it if it hasn't been set before. NOTE: We | 1434 // declaration. Set it if it hasn't been set before. NOTE: We |
1445 // cannot use GetProperty() to get the current value as it | 1435 // cannot use GetProperty() to get the current value as it |
(...skipping 16 matching lines...) Expand all Loading... |
1462 } | 1452 } |
1463 } else { | 1453 } else { |
1464 // We should not reach here. Any real, named property should be | 1454 // We should not reach here. Any real, named property should be |
1465 // either a field or a dictionary slot. | 1455 // either a field or a dictionary slot. |
1466 UNREACHABLE(); | 1456 UNREACHABLE(); |
1467 } | 1457 } |
1468 } else { | 1458 } else { |
1469 // The property was found in a different context extension object. | 1459 // The property was found in a different context extension object. |
1470 // Set it if it is not a read-only property. | 1460 // Set it if it is not a read-only property. |
1471 if ((attributes & READ_ONLY) == 0) { | 1461 if ((attributes & READ_ONLY) == 0) { |
1472 Handle<Object> set = SetProperty(context_ext, name, value, attributes); | 1462 RETURN_IF_EMPTY_HANDLE( |
1473 // Setting a property might throw an exception. Exceptions | 1463 SetProperty(context_ext, name, value, attributes)); |
1474 // are converted to empty handles in handle operations. We | |
1475 // need to convert back to exceptions here. | |
1476 if (set.is_null()) { | |
1477 ASSERT(Top::has_pending_exception()); | |
1478 return Failure::Exception(); | |
1479 } | |
1480 } | 1464 } |
1481 } | 1465 } |
1482 | 1466 |
1483 return *value; | 1467 return *value; |
1484 } | 1468 } |
1485 | 1469 |
1486 | 1470 |
1487 static MaybeObject* Runtime_OptimizeObjectForAddingMultipleProperties( | 1471 static MaybeObject* Runtime_OptimizeObjectForAddingMultipleProperties( |
1488 Arguments args) { | 1472 Arguments args) { |
1489 HandleScope scope; | 1473 HandleScope scope; |
(...skipping 5927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7417 // The property was not found. It needs to be stored in the global context. | 7401 // The property was not found. It needs to be stored in the global context. |
7418 ASSERT(attributes == ABSENT); | 7402 ASSERT(attributes == ABSENT); |
7419 attributes = NONE; | 7403 attributes = NONE; |
7420 context_ext = Handle<JSObject>(Top::context()->global()); | 7404 context_ext = Handle<JSObject>(Top::context()->global()); |
7421 } | 7405 } |
7422 | 7406 |
7423 // Set the property, but ignore if read_only variable on the context | 7407 // Set the property, but ignore if read_only variable on the context |
7424 // extension object itself. | 7408 // extension object itself. |
7425 if ((attributes & READ_ONLY) == 0 || | 7409 if ((attributes & READ_ONLY) == 0 || |
7426 (context_ext->GetLocalPropertyAttribute(*name) == ABSENT)) { | 7410 (context_ext->GetLocalPropertyAttribute(*name) == ABSENT)) { |
7427 Handle<Object> result = SetProperty(context_ext, name, value, NONE); | 7411 RETURN_IF_EMPTY_HANDLE(SetProperty(context_ext, name, value, NONE)); |
7428 if (result.is_null()) { | |
7429 // Failure::Exception is converted to a null handle in the | |
7430 // handle-based methods such as SetProperty. We therefore need | |
7431 // to convert null handles back to exceptions. | |
7432 ASSERT(Top::has_pending_exception()); | |
7433 return Failure::Exception(); | |
7434 } | |
7435 } | 7412 } |
7436 return *value; | 7413 return *value; |
7437 } | 7414 } |
7438 | 7415 |
7439 | 7416 |
7440 static MaybeObject* Runtime_Throw(Arguments args) { | 7417 static MaybeObject* Runtime_Throw(Arguments args) { |
7441 HandleScope scope; | 7418 HandleScope scope; |
7442 ASSERT(args.length() == 1); | 7419 ASSERT(args.length() == 1); |
7443 | 7420 |
7444 return Top::Throw(args[0]); | 7421 return Top::Throw(args[0]); |
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9068 receiver = Factory::ToObject(receiver, calling_frames_global_context); | 9045 receiver = Factory::ToObject(receiver, calling_frames_global_context); |
9069 } | 9046 } |
9070 details->set(kFrameDetailsReceiverIndex, *receiver); | 9047 details->set(kFrameDetailsReceiverIndex, *receiver); |
9071 | 9048 |
9072 ASSERT_EQ(details_size, details_index); | 9049 ASSERT_EQ(details_size, details_index); |
9073 return *Factory::NewJSArrayWithElements(details); | 9050 return *Factory::NewJSArrayWithElements(details); |
9074 } | 9051 } |
9075 | 9052 |
9076 | 9053 |
9077 // Copy all the context locals into an object used to materialize a scope. | 9054 // Copy all the context locals into an object used to materialize a scope. |
9078 static void CopyContextLocalsToScopeObject( | 9055 static bool CopyContextLocalsToScopeObject( |
9079 Handle<SerializedScopeInfo> serialized_scope_info, | 9056 Handle<SerializedScopeInfo> serialized_scope_info, |
9080 ScopeInfo<>& scope_info, | 9057 ScopeInfo<>& scope_info, |
9081 Handle<Context> context, | 9058 Handle<Context> context, |
9082 Handle<JSObject> scope_object) { | 9059 Handle<JSObject> scope_object) { |
9083 // Fill all context locals to the context extension. | 9060 // Fill all context locals to the context extension. |
9084 for (int i = Context::MIN_CONTEXT_SLOTS; | 9061 for (int i = Context::MIN_CONTEXT_SLOTS; |
9085 i < scope_info.number_of_context_slots(); | 9062 i < scope_info.number_of_context_slots(); |
9086 i++) { | 9063 i++) { |
9087 int context_index = serialized_scope_info->ContextSlotIndex( | 9064 int context_index = serialized_scope_info->ContextSlotIndex( |
9088 *scope_info.context_slot_name(i), NULL); | 9065 *scope_info.context_slot_name(i), NULL); |
9089 | 9066 |
9090 // Don't include the arguments shadow (.arguments) context variable. | 9067 // Don't include the arguments shadow (.arguments) context variable. |
9091 if (*scope_info.context_slot_name(i) != Heap::arguments_shadow_symbol()) { | 9068 if (*scope_info.context_slot_name(i) != Heap::arguments_shadow_symbol()) { |
9092 SetProperty(scope_object, | 9069 RETURN_IF_EMPTY_HANDLE_VALUE( |
9093 scope_info.context_slot_name(i), | 9070 SetProperty(scope_object, |
9094 Handle<Object>(context->get(context_index)), NONE); | 9071 scope_info.context_slot_name(i), |
| 9072 Handle<Object>(context->get(context_index)), NONE), |
| 9073 false); |
9095 } | 9074 } |
9096 } | 9075 } |
| 9076 |
| 9077 return true; |
9097 } | 9078 } |
9098 | 9079 |
9099 | 9080 |
9100 // Create a plain JSObject which materializes the local scope for the specified | 9081 // Create a plain JSObject which materializes the local scope for the specified |
9101 // frame. | 9082 // frame. |
9102 static Handle<JSObject> MaterializeLocalScope(JavaScriptFrame* frame) { | 9083 static Handle<JSObject> MaterializeLocalScope(JavaScriptFrame* frame) { |
9103 Handle<JSFunction> function(JSFunction::cast(frame->function())); | 9084 Handle<JSFunction> function(JSFunction::cast(frame->function())); |
9104 Handle<SharedFunctionInfo> shared(function->shared()); | 9085 Handle<SharedFunctionInfo> shared(function->shared()); |
9105 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); | 9086 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); |
9106 ScopeInfo<> scope_info(*serialized_scope_info); | 9087 ScopeInfo<> scope_info(*serialized_scope_info); |
9107 | 9088 |
9108 // Allocate and initialize a JSObject with all the arguments, stack locals | 9089 // Allocate and initialize a JSObject with all the arguments, stack locals |
9109 // heap locals and extension properties of the debugged function. | 9090 // heap locals and extension properties of the debugged function. |
9110 Handle<JSObject> local_scope = Factory::NewJSObject(Top::object_function()); | 9091 Handle<JSObject> local_scope = Factory::NewJSObject(Top::object_function()); |
9111 | 9092 |
9112 // First fill all parameters. | 9093 // First fill all parameters. |
9113 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { | 9094 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { |
9114 SetProperty(local_scope, | 9095 RETURN_IF_EMPTY_HANDLE_VALUE( |
9115 scope_info.parameter_name(i), | 9096 SetProperty(local_scope, |
9116 Handle<Object>(frame->GetParameter(i)), NONE); | 9097 scope_info.parameter_name(i), |
| 9098 Handle<Object>(frame->GetParameter(i)), NONE), |
| 9099 Handle<JSObject>()); |
9117 } | 9100 } |
9118 | 9101 |
9119 // Second fill all stack locals. | 9102 // Second fill all stack locals. |
9120 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) { | 9103 for (int i = 0; i < scope_info.number_of_stack_slots(); i++) { |
9121 SetProperty(local_scope, | 9104 RETURN_IF_EMPTY_HANDLE_VALUE( |
9122 scope_info.stack_slot_name(i), | 9105 SetProperty(local_scope, |
9123 Handle<Object>(frame->GetExpression(i)), NONE); | 9106 scope_info.stack_slot_name(i), |
| 9107 Handle<Object>(frame->GetExpression(i)), NONE), |
| 9108 Handle<JSObject>()); |
9124 } | 9109 } |
9125 | 9110 |
9126 // Third fill all context locals. | 9111 // Third fill all context locals. |
9127 Handle<Context> frame_context(Context::cast(frame->context())); | 9112 Handle<Context> frame_context(Context::cast(frame->context())); |
9128 Handle<Context> function_context(frame_context->fcontext()); | 9113 Handle<Context> function_context(frame_context->fcontext()); |
9129 CopyContextLocalsToScopeObject(serialized_scope_info, scope_info, | 9114 if (!CopyContextLocalsToScopeObject(serialized_scope_info, scope_info, |
9130 function_context, local_scope); | 9115 function_context, local_scope)) { |
| 9116 return Handle<JSObject>(); |
| 9117 } |
9131 | 9118 |
9132 // Finally copy any properties from the function context extension. This will | 9119 // Finally copy any properties from the function context extension. This will |
9133 // be variables introduced by eval. | 9120 // be variables introduced by eval. |
9134 if (function_context->closure() == *function) { | 9121 if (function_context->closure() == *function) { |
9135 if (function_context->has_extension() && | 9122 if (function_context->has_extension() && |
9136 !function_context->IsGlobalContext()) { | 9123 !function_context->IsGlobalContext()) { |
9137 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 9124 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
9138 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); | 9125 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); |
9139 for (int i = 0; i < keys->length(); i++) { | 9126 for (int i = 0; i < keys->length(); i++) { |
9140 // Names of variables introduced by eval are strings. | 9127 // Names of variables introduced by eval are strings. |
9141 ASSERT(keys->get(i)->IsString()); | 9128 ASSERT(keys->get(i)->IsString()); |
9142 Handle<String> key(String::cast(keys->get(i))); | 9129 Handle<String> key(String::cast(keys->get(i))); |
9143 SetProperty(local_scope, key, GetProperty(ext, key), NONE); | 9130 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 9131 SetProperty(local_scope, key, GetProperty(ext, key), NONE), |
| 9132 Handle<JSObject>()); |
9144 } | 9133 } |
9145 } | 9134 } |
9146 } | 9135 } |
9147 return local_scope; | 9136 return local_scope; |
9148 } | 9137 } |
9149 | 9138 |
9150 | 9139 |
9151 // Create a plain JSObject which materializes the closure content for the | 9140 // Create a plain JSObject which materializes the closure content for the |
9152 // context. | 9141 // context. |
9153 static Handle<JSObject> MaterializeClosure(Handle<Context> context) { | 9142 static Handle<JSObject> MaterializeClosure(Handle<Context> context) { |
(...skipping 12 matching lines...) Expand all Loading... |
9166 shared->scope_info()->ContextSlotIndex(Heap::arguments_shadow_symbol(), | 9155 shared->scope_info()->ContextSlotIndex(Heap::arguments_shadow_symbol(), |
9167 NULL); | 9156 NULL); |
9168 if (arguments_shadow_index >= 0) { | 9157 if (arguments_shadow_index >= 0) { |
9169 // In this case all the arguments are available in the arguments shadow | 9158 // In this case all the arguments are available in the arguments shadow |
9170 // object. | 9159 // object. |
9171 Handle<JSObject> arguments_shadow( | 9160 Handle<JSObject> arguments_shadow( |
9172 JSObject::cast(context->get(arguments_shadow_index))); | 9161 JSObject::cast(context->get(arguments_shadow_index))); |
9173 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { | 9162 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { |
9174 // We don't expect exception-throwing getters on the arguments shadow. | 9163 // We don't expect exception-throwing getters on the arguments shadow. |
9175 Object* element = arguments_shadow->GetElement(i)->ToObjectUnchecked(); | 9164 Object* element = arguments_shadow->GetElement(i)->ToObjectUnchecked(); |
9176 SetProperty(closure_scope, | 9165 RETURN_IF_EMPTY_HANDLE_VALUE( |
9177 scope_info.parameter_name(i), | 9166 SetProperty(closure_scope, |
9178 Handle<Object>(element), | 9167 scope_info.parameter_name(i), |
9179 NONE); | 9168 Handle<Object>(element), |
| 9169 NONE), |
| 9170 Handle<JSObject>()); |
9180 } | 9171 } |
9181 } | 9172 } |
9182 | 9173 |
9183 // Fill all context locals to the context extension. | 9174 // Fill all context locals to the context extension. |
9184 CopyContextLocalsToScopeObject(serialized_scope_info, scope_info, | 9175 if (!CopyContextLocalsToScopeObject(serialized_scope_info, scope_info, |
9185 context, closure_scope); | 9176 context, closure_scope)) { |
| 9177 return Handle<JSObject>(); |
| 9178 } |
9186 | 9179 |
9187 // Finally copy any properties from the function context extension. This will | 9180 // Finally copy any properties from the function context extension. This will |
9188 // be variables introduced by eval. | 9181 // be variables introduced by eval. |
9189 if (context->has_extension()) { | 9182 if (context->has_extension()) { |
9190 Handle<JSObject> ext(JSObject::cast(context->extension())); | 9183 Handle<JSObject> ext(JSObject::cast(context->extension())); |
9191 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); | 9184 Handle<FixedArray> keys = GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS); |
9192 for (int i = 0; i < keys->length(); i++) { | 9185 for (int i = 0; i < keys->length(); i++) { |
9193 // Names of variables introduced by eval are strings. | 9186 // Names of variables introduced by eval are strings. |
9194 ASSERT(keys->get(i)->IsString()); | 9187 ASSERT(keys->get(i)->IsString()); |
9195 Handle<String> key(String::cast(keys->get(i))); | 9188 Handle<String> key(String::cast(keys->get(i))); |
9196 SetProperty(closure_scope, key, GetProperty(ext, key), NONE); | 9189 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 9190 SetProperty(closure_scope, key, GetProperty(ext, key), NONE), |
| 9191 Handle<JSObject>()); |
9197 } | 9192 } |
9198 } | 9193 } |
9199 | 9194 |
9200 return closure_scope; | 9195 return closure_scope; |
9201 } | 9196 } |
9202 | 9197 |
9203 | 9198 |
9204 // Iterate over the actual scopes visible from a stack frame. All scopes are | 9199 // Iterate over the actual scopes visible from a stack frame. All scopes are |
9205 // backed by an actual context except the local scope, which is inserted | 9200 // backed by an actual context except the local scope, which is inserted |
9206 // "artifically" in the context chain. | 9201 // "artifically" in the context chain. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9473 return Heap::undefined_value(); | 9468 return Heap::undefined_value(); |
9474 } | 9469 } |
9475 | 9470 |
9476 // Calculate the size of the result. | 9471 // Calculate the size of the result. |
9477 int details_size = kScopeDetailsSize; | 9472 int details_size = kScopeDetailsSize; |
9478 Handle<FixedArray> details = Factory::NewFixedArray(details_size); | 9473 Handle<FixedArray> details = Factory::NewFixedArray(details_size); |
9479 | 9474 |
9480 // Fill in scope details. | 9475 // Fill in scope details. |
9481 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type())); | 9476 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type())); |
9482 Handle<JSObject> scope_object = it.ScopeObject(); | 9477 Handle<JSObject> scope_object = it.ScopeObject(); |
| 9478 RETURN_IF_EMPTY_HANDLE(scope_object); |
9483 details->set(kScopeDetailsObjectIndex, *scope_object); | 9479 details->set(kScopeDetailsObjectIndex, *scope_object); |
9484 | 9480 |
9485 return *Factory::NewJSArrayWithElements(details); | 9481 return *Factory::NewJSArrayWithElements(details); |
9486 } | 9482 } |
9487 | 9483 |
9488 | 9484 |
9489 static MaybeObject* Runtime_DebugPrintScopes(Arguments args) { | 9485 static MaybeObject* Runtime_DebugPrintScopes(Arguments args) { |
9490 HandleScope scope; | 9486 HandleScope scope; |
9491 ASSERT(args.length() == 0); | 9487 ASSERT(args.length() == 0); |
9492 | 9488 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9954 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value()); | 9950 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value()); |
9955 go_between->set_context(function->context()); | 9951 go_between->set_context(function->context()); |
9956 #ifdef DEBUG | 9952 #ifdef DEBUG |
9957 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info()); | 9953 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info()); |
9958 ASSERT(go_between_sinfo.number_of_parameters() == 0); | 9954 ASSERT(go_between_sinfo.number_of_parameters() == 0); |
9959 ASSERT(go_between_sinfo.number_of_context_slots() == 0); | 9955 ASSERT(go_between_sinfo.number_of_context_slots() == 0); |
9960 #endif | 9956 #endif |
9961 | 9957 |
9962 // Materialize the content of the local scope into a JSObject. | 9958 // Materialize the content of the local scope into a JSObject. |
9963 Handle<JSObject> local_scope = MaterializeLocalScope(frame); | 9959 Handle<JSObject> local_scope = MaterializeLocalScope(frame); |
| 9960 RETURN_IF_EMPTY_HANDLE(local_scope); |
9964 | 9961 |
9965 // Allocate a new context for the debug evaluation and set the extension | 9962 // Allocate a new context for the debug evaluation and set the extension |
9966 // object build. | 9963 // object build. |
9967 Handle<Context> context = | 9964 Handle<Context> context = |
9968 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); | 9965 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); |
9969 context->set_extension(*local_scope); | 9966 context->set_extension(*local_scope); |
9970 // Copy any with contexts present and chain them in front of this context. | 9967 // Copy any with contexts present and chain them in front of this context. |
9971 Handle<Context> frame_context(Context::cast(frame->context())); | 9968 Handle<Context> frame_context(Context::cast(frame->context())); |
9972 Handle<Context> function_context(frame_context->fcontext()); | 9969 Handle<Context> function_context(frame_context->fcontext()); |
9973 context = CopyWithContextChain(frame_context, context); | 9970 context = CopyWithContextChain(frame_context, context); |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11101 } else { | 11098 } else { |
11102 // Handle last resort GC and make sure to allow future allocations | 11099 // Handle last resort GC and make sure to allow future allocations |
11103 // to grow the heap without causing GCs (if possible). | 11100 // to grow the heap without causing GCs (if possible). |
11104 Counters::gc_last_resort_from_js.Increment(); | 11101 Counters::gc_last_resort_from_js.Increment(); |
11105 Heap::CollectAllGarbage(false); | 11102 Heap::CollectAllGarbage(false); |
11106 } | 11103 } |
11107 } | 11104 } |
11108 | 11105 |
11109 | 11106 |
11110 } } // namespace v8::internal | 11107 } } // namespace v8::internal |
OLD | NEW |