| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 3409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3420 CONVERT_CHECKED(JSFunction, function, args[0]); | 3420 CONVERT_CHECKED(JSFunction, function, args[0]); |
| 3421 int length = ScopeInfo<>::NumberOfContextSlots(function->code()); | 3421 int length = ScopeInfo<>::NumberOfContextSlots(function->code()); |
| 3422 Object* result = Heap::AllocateFunctionContext(length, function); | 3422 Object* result = Heap::AllocateFunctionContext(length, function); |
| 3423 if (result->IsFailure()) return result; | 3423 if (result->IsFailure()) return result; |
| 3424 | 3424 |
| 3425 Top::set_context(Context::cast(result)); | 3425 Top::set_context(Context::cast(result)); |
| 3426 | 3426 |
| 3427 return result; // non-failure | 3427 return result; // non-failure |
| 3428 } | 3428 } |
| 3429 | 3429 |
| 3430 | 3430 static Object* PushContextHelper(Object* object, bool is_catch_context) { |
| 3431 static Object* Runtime_PushContext(Arguments args) { | |
| 3432 NoHandleAllocation ha; | |
| 3433 ASSERT(args.length() == 1); | |
| 3434 | |
| 3435 // Convert the object to a proper JavaScript object. | 3431 // Convert the object to a proper JavaScript object. |
| 3436 Object* object = args[0]; | 3432 Object* js_object = object; |
| 3437 if (!object->IsJSObject()) { | 3433 if (!js_object->IsJSObject()) { |
| 3438 object = object->ToObject(); | 3434 js_object = js_object->ToObject(); |
| 3439 if (object->IsFailure()) { | 3435 if (js_object->IsFailure()) { |
| 3440 if (!Failure::cast(object)->IsInternalError()) return object; | 3436 if (!Failure::cast(js_object)->IsInternalError()) return js_object; |
| 3441 HandleScope scope; | 3437 HandleScope scope; |
| 3442 Handle<Object> handle(args[0]); | 3438 Handle<Object> handle(object); |
| 3443 Handle<Object> result = | 3439 Handle<Object> result = |
| 3444 Factory::NewTypeError("with_expression", HandleVector(&handle, 1)); | 3440 Factory::NewTypeError("with_expression", HandleVector(&handle, 1)); |
| 3445 return Top::Throw(*result); | 3441 return Top::Throw(*result); |
| 3446 } | 3442 } |
| 3447 } | 3443 } |
| 3448 | 3444 |
| 3449 Object* result = | 3445 Object* result = |
| 3450 Heap::AllocateWithContext(Top::context(), JSObject::cast(object)); | 3446 Heap::AllocateWithContext(Top::context(), |
| 3447 JSObject::cast(js_object), |
| 3448 is_catch_context); |
| 3451 if (result->IsFailure()) return result; | 3449 if (result->IsFailure()) return result; |
| 3452 | 3450 |
| 3453 Top::set_context(Context::cast(result)); | 3451 Context* context = Context::cast(result); |
| 3452 Top::set_context(context); |
| 3454 | 3453 |
| 3455 return result; | 3454 return result; |
| 3456 } | 3455 } |
| 3457 | 3456 |
| 3458 | 3457 |
| 3458 static Object* Runtime_PushContext(Arguments args) { |
| 3459 NoHandleAllocation ha; |
| 3460 ASSERT(args.length() == 1); |
| 3461 return PushContextHelper(args[0], false); |
| 3462 } |
| 3463 |
| 3464 |
| 3465 static Object* Runtime_PushCatchContext(Arguments args) { |
| 3466 NoHandleAllocation ha; |
| 3467 ASSERT(args.length() == 1); |
| 3468 return PushContextHelper(args[0], true); |
| 3469 } |
| 3470 |
| 3471 |
| 3459 static Object* Runtime_LookupContext(Arguments args) { | 3472 static Object* Runtime_LookupContext(Arguments args) { |
| 3460 HandleScope scope; | 3473 HandleScope scope; |
| 3461 ASSERT(args.length() == 2); | 3474 ASSERT(args.length() == 2); |
| 3462 | 3475 |
| 3463 CONVERT_ARG_CHECKED(Context, context, 0); | 3476 CONVERT_ARG_CHECKED(Context, context, 0); |
| 3464 CONVERT_ARG_CHECKED(String, name, 1); | 3477 CONVERT_ARG_CHECKED(String, name, 1); |
| 3465 | 3478 |
| 3466 int index; | 3479 int index; |
| 3467 PropertyAttributes attributes; | 3480 PropertyAttributes attributes; |
| 3468 ContextLookupFlags flags = FOLLOW_CHAINS; | 3481 ContextLookupFlags flags = FOLLOW_CHAINS; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3546 Object* value = (holder->IsContext()) | 3559 Object* value = (holder->IsContext()) |
| 3547 ? Context::cast(*holder)->get(index) | 3560 ? Context::cast(*holder)->get(index) |
| 3548 : JSObject::cast(*holder)->GetElement(index); | 3561 : JSObject::cast(*holder)->GetElement(index); |
| 3549 return MakePair(Unhole(value, attributes), receiver); | 3562 return MakePair(Unhole(value, attributes), receiver); |
| 3550 } | 3563 } |
| 3551 | 3564 |
| 3552 // If the holder is found, we read the property from it. | 3565 // If the holder is found, we read the property from it. |
| 3553 if (!holder.is_null() && holder->IsJSObject()) { | 3566 if (!holder.is_null() && holder->IsJSObject()) { |
| 3554 ASSERT(Handle<JSObject>::cast(holder)->HasProperty(*name)); | 3567 ASSERT(Handle<JSObject>::cast(holder)->HasProperty(*name)); |
| 3555 JSObject* object = JSObject::cast(*holder); | 3568 JSObject* object = JSObject::cast(*holder); |
| 3556 JSObject* receiver = (object->IsGlobalObject()) | 3569 JSObject* receiver; |
| 3557 ? GlobalObject::cast(object)->global_receiver() | 3570 if (object->IsGlobalObject()) { |
| 3558 : ComputeReceiverForNonGlobal(object); | 3571 receiver = GlobalObject::cast(object)->global_receiver(); |
| 3572 } else if (context->is_exception_holder(*holder)) { |
| 3573 receiver = Top::context()->global()->global_receiver(); |
| 3574 } else { |
| 3575 receiver = ComputeReceiverForNonGlobal(object); |
| 3576 } |
| 3559 // No need to unhole the value here. This is taken care of by the | 3577 // No need to unhole the value here. This is taken care of by the |
| 3560 // GetProperty function. | 3578 // GetProperty function. |
| 3561 Object* value = object->GetProperty(*name); | 3579 Object* value = object->GetProperty(*name); |
| 3562 return MakePair(value, receiver); | 3580 return MakePair(value, receiver); |
| 3563 } | 3581 } |
| 3564 | 3582 |
| 3565 if (throw_error) { | 3583 if (throw_error) { |
| 3566 // The property doesn't exist - throw exception. | 3584 // The property doesn't exist - throw exception. |
| 3567 Handle<Object> reference_error = | 3585 Handle<Object> reference_error = |
| 3568 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); | 3586 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); |
| (...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5212 Handle<Context> function_context) { | 5230 Handle<Context> function_context) { |
| 5213 // At the bottom of the chain. Return the function context to link to. | 5231 // At the bottom of the chain. Return the function context to link to. |
| 5214 if (context_chain->is_function_context()) { | 5232 if (context_chain->is_function_context()) { |
| 5215 return function_context; | 5233 return function_context; |
| 5216 } | 5234 } |
| 5217 | 5235 |
| 5218 // Recursively copy the with contexts. | 5236 // Recursively copy the with contexts. |
| 5219 Handle<Context> previous(context_chain->previous()); | 5237 Handle<Context> previous(context_chain->previous()); |
| 5220 Handle<JSObject> extension(JSObject::cast(context_chain->extension())); | 5238 Handle<JSObject> extension(JSObject::cast(context_chain->extension())); |
| 5221 return Factory::NewWithContext( | 5239 return Factory::NewWithContext( |
| 5222 CopyWithContextChain(function_context, previous), extension); | 5240 CopyWithContextChain(function_context, previous), |
| 5241 extension, |
| 5242 context_chain->IsCatchContext()); |
| 5223 } | 5243 } |
| 5224 | 5244 |
| 5225 | 5245 |
| 5226 // Helper function to find or create the arguments object for | 5246 // Helper function to find or create the arguments object for |
| 5227 // Runtime_DebugEvaluate. | 5247 // Runtime_DebugEvaluate. |
| 5228 static Handle<Object> GetArgumentsObject(JavaScriptFrame* frame, | 5248 static Handle<Object> GetArgumentsObject(JavaScriptFrame* frame, |
| 5229 Handle<JSFunction> function, | 5249 Handle<JSFunction> function, |
| 5230 Handle<Code> code, | 5250 Handle<Code> code, |
| 5231 const ScopeInfo<>* sinfo, | 5251 const ScopeInfo<>* sinfo, |
| 5232 Handle<Context> function_context) { | 5252 Handle<Context> function_context) { |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5871 } else { | 5891 } else { |
| 5872 // Handle last resort GC and make sure to allow future allocations | 5892 // Handle last resort GC and make sure to allow future allocations |
| 5873 // to grow the heap without causing GCs (if possible). | 5893 // to grow the heap without causing GCs (if possible). |
| 5874 Counters::gc_last_resort_from_js.Increment(); | 5894 Counters::gc_last_resort_from_js.Increment(); |
| 5875 Heap::CollectAllGarbage(); | 5895 Heap::CollectAllGarbage(); |
| 5876 } | 5896 } |
| 5877 } | 5897 } |
| 5878 | 5898 |
| 5879 | 5899 |
| 5880 } } // namespace v8::internal | 5900 } } // namespace v8::internal |
| OLD | NEW |