OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 6914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6925 | 6925 |
6926 | 6926 |
6927 static Object* Runtime_GlobalReceiver(Arguments args) { | 6927 static Object* Runtime_GlobalReceiver(Arguments args) { |
6928 ASSERT(args.length() == 1); | 6928 ASSERT(args.length() == 1); |
6929 Object* global = args[0]; | 6929 Object* global = args[0]; |
6930 if (!global->IsJSGlobalObject()) return Heap::null_value(); | 6930 if (!global->IsJSGlobalObject()) return Heap::null_value(); |
6931 return JSGlobalObject::cast(global)->global_receiver(); | 6931 return JSGlobalObject::cast(global)->global_receiver(); |
6932 } | 6932 } |
6933 | 6933 |
6934 | 6934 |
| 6935 static Object* Runtime_ParseJson(Arguments args) { |
| 6936 HandleScope scope; |
| 6937 ASSERT_EQ(1, args.length()); |
| 6938 CONVERT_ARG_CHECKED(String, source, 0); |
| 6939 |
| 6940 Handle<Object> result = JsonParser::Parse(source); |
| 6941 if (result.is_null()) { |
| 6942 // Syntax error or stack overflow in scanner. |
| 6943 ASSERT(Top::has_pending_exception()); |
| 6944 return Failure::Exception(); |
| 6945 } |
| 6946 return *result; |
| 6947 } |
| 6948 |
| 6949 |
6935 static Object* Runtime_CompileString(Arguments args) { | 6950 static Object* Runtime_CompileString(Arguments args) { |
6936 HandleScope scope; | 6951 HandleScope scope; |
6937 ASSERT_EQ(2, args.length()); | 6952 ASSERT_EQ(1, args.length()); |
6938 CONVERT_ARG_CHECKED(String, source, 0); | 6953 CONVERT_ARG_CHECKED(String, source, 0); |
6939 CONVERT_ARG_CHECKED(Oddball, is_json, 1) | |
6940 | 6954 |
6941 // Compile source string in the global context. | 6955 // Compile source string in the global context. |
6942 Handle<Context> context(Top::context()->global_context()); | 6956 Handle<Context> context(Top::context()->global_context()); |
6943 Compiler::ValidationState validate = (is_json->IsTrue()) | |
6944 ? Compiler::VALIDATE_JSON : Compiler::DONT_VALIDATE_JSON; | |
6945 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, | 6957 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, |
6946 context, | 6958 context, |
6947 true, | 6959 true); |
6948 validate); | |
6949 if (shared.is_null()) return Failure::Exception(); | 6960 if (shared.is_null()) return Failure::Exception(); |
6950 Handle<JSFunction> fun = | 6961 Handle<JSFunction> fun = |
6951 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED); | 6962 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED); |
6952 return *fun; | 6963 return *fun; |
6953 } | 6964 } |
6954 | 6965 |
6955 | 6966 |
6956 static ObjectPair CompileGlobalEval(Handle<String> source, | 6967 static ObjectPair CompileGlobalEval(Handle<String> source, |
6957 Handle<Object> receiver) { | 6968 Handle<Object> receiver) { |
6958 // Deal with a normal eval call with a string argument. Compile it | 6969 // Deal with a normal eval call with a string argument. Compile it |
6959 // and return the compiled function bound in the local context. | 6970 // and return the compiled function bound in the local context. |
6960 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 6971 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
6961 source, | 6972 source, |
6962 Handle<Context>(Top::context()), | 6973 Handle<Context>(Top::context()), |
6963 Top::context()->IsGlobalContext(), | 6974 Top::context()->IsGlobalContext()); |
6964 Compiler::DONT_VALIDATE_JSON); | |
6965 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); | 6975 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); |
6966 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo( | 6976 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo( |
6967 shared, | 6977 shared, |
6968 Handle<Context>(Top::context()), | 6978 Handle<Context>(Top::context()), |
6969 NOT_TENURED); | 6979 NOT_TENURED); |
6970 return MakePair(*compiled, *receiver); | 6980 return MakePair(*compiled, *receiver); |
6971 } | 6981 } |
6972 | 6982 |
6973 | 6983 |
6974 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { | 6984 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { |
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9157 // function(arguments,__source__) {return eval(__source__);} | 9167 // function(arguments,__source__) {return eval(__source__);} |
9158 static const char* source_str = | 9168 static const char* source_str = |
9159 "(function(arguments,__source__){return eval(__source__);})"; | 9169 "(function(arguments,__source__){return eval(__source__);})"; |
9160 static const int source_str_length = StrLength(source_str); | 9170 static const int source_str_length = StrLength(source_str); |
9161 Handle<String> function_source = | 9171 Handle<String> function_source = |
9162 Factory::NewStringFromAscii(Vector<const char>(source_str, | 9172 Factory::NewStringFromAscii(Vector<const char>(source_str, |
9163 source_str_length)); | 9173 source_str_length)); |
9164 Handle<SharedFunctionInfo> shared = | 9174 Handle<SharedFunctionInfo> shared = |
9165 Compiler::CompileEval(function_source, | 9175 Compiler::CompileEval(function_source, |
9166 context, | 9176 context, |
9167 context->IsGlobalContext(), | 9177 context->IsGlobalContext()); |
9168 Compiler::DONT_VALIDATE_JSON); | |
9169 if (shared.is_null()) return Failure::Exception(); | 9178 if (shared.is_null()) return Failure::Exception(); |
9170 Handle<JSFunction> compiled_function = | 9179 Handle<JSFunction> compiled_function = |
9171 Factory::NewFunctionFromSharedFunctionInfo(shared, context); | 9180 Factory::NewFunctionFromSharedFunctionInfo(shared, context); |
9172 | 9181 |
9173 // Invoke the result of the compilation to get the evaluation function. | 9182 // Invoke the result of the compilation to get the evaluation function. |
9174 bool has_pending_exception; | 9183 bool has_pending_exception; |
9175 Handle<Object> receiver(frame->receiver()); | 9184 Handle<Object> receiver(frame->receiver()); |
9176 Handle<Object> evaluation_function = | 9185 Handle<Object> evaluation_function = |
9177 Execution::Call(compiled_function, receiver, 0, NULL, | 9186 Execution::Call(compiled_function, receiver, 0, NULL, |
9178 &has_pending_exception); | 9187 &has_pending_exception); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9225 } | 9234 } |
9226 | 9235 |
9227 // Get the global context now set to the top context from before the | 9236 // Get the global context now set to the top context from before the |
9228 // debugger was invoked. | 9237 // debugger was invoked. |
9229 Handle<Context> context = Top::global_context(); | 9238 Handle<Context> context = Top::global_context(); |
9230 | 9239 |
9231 // Compile the source to be evaluated. | 9240 // Compile the source to be evaluated. |
9232 Handle<SharedFunctionInfo> shared = | 9241 Handle<SharedFunctionInfo> shared = |
9233 Compiler::CompileEval(source, | 9242 Compiler::CompileEval(source, |
9234 context, | 9243 context, |
9235 true, | 9244 true); |
9236 Compiler::DONT_VALIDATE_JSON); | |
9237 if (shared.is_null()) return Failure::Exception(); | 9245 if (shared.is_null()) return Failure::Exception(); |
9238 Handle<JSFunction> compiled_function = | 9246 Handle<JSFunction> compiled_function = |
9239 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, | 9247 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, |
9240 context)); | 9248 context)); |
9241 | 9249 |
9242 // Invoke the result of the compilation to get the evaluation function. | 9250 // Invoke the result of the compilation to get the evaluation function. |
9243 bool has_pending_exception; | 9251 bool has_pending_exception; |
9244 Handle<Object> receiver = Top::global(); | 9252 Handle<Object> receiver = Top::global(); |
9245 Handle<Object> result = | 9253 Handle<Object> result = |
9246 Execution::Call(compiled_function, receiver, 0, NULL, | 9254 Execution::Call(compiled_function, receiver, 0, NULL, |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10157 } else { | 10165 } else { |
10158 // Handle last resort GC and make sure to allow future allocations | 10166 // Handle last resort GC and make sure to allow future allocations |
10159 // to grow the heap without causing GCs (if possible). | 10167 // to grow the heap without causing GCs (if possible). |
10160 Counters::gc_last_resort_from_js.Increment(); | 10168 Counters::gc_last_resort_from_js.Increment(); |
10161 Heap::CollectAllGarbage(false); | 10169 Heap::CollectAllGarbage(false); |
10162 } | 10170 } |
10163 } | 10171 } |
10164 | 10172 |
10165 | 10173 |
10166 } } // namespace v8::internal | 10174 } } // namespace v8::internal |
OLD | NEW |