| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
| (...skipping 9876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9887 Handle<Object> error_message = | 9887 Handle<Object> error_message = |
| 9888 context->ErrorMessageForCodeGenerationFromStrings(); | 9888 context->ErrorMessageForCodeGenerationFromStrings(); |
| 9889 THROW_NEW_ERROR_RETURN_FAILURE( | 9889 THROW_NEW_ERROR_RETURN_FAILURE( |
| 9890 isolate, NewEvalError("code_gen_from_strings", | 9890 isolate, NewEvalError("code_gen_from_strings", |
| 9891 HandleVector<Object>(&error_message, 1))); | 9891 HandleVector<Object>(&error_message, 1))); |
| 9892 } | 9892 } |
| 9893 | 9893 |
| 9894 // Compile source string in the native context. | 9894 // Compile source string in the native context. |
| 9895 ParseRestriction restriction = function_literal_only | 9895 ParseRestriction restriction = function_literal_only |
| 9896 ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION; | 9896 ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION; |
| 9897 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); |
| 9897 Handle<JSFunction> fun; | 9898 Handle<JSFunction> fun; |
| 9898 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 9899 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 9899 isolate, fun, | 9900 isolate, fun, |
| 9900 Compiler::GetFunctionFromEval( | 9901 Compiler::GetFunctionFromEval( |
| 9901 source, context, SLOPPY, restriction, RelocInfo::kNoPosition)); | 9902 source, outer_info, |
| 9903 context, SLOPPY, restriction, RelocInfo::kNoPosition)); |
| 9902 return *fun; | 9904 return *fun; |
| 9903 } | 9905 } |
| 9904 | 9906 |
| 9905 | 9907 |
| 9906 static ObjectPair CompileGlobalEval(Isolate* isolate, | 9908 static ObjectPair CompileGlobalEval(Isolate* isolate, |
| 9907 Handle<String> source, | 9909 Handle<String> source, |
| 9910 Handle<SharedFunctionInfo> outer_info, |
| 9908 Handle<Object> receiver, | 9911 Handle<Object> receiver, |
| 9909 StrictMode strict_mode, | 9912 StrictMode strict_mode, |
| 9910 int scope_position) { | 9913 int scope_position) { |
| 9911 Handle<Context> context = Handle<Context>(isolate->context()); | 9914 Handle<Context> context = Handle<Context>(isolate->context()); |
| 9912 Handle<Context> native_context = Handle<Context>(context->native_context()); | 9915 Handle<Context> native_context = Handle<Context>(context->native_context()); |
| 9913 | 9916 |
| 9914 // Check if native context allows code generation from | 9917 // Check if native context allows code generation from |
| 9915 // strings. Throw an exception if it doesn't. | 9918 // strings. Throw an exception if it doesn't. |
| 9916 if (native_context->allow_code_gen_from_strings()->IsFalse() && | 9919 if (native_context->allow_code_gen_from_strings()->IsFalse() && |
| 9917 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 9920 !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
| 9918 Handle<Object> error_message = | 9921 Handle<Object> error_message = |
| 9919 native_context->ErrorMessageForCodeGenerationFromStrings(); | 9922 native_context->ErrorMessageForCodeGenerationFromStrings(); |
| 9920 Handle<Object> error; | 9923 Handle<Object> error; |
| 9921 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( | 9924 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( |
| 9922 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)); | 9925 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)); |
| 9923 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); | 9926 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); |
| 9924 return MakePair(isolate->heap()->exception(), NULL); | 9927 return MakePair(isolate->heap()->exception(), NULL); |
| 9925 } | 9928 } |
| 9926 | 9929 |
| 9927 // Deal with a normal eval call with a string argument. Compile it | 9930 // Deal with a normal eval call with a string argument. Compile it |
| 9928 // and return the compiled function bound in the local context. | 9931 // and return the compiled function bound in the local context. |
| 9929 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; | 9932 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; |
| 9930 Handle<JSFunction> compiled; | 9933 Handle<JSFunction> compiled; |
| 9931 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 9934 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 9932 isolate, compiled, | 9935 isolate, compiled, |
| 9933 Compiler::GetFunctionFromEval( | 9936 Compiler::GetFunctionFromEval( |
| 9934 source, context, strict_mode, restriction, scope_position), | 9937 source, outer_info, |
| 9938 context, strict_mode, restriction, scope_position), |
| 9935 MakePair(isolate->heap()->exception(), NULL)); | 9939 MakePair(isolate->heap()->exception(), NULL)); |
| 9936 return MakePair(*compiled, *receiver); | 9940 return MakePair(*compiled, *receiver); |
| 9937 } | 9941 } |
| 9938 | 9942 |
| 9939 | 9943 |
| 9940 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ResolvePossiblyDirectEval) { | 9944 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ResolvePossiblyDirectEval) { |
| 9941 HandleScope scope(isolate); | 9945 HandleScope scope(isolate); |
| 9942 DCHECK(args.length() == 5); | 9946 DCHECK(args.length() == 6); |
| 9943 | 9947 |
| 9944 Handle<Object> callee = args.at<Object>(0); | 9948 Handle<Object> callee = args.at<Object>(0); |
| 9945 | 9949 |
| 9946 // If "eval" didn't refer to the original GlobalEval, it's not a | 9950 // If "eval" didn't refer to the original GlobalEval, it's not a |
| 9947 // direct call to eval. | 9951 // direct call to eval. |
| 9948 // (And even if it is, but the first argument isn't a string, just let | 9952 // (And even if it is, but the first argument isn't a string, just let |
| 9949 // execution default to an indirect call to eval, which will also return | 9953 // execution default to an indirect call to eval, which will also return |
| 9950 // the first argument without doing anything). | 9954 // the first argument without doing anything). |
| 9951 if (*callee != isolate->native_context()->global_eval_fun() || | 9955 if (*callee != isolate->native_context()->global_eval_fun() || |
| 9952 !args[1]->IsString()) { | 9956 !args[1]->IsString()) { |
| 9953 return MakePair(*callee, isolate->heap()->undefined_value()); | 9957 return MakePair(*callee, isolate->heap()->undefined_value()); |
| 9954 } | 9958 } |
| 9955 | 9959 |
| 9956 DCHECK(args[3]->IsSmi()); | |
| 9957 DCHECK(args.smi_at(3) == SLOPPY || args.smi_at(3) == STRICT); | |
| 9958 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(3)); | |
| 9959 DCHECK(args[4]->IsSmi()); | 9960 DCHECK(args[4]->IsSmi()); |
| 9961 DCHECK(args.smi_at(4) == SLOPPY || args.smi_at(4) == STRICT); |
| 9962 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(4)); |
| 9963 DCHECK(args[5]->IsSmi()); |
| 9964 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), |
| 9965 isolate); |
| 9960 return CompileGlobalEval(isolate, | 9966 return CompileGlobalEval(isolate, |
| 9961 args.at<String>(1), | 9967 args.at<String>(1), |
| 9962 args.at<Object>(2), | 9968 outer_info, |
| 9969 args.at<Object>(3), |
| 9963 strict_mode, | 9970 strict_mode, |
| 9964 args.smi_at(4)); | 9971 args.smi_at(5)); |
| 9965 } | 9972 } |
| 9966 | 9973 |
| 9967 | 9974 |
| 9968 RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) { | 9975 RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) { |
| 9969 HandleScope scope(isolate); | 9976 HandleScope scope(isolate); |
| 9970 DCHECK(args.length() == 1); | 9977 DCHECK(args.length() == 1); |
| 9971 CONVERT_SMI_ARG_CHECKED(size, 0); | 9978 CONVERT_SMI_ARG_CHECKED(size, 0); |
| 9972 RUNTIME_ASSERT(IsAligned(size, kPointerSize)); | 9979 RUNTIME_ASSERT(IsAligned(size, kPointerSize)); |
| 9973 RUNTIME_ASSERT(size > 0); | 9980 RUNTIME_ASSERT(size > 0); |
| 9974 RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize); | 9981 RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize); |
| (...skipping 2986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12961 RETURN_ON_EXCEPTION( | 12968 RETURN_ON_EXCEPTION( |
| 12962 isolate, | 12969 isolate, |
| 12963 Runtime::DefineObjectProperty(target, arguments_str, arguments, NONE), | 12970 Runtime::DefineObjectProperty(target, arguments_str, arguments, NONE), |
| 12964 JSObject); | 12971 JSObject); |
| 12965 return target; | 12972 return target; |
| 12966 } | 12973 } |
| 12967 | 12974 |
| 12968 | 12975 |
| 12969 // Compile and evaluate source for the given context. | 12976 // Compile and evaluate source for the given context. |
| 12970 static MaybeHandle<Object> DebugEvaluate(Isolate* isolate, | 12977 static MaybeHandle<Object> DebugEvaluate(Isolate* isolate, |
| 12978 Handle<SharedFunctionInfo> outer_info, |
| 12971 Handle<Context> context, | 12979 Handle<Context> context, |
| 12972 Handle<Object> context_extension, | 12980 Handle<Object> context_extension, |
| 12973 Handle<Object> receiver, | 12981 Handle<Object> receiver, |
| 12974 Handle<String> source) { | 12982 Handle<String> source) { |
| 12975 if (context_extension->IsJSObject()) { | 12983 if (context_extension->IsJSObject()) { |
| 12976 Handle<JSObject> extension = Handle<JSObject>::cast(context_extension); | 12984 Handle<JSObject> extension = Handle<JSObject>::cast(context_extension); |
| 12977 Handle<JSFunction> closure(context->closure(), isolate); | 12985 Handle<JSFunction> closure(context->closure(), isolate); |
| 12978 context = isolate->factory()->NewWithContext(closure, context, extension); | 12986 context = isolate->factory()->NewWithContext(closure, context, extension); |
| 12979 } | 12987 } |
| 12980 | 12988 |
| 12981 Handle<JSFunction> eval_fun; | 12989 Handle<JSFunction> eval_fun; |
| 12982 ASSIGN_RETURN_ON_EXCEPTION( | 12990 ASSIGN_RETURN_ON_EXCEPTION( |
| 12983 isolate, eval_fun, | 12991 isolate, eval_fun, |
| 12984 Compiler::GetFunctionFromEval(source, | 12992 Compiler::GetFunctionFromEval(source, |
| 12993 outer_info, |
| 12985 context, | 12994 context, |
| 12986 SLOPPY, | 12995 SLOPPY, |
| 12987 NO_PARSE_RESTRICTION, | 12996 NO_PARSE_RESTRICTION, |
| 12988 RelocInfo::kNoPosition), | 12997 RelocInfo::kNoPosition), |
| 12989 Object); | 12998 Object); |
| 12990 | 12999 |
| 12991 Handle<Object> result; | 13000 Handle<Object> result; |
| 12992 ASSIGN_RETURN_ON_EXCEPTION( | 13001 ASSIGN_RETURN_ON_EXCEPTION( |
| 12993 isolate, result, | 13002 isolate, result, |
| 12994 Execution::Call(isolate, eval_fun, receiver, 0, NULL), | 13003 Execution::Call(isolate, eval_fun, receiver, 0, NULL), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13040 | 13049 |
| 13041 // Handle the processing of break. | 13050 // Handle the processing of break. |
| 13042 DisableBreak disable_break_scope(isolate->debug(), disable_break); | 13051 DisableBreak disable_break_scope(isolate->debug(), disable_break); |
| 13043 | 13052 |
| 13044 // Get the frame where the debugging is performed. | 13053 // Get the frame where the debugging is performed. |
| 13045 StackFrame::Id id = UnwrapFrameId(wrapped_id); | 13054 StackFrame::Id id = UnwrapFrameId(wrapped_id); |
| 13046 JavaScriptFrameIterator it(isolate, id); | 13055 JavaScriptFrameIterator it(isolate, id); |
| 13047 JavaScriptFrame* frame = it.frame(); | 13056 JavaScriptFrame* frame = it.frame(); |
| 13048 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 13057 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
| 13049 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); | 13058 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction())); |
| 13059 Handle<SharedFunctionInfo> outer_info(function->shared()); |
| 13050 | 13060 |
| 13051 // Traverse the saved contexts chain to find the active context for the | 13061 // Traverse the saved contexts chain to find the active context for the |
| 13052 // selected frame. | 13062 // selected frame. |
| 13053 SaveContext* save = FindSavedContextForFrame(isolate, frame); | 13063 SaveContext* save = FindSavedContextForFrame(isolate, frame); |
| 13054 | 13064 |
| 13055 SaveContext savex(isolate); | 13065 SaveContext savex(isolate); |
| 13056 isolate->set_context(*(save->context())); | 13066 isolate->set_context(*(save->context())); |
| 13057 | 13067 |
| 13058 // Evaluate on the context of the frame. | 13068 // Evaluate on the context of the frame. |
| 13059 Handle<Context> context(Context::cast(frame_inspector.GetContext())); | 13069 Handle<Context> context(Context::cast(frame_inspector.GetContext())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 13071 isolate, materialized, | 13081 isolate, materialized, |
| 13072 MaterializeArgumentsObject(isolate, materialized, function)); | 13082 MaterializeArgumentsObject(isolate, materialized, function)); |
| 13073 | 13083 |
| 13074 // Add the materialized object in a with-scope to shadow the stack locals. | 13084 // Add the materialized object in a with-scope to shadow the stack locals. |
| 13075 context = isolate->factory()->NewWithContext(function, context, materialized); | 13085 context = isolate->factory()->NewWithContext(function, context, materialized); |
| 13076 | 13086 |
| 13077 Handle<Object> receiver(frame->receiver(), isolate); | 13087 Handle<Object> receiver(frame->receiver(), isolate); |
| 13078 Handle<Object> result; | 13088 Handle<Object> result; |
| 13079 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 13089 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 13080 isolate, result, | 13090 isolate, result, |
| 13081 DebugEvaluate(isolate, context, context_extension, receiver, source)); | 13091 DebugEvaluate(isolate, outer_info, |
| 13092 context, context_extension, receiver, source)); |
| 13082 | 13093 |
| 13083 // Write back potential changes to materialized stack locals to the stack. | 13094 // Write back potential changes to materialized stack locals to the stack. |
| 13084 UpdateStackLocalsFromMaterializedObject( | 13095 UpdateStackLocalsFromMaterializedObject( |
| 13085 isolate, materialized, function, frame, inlined_jsframe_index); | 13096 isolate, materialized, function, frame, inlined_jsframe_index); |
| 13086 | 13097 |
| 13087 return *result; | 13098 return *result; |
| 13088 } | 13099 } |
| 13089 | 13100 |
| 13090 | 13101 |
| 13091 RUNTIME_FUNCTION(Runtime_DebugEvaluateGlobal) { | 13102 RUNTIME_FUNCTION(Runtime_DebugEvaluateGlobal) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 13111 top = top->prev(); | 13122 top = top->prev(); |
| 13112 } | 13123 } |
| 13113 if (top != NULL) { | 13124 if (top != NULL) { |
| 13114 isolate->set_context(*top->context()); | 13125 isolate->set_context(*top->context()); |
| 13115 } | 13126 } |
| 13116 | 13127 |
| 13117 // Get the native context now set to the top context from before the | 13128 // Get the native context now set to the top context from before the |
| 13118 // debugger was invoked. | 13129 // debugger was invoked. |
| 13119 Handle<Context> context = isolate->native_context(); | 13130 Handle<Context> context = isolate->native_context(); |
| 13120 Handle<JSObject> receiver(context->global_proxy()); | 13131 Handle<JSObject> receiver(context->global_proxy()); |
| 13132 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); |
| 13121 Handle<Object> result; | 13133 Handle<Object> result; |
| 13122 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 13134 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 13123 isolate, result, | 13135 isolate, result, |
| 13124 DebugEvaluate(isolate, context, context_extension, receiver, source)); | 13136 DebugEvaluate(isolate, outer_info, |
| 13137 context, context_extension, receiver, source)); |
| 13125 return *result; | 13138 return *result; |
| 13126 } | 13139 } |
| 13127 | 13140 |
| 13128 | 13141 |
| 13129 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { | 13142 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { |
| 13130 HandleScope scope(isolate); | 13143 HandleScope scope(isolate); |
| 13131 DCHECK(args.length() == 0); | 13144 DCHECK(args.length() == 0); |
| 13132 | 13145 |
| 13133 // Fill the script objects. | 13146 // Fill the script objects. |
| 13134 Handle<FixedArray> instances = isolate->debug()->GetLoadedScripts(); | 13147 Handle<FixedArray> instances = isolate->debug()->GetLoadedScripts(); |
| (...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15749 } | 15762 } |
| 15750 return NULL; | 15763 return NULL; |
| 15751 } | 15764 } |
| 15752 | 15765 |
| 15753 | 15766 |
| 15754 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15767 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 15755 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15768 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 15756 } | 15769 } |
| 15757 | 15770 |
| 15758 } } // namespace v8::internal | 15771 } } // namespace v8::internal |
| OLD | NEW |