Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: src/runtime.cc

Issue 4248: Make sure that the body of the function created by calling Function is... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.h ('k') | src/v8natives.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 719
720 static Object* Runtime_FunctionGetName(Arguments args) { 720 static Object* Runtime_FunctionGetName(Arguments args) {
721 NoHandleAllocation ha; 721 NoHandleAllocation ha;
722 ASSERT(args.length() == 1); 722 ASSERT(args.length() == 1);
723 723
724 CONVERT_CHECKED(JSFunction, f, args[0]); 724 CONVERT_CHECKED(JSFunction, f, args[0]);
725 return f->shared()->name(); 725 return f->shared()->name();
726 } 726 }
727 727
728 728
729 static Object* Runtime_FunctionSetName(Arguments args) {
730 NoHandleAllocation ha;
731 ASSERT(args.length() == 2);
732
733 CONVERT_CHECKED(JSFunction, f, args[0]);
734 CONVERT_CHECKED(String, name, args[1]);
735 f->shared()->set_name(name);
736 return Heap::undefined_value();
737 }
738
739
729 static Object* Runtime_FunctionGetScript(Arguments args) { 740 static Object* Runtime_FunctionGetScript(Arguments args) {
730 HandleScope scope; 741 HandleScope scope;
731 ASSERT(args.length() == 1); 742 ASSERT(args.length() == 1);
732 743
733 CONVERT_CHECKED(JSFunction, fun, args[0]); 744 CONVERT_CHECKED(JSFunction, fun, args[0]);
734 Handle<Object> script = Handle<Object>(fun->shared()->script()); 745 Handle<Object> script = Handle<Object>(fun->shared()->script());
735 if (!script->IsScript()) return Heap::undefined_value(); 746 if (!script->IsScript()) return Heap::undefined_value();
736 747
737 return *GetScriptWrapper(Handle<Script>::cast(script)); 748 return *GetScriptWrapper(Handle<Script>::cast(script));
738 } 749 }
(...skipping 2615 matching lines...) Expand 10 before | Expand all | Expand 10 after
3354 3365
3355 3366
3356 static Object* Runtime_EvalReceiver(Arguments args) { 3367 static Object* Runtime_EvalReceiver(Arguments args) {
3357 StackFrameLocator locator; 3368 StackFrameLocator locator;
3358 return locator.FindJavaScriptFrame(1)->receiver(); 3369 return locator.FindJavaScriptFrame(1)->receiver();
3359 } 3370 }
3360 3371
3361 3372
3362 static Object* Runtime_CompileString(Arguments args) { 3373 static Object* Runtime_CompileString(Arguments args) {
3363 HandleScope scope; 3374 HandleScope scope;
3364 ASSERT(args.length() == 2); 3375 ASSERT(args.length() == 3);
3365 CONVERT_ARG_CHECKED(String, source, 0); 3376 CONVERT_ARG_CHECKED(String, source, 0);
3366 bool contextual = args[1]->IsTrue(); 3377 CONVERT_ARG_CHECKED(Smi, line_offset, 1);
3367 RUNTIME_ASSERT(contextual || args[1]->IsFalse()); 3378 bool contextual = args[2]->IsTrue();
3379 RUNTIME_ASSERT(contextual || args[2]->IsFalse());
3368 3380
3369 // Compute the eval context. 3381 // Compute the eval context.
3370 Handle<Context> context; 3382 Handle<Context> context;
3371 if (contextual) { 3383 if (contextual) {
3372 // Get eval context. May not be available if we are calling eval 3384 // Get eval context. May not be available if we are calling eval
3373 // through an alias, and the corresponding frame doesn't have a 3385 // through an alias, and the corresponding frame doesn't have a
3374 // proper eval context set up. 3386 // proper eval context set up.
3375 Object* eval_context = EvalContext(); 3387 Object* eval_context = EvalContext();
3376 if (eval_context->IsFailure()) return eval_context; 3388 if (eval_context->IsFailure()) return eval_context;
3377 context = Handle<Context>(Context::cast(eval_context)); 3389 context = Handle<Context>(Context::cast(eval_context));
3378 } else { 3390 } else {
3379 context = Handle<Context>(Top::context()->global_context()); 3391 context = Handle<Context>(Top::context()->global_context());
3380 } 3392 }
3381 3393
3382 3394
3383 // Compile source string. 3395 // Compile source string.
3384 bool is_global = context->IsGlobalContext(); 3396 bool is_global = context->IsGlobalContext();
3385 Handle<JSFunction> boilerplate = 3397 Handle<JSFunction> boilerplate =
3386 Compiler::CompileEval(is_global, source); 3398 Compiler::CompileEval(source, line_offset->value(), is_global);
3387 if (boilerplate.is_null()) return Failure::Exception(); 3399 if (boilerplate.is_null()) return Failure::Exception();
3388 Handle<JSFunction> fun = 3400 Handle<JSFunction> fun =
3389 Factory::NewFunctionFromBoilerplate(boilerplate, context); 3401 Factory::NewFunctionFromBoilerplate(boilerplate, context);
3390 return *fun; 3402 return *fun;
3391 } 3403 }
3392 3404
3393 3405
3394 static Object* Runtime_CompileScript(Arguments args) { 3406 static Object* Runtime_CompileScript(Arguments args) {
3395 HandleScope scope; 3407 HandleScope scope;
3396 ASSERT(args.length() == 4); 3408 ASSERT(args.length() == 4);
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
4495 // 'arguments'. This it to have access to what would have been 'arguments' in 4507 // 'arguments'. This it to have access to what would have been 'arguments' in
4496 // the function beeing debugged. 4508 // the function beeing debugged.
4497 // function(arguments,__source__) {return eval(__source__);} 4509 // function(arguments,__source__) {return eval(__source__);}
4498 static const char* source_str = 4510 static const char* source_str =
4499 "function(arguments,__source__){return eval(__source__);}"; 4511 "function(arguments,__source__){return eval(__source__);}";
4500 static const int source_str_length = strlen(source_str); 4512 static const int source_str_length = strlen(source_str);
4501 Handle<String> function_source = 4513 Handle<String> function_source =
4502 Factory::NewStringFromAscii(Vector<const char>(source_str, 4514 Factory::NewStringFromAscii(Vector<const char>(source_str,
4503 source_str_length)); 4515 source_str_length));
4504 Handle<JSFunction> boilerplate = 4516 Handle<JSFunction> boilerplate =
4505 Compiler::CompileEval(context->IsGlobalContext(), function_source); 4517 Compiler::CompileEval(function_source, 0, context->IsGlobalContext());
4506 if (boilerplate.is_null()) return Failure::Exception(); 4518 if (boilerplate.is_null()) return Failure::Exception();
4507 Handle<JSFunction> compiled_function = 4519 Handle<JSFunction> compiled_function =
4508 Factory::NewFunctionFromBoilerplate(boilerplate, context); 4520 Factory::NewFunctionFromBoilerplate(boilerplate, context);
4509 4521
4510 // Invoke the result of the compilation to get the evaluation function. 4522 // Invoke the result of the compilation to get the evaluation function.
4511 bool has_pending_exception; 4523 bool has_pending_exception;
4512 Handle<Object> receiver(frame->receiver()); 4524 Handle<Object> receiver(frame->receiver());
4513 Handle<Object> evaluation_function = 4525 Handle<Object> evaluation_function =
4514 Execution::Call(compiled_function, receiver, 0, NULL, 4526 Execution::Call(compiled_function, receiver, 0, NULL,
4515 &has_pending_exception); 4527 &has_pending_exception);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4551 if (top != NULL) { 4563 if (top != NULL) {
4552 Top::set_context(*top->context()); 4564 Top::set_context(*top->context());
4553 Top::set_security_context(*top->security_context()); 4565 Top::set_security_context(*top->security_context());
4554 } 4566 }
4555 4567
4556 // Get the global context now set to the top context from before the 4568 // Get the global context now set to the top context from before the
4557 // debugger was invoked. 4569 // debugger was invoked.
4558 Handle<Context> context = Top::global_context(); 4570 Handle<Context> context = Top::global_context();
4559 4571
4560 // Compile the source to be evaluated. 4572 // Compile the source to be evaluated.
4561 Handle<JSFunction> boilerplate(Compiler::CompileEval(true, source)); 4573 Handle<JSFunction> boilerplate(Compiler::CompileEval(source, 0, true));
4562 if (boilerplate.is_null()) return Failure::Exception(); 4574 if (boilerplate.is_null()) return Failure::Exception();
4563 Handle<JSFunction> compiled_function = 4575 Handle<JSFunction> compiled_function =
4564 Handle<JSFunction>(Factory::NewFunctionFromBoilerplate(boilerplate, 4576 Handle<JSFunction>(Factory::NewFunctionFromBoilerplate(boilerplate,
4565 context)); 4577 context));
4566 4578
4567 // Invoke the result of the compilation to get the evaluation function. 4579 // Invoke the result of the compilation to get the evaluation function.
4568 bool has_pending_exception; 4580 bool has_pending_exception;
4569 Handle<Object> receiver = Top::global(); 4581 Handle<Object> receiver = Top::global();
4570 Handle<Object> result = 4582 Handle<Object> result =
4571 Execution::Call(compiled_function, receiver, 0, NULL, 4583 Execution::Call(compiled_function, receiver, 0, NULL,
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
4976 4988
4977 void Runtime::PerformGC(Object* result) { 4989 void Runtime::PerformGC(Object* result) {
4978 Failure* failure = Failure::cast(result); 4990 Failure* failure = Failure::cast(result);
4979 // Try to do a garbage collection; ignore it if it fails. The C 4991 // Try to do a garbage collection; ignore it if it fails. The C
4980 // entry stub will throw an out-of-memory exception in that case. 4992 // entry stub will throw an out-of-memory exception in that case.
4981 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); 4993 Heap::CollectGarbage(failure->requested(), failure->allocation_space());
4982 } 4994 }
4983 4995
4984 4996
4985 } } // namespace v8::internal 4997 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698