| 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 2133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 | 2144 |
| 2145 // Handle special arguments properties. | 2145 // Handle special arguments properties. |
| 2146 if (key->Equals(Heap::length_symbol())) return Smi::FromInt(n); | 2146 if (key->Equals(Heap::length_symbol())) return Smi::FromInt(n); |
| 2147 if (key->Equals(Heap::callee_symbol())) return frame->function(); | 2147 if (key->Equals(Heap::callee_symbol())) return frame->function(); |
| 2148 | 2148 |
| 2149 // Lookup in the initial Object.prototype object. | 2149 // Lookup in the initial Object.prototype object. |
| 2150 return Top::initial_object_prototype()->GetProperty(*key); | 2150 return Top::initial_object_prototype()->GetProperty(*key); |
| 2151 } | 2151 } |
| 2152 | 2152 |
| 2153 | 2153 |
| 2154 static Object* Runtime_ToFastProperties(Arguments args) { |
| 2155 ASSERT(args.length() == 1); |
| 2156 CONVERT_ARG_CHECKED(JSObject, object, 0); |
| 2157 object->TransformToFastProperties(0); |
| 2158 return *object; |
| 2159 } |
| 2160 |
| 2161 |
| 2162 static Object* Runtime_ToSlowProperties(Arguments args) { |
| 2163 ASSERT(args.length() == 1); |
| 2164 CONVERT_ARG_CHECKED(JSObject, object, 0); |
| 2165 object->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES); |
| 2166 return *object; |
| 2167 } |
| 2168 |
| 2169 |
| 2154 static Object* Runtime_ToBool(Arguments args) { | 2170 static Object* Runtime_ToBool(Arguments args) { |
| 2155 NoHandleAllocation ha; | 2171 NoHandleAllocation ha; |
| 2156 ASSERT(args.length() == 1); | 2172 ASSERT(args.length() == 1); |
| 2157 | 2173 |
| 2158 return args[0]->ToBoolean(); | 2174 return args[0]->ToBoolean(); |
| 2159 } | 2175 } |
| 2160 | 2176 |
| 2161 | 2177 |
| 2162 // Returns the type string of a value; see ECMA-262, 11.4.3 (p 47). | 2178 // Returns the type string of a value; see ECMA-262, 11.4.3 (p 47). |
| 2163 // Possible optimizations: put the type string into the oddballs. | 2179 // Possible optimizations: put the type string into the oddballs. |
| (...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4000 return JSGlobalObject::cast(global)->global_receiver(); | 4016 return JSGlobalObject::cast(global)->global_receiver(); |
| 4001 } | 4017 } |
| 4002 | 4018 |
| 4003 | 4019 |
| 4004 static Object* Runtime_CompileString(Arguments args) { | 4020 static Object* Runtime_CompileString(Arguments args) { |
| 4005 HandleScope scope; | 4021 HandleScope scope; |
| 4006 ASSERT(args.length() == 2); | 4022 ASSERT(args.length() == 2); |
| 4007 CONVERT_ARG_CHECKED(String, source, 0); | 4023 CONVERT_ARG_CHECKED(String, source, 0); |
| 4008 CONVERT_ARG_CHECKED(Smi, line_offset, 1); | 4024 CONVERT_ARG_CHECKED(Smi, line_offset, 1); |
| 4009 | 4025 |
| 4010 // Compile source string. | 4026 // Compile source string in the global context. |
| 4027 Handle<Context> context(Top::context()->global_context()); |
| 4011 Handle<JSFunction> boilerplate = | 4028 Handle<JSFunction> boilerplate = |
| 4012 Compiler::CompileEval(source, line_offset->value(), true); | 4029 Compiler::CompileEval(source, context, line_offset->value(), true); |
| 4013 if (boilerplate.is_null()) return Failure::Exception(); | 4030 if (boilerplate.is_null()) return Failure::Exception(); |
| 4014 Handle<Context> context(Top::context()->global_context()); | |
| 4015 Handle<JSFunction> fun = | 4031 Handle<JSFunction> fun = |
| 4016 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 4032 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
| 4017 return *fun; | 4033 return *fun; |
| 4018 } | 4034 } |
| 4019 | 4035 |
| 4020 | 4036 |
| 4021 static Handle<JSFunction> GetBuiltinFunction(String* name) { | 4037 static Handle<JSFunction> GetBuiltinFunction(String* name) { |
| 4022 LookupResult result; | 4038 LookupResult result; |
| 4023 Top::global_context()->builtins()->LocalLookup(name, &result); | 4039 Top::global_context()->builtins()->LocalLookup(name, &result); |
| 4024 return Handle<JSFunction>(JSFunction::cast(result.GetValue())); | 4040 return Handle<JSFunction>(JSFunction::cast(result.GetValue())); |
| 4025 } | 4041 } |
| 4026 | 4042 |
| 4027 | 4043 |
| 4028 static Object* CompileDirectEval(Handle<String> source) { | 4044 static Object* CompileDirectEval(Handle<String> source) { |
| 4029 // Compute the eval context. | 4045 // Compute the eval context. |
| 4030 HandleScope scope; | 4046 HandleScope scope; |
| 4031 StackFrameLocator locator; | 4047 StackFrameLocator locator; |
| 4032 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); | 4048 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); |
| 4033 Handle<Context> context(Context::cast(frame->context())); | 4049 Handle<Context> context(Context::cast(frame->context())); |
| 4034 bool is_global = context->IsGlobalContext(); | 4050 bool is_global = context->IsGlobalContext(); |
| 4035 | 4051 |
| 4036 // Compile source string. | 4052 // Compile source string in the current context. |
| 4037 Handle<JSFunction> boilerplate = Compiler::CompileEval(source, 0, is_global); | 4053 Handle<JSFunction> boilerplate = |
| 4054 Compiler::CompileEval(source, context, 0, is_global); |
| 4038 if (boilerplate.is_null()) return Failure::Exception(); | 4055 if (boilerplate.is_null()) return Failure::Exception(); |
| 4039 Handle<JSFunction> fun = | 4056 Handle<JSFunction> fun = |
| 4040 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 4057 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
| 4041 return *fun; | 4058 return *fun; |
| 4042 } | 4059 } |
| 4043 | 4060 |
| 4044 | 4061 |
| 4045 static Object* Runtime_ResolvePossiblyDirectEval(Arguments args) { | 4062 static Object* Runtime_ResolvePossiblyDirectEval(Arguments args) { |
| 4046 ASSERT(args.length() == 2); | 4063 ASSERT(args.length() == 2); |
| 4047 | 4064 |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5007 SaveContext* save = Top::save_context(); | 5024 SaveContext* save = Top::save_context(); |
| 5008 while (save != NULL && !save->below(it.frame())) { | 5025 while (save != NULL && !save->below(it.frame())) { |
| 5009 save = save->prev(); | 5026 save = save->prev(); |
| 5010 } | 5027 } |
| 5011 ASSERT(save != NULL); | 5028 ASSERT(save != NULL); |
| 5012 | 5029 |
| 5013 // Get the frame id. | 5030 // Get the frame id. |
| 5014 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); | 5031 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); |
| 5015 | 5032 |
| 5016 // Find source position. | 5033 // Find source position. |
| 5017 int position = it.frame()->FindCode()->SourcePosition(it.frame()->pc()); | 5034 int position = it.frame()->code()->SourcePosition(it.frame()->pc()); |
| 5018 | 5035 |
| 5019 // Check for constructor frame. | 5036 // Check for constructor frame. |
| 5020 bool constructor = it.frame()->IsConstructor(); | 5037 bool constructor = it.frame()->IsConstructor(); |
| 5021 | 5038 |
| 5022 // Get code and read scope info from it for local variable information. | 5039 // Get code and read scope info from it for local variable information. |
| 5023 Handle<Code> code(it.frame()->FindCode()); | 5040 Handle<Code> code(it.frame()->code()); |
| 5024 ScopeInfo<> info(*code); | 5041 ScopeInfo<> info(*code); |
| 5025 | 5042 |
| 5026 // Get the context. | 5043 // Get the context. |
| 5027 Handle<Context> context(Context::cast(it.frame()->context())); | 5044 Handle<Context> context(Context::cast(it.frame()->context())); |
| 5028 | 5045 |
| 5029 // Get the locals names and values into a temporary array. | 5046 // Get the locals names and values into a temporary array. |
| 5030 // | 5047 // |
| 5031 // TODO(1240907): Hide compiler-introduced stack variables | 5048 // TODO(1240907): Hide compiler-introduced stack variables |
| 5032 // (e.g. .result)? For users of the debugger, they will probably be | 5049 // (e.g. .result)? For users of the debugger, they will probably be |
| 5033 // confusing. | 5050 // confusing. |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5587 // 'arguments'. This it to have access to what would have been 'arguments' in | 5604 // 'arguments'. This it to have access to what would have been 'arguments' in |
| 5588 // the function being debugged. | 5605 // the function being debugged. |
| 5589 // function(arguments,__source__) {return eval(__source__);} | 5606 // function(arguments,__source__) {return eval(__source__);} |
| 5590 static const char* source_str = | 5607 static const char* source_str = |
| 5591 "function(arguments,__source__){return eval(__source__);}"; | 5608 "function(arguments,__source__){return eval(__source__);}"; |
| 5592 static const int source_str_length = strlen(source_str); | 5609 static const int source_str_length = strlen(source_str); |
| 5593 Handle<String> function_source = | 5610 Handle<String> function_source = |
| 5594 Factory::NewStringFromAscii(Vector<const char>(source_str, | 5611 Factory::NewStringFromAscii(Vector<const char>(source_str, |
| 5595 source_str_length)); | 5612 source_str_length)); |
| 5596 Handle<JSFunction> boilerplate = | 5613 Handle<JSFunction> boilerplate = |
| 5597 Compiler::CompileEval(function_source, 0, context->IsGlobalContext()); | 5614 Compiler::CompileEval(function_source, |
| 5615 context, |
| 5616 0, |
| 5617 context->IsGlobalContext()); |
| 5598 if (boilerplate.is_null()) return Failure::Exception(); | 5618 if (boilerplate.is_null()) return Failure::Exception(); |
| 5599 Handle<JSFunction> compiled_function = | 5619 Handle<JSFunction> compiled_function = |
| 5600 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 5620 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
| 5601 | 5621 |
| 5602 // Invoke the result of the compilation to get the evaluation function. | 5622 // Invoke the result of the compilation to get the evaluation function. |
| 5603 bool has_pending_exception; | 5623 bool has_pending_exception; |
| 5604 Handle<Object> receiver(frame->receiver()); | 5624 Handle<Object> receiver(frame->receiver()); |
| 5605 Handle<Object> evaluation_function = | 5625 Handle<Object> evaluation_function = |
| 5606 Execution::Call(compiled_function, receiver, 0, NULL, | 5626 Execution::Call(compiled_function, receiver, 0, NULL, |
| 5607 &has_pending_exception); | 5627 &has_pending_exception); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5644 } | 5664 } |
| 5645 if (top != NULL) { | 5665 if (top != NULL) { |
| 5646 Top::set_context(*top->context()); | 5666 Top::set_context(*top->context()); |
| 5647 } | 5667 } |
| 5648 | 5668 |
| 5649 // Get the global context now set to the top context from before the | 5669 // Get the global context now set to the top context from before the |
| 5650 // debugger was invoked. | 5670 // debugger was invoked. |
| 5651 Handle<Context> context = Top::global_context(); | 5671 Handle<Context> context = Top::global_context(); |
| 5652 | 5672 |
| 5653 // Compile the source to be evaluated. | 5673 // Compile the source to be evaluated. |
| 5654 Handle<JSFunction> boilerplate(Compiler::CompileEval(source, 0, true)); | 5674 Handle<JSFunction> boilerplate = |
| 5675 Handle<JSFunction>(Compiler::CompileEval(source, context, 0, true)); |
| 5655 if (boilerplate.is_null()) return Failure::Exception(); | 5676 if (boilerplate.is_null()) return Failure::Exception(); |
| 5656 Handle<JSFunction> compiled_function = | 5677 Handle<JSFunction> compiled_function = |
| 5657 Handle<JSFunction>(Factory::NewFunctionFromBoilerplate(boilerplate, | 5678 Handle<JSFunction>(Factory::NewFunctionFromBoilerplate(boilerplate, |
| 5658 context)); | 5679 context)); |
| 5659 | 5680 |
| 5660 // Invoke the result of the compilation to get the evaluation function. | 5681 // Invoke the result of the compilation to get the evaluation function. |
| 5661 bool has_pending_exception; | 5682 bool has_pending_exception; |
| 5662 Handle<Object> receiver = Top::global(); | 5683 Handle<Object> receiver = Top::global(); |
| 5663 Handle<Object> result = | 5684 Handle<Object> result = |
| 5664 Execution::Call(compiled_function, receiver, 0, NULL, | 5685 Execution::Call(compiled_function, receiver, 0, NULL, |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6091 } else { | 6112 } else { |
| 6092 // Handle last resort GC and make sure to allow future allocations | 6113 // Handle last resort GC and make sure to allow future allocations |
| 6093 // to grow the heap without causing GCs (if possible). | 6114 // to grow the heap without causing GCs (if possible). |
| 6094 Counters::gc_last_resort_from_js.Increment(); | 6115 Counters::gc_last_resort_from_js.Increment(); |
| 6095 Heap::CollectAllGarbage(); | 6116 Heap::CollectAllGarbage(); |
| 6096 } | 6117 } |
| 6097 } | 6118 } |
| 6098 | 6119 |
| 6099 | 6120 |
| 6100 } } // namespace v8::internal | 6121 } } // namespace v8::internal |
| OLD | NEW |