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

Side by Side Diff: src/d8.cc

Issue 7189007: Reinitialize the arguments object in d8 when renewing the evaluation context (fixes issue 1477). (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 606 }
607 607
608 // Initialize the global objects 608 // Initialize the global objects
609 HandleScope scope; 609 HandleScope scope;
610 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); 610 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
611 611
612 utility_context_ = Context::New(NULL, global_template); 612 utility_context_ = Context::New(NULL, global_template);
613 utility_context_->SetSecurityToken(Undefined()); 613 utility_context_->SetSecurityToken(Undefined());
614 Context::Scope utility_scope(utility_context_); 614 Context::Scope utility_scope(utility_context_);
615 615
616 i::JSArguments js_args = i::FLAG_js_arguments;
617 i::Handle<i::FixedArray> arguments_array =
618 FACTORY->NewFixedArray(js_args.argc());
619 for (int j = 0; j < js_args.argc(); j++) {
620 i::Handle<i::String> arg =
621 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
622 arguments_array->set(j, *arg);
623 }
624 i::Handle<i::JSArray> arguments_jsarray =
625 FACTORY->NewJSArrayWithElements(arguments_array);
626 global_template->Set(String::New("arguments"),
627 Utils::ToLocal(arguments_jsarray));
628
629 #ifdef ENABLE_DEBUGGER_SUPPORT 616 #ifdef ENABLE_DEBUGGER_SUPPORT
630 // Install the debugger object in the utility scope 617 // Install the debugger object in the utility scope
631 i::Debug* debug = i::Isolate::Current()->debug(); 618 i::Debug* debug = i::Isolate::Current()->debug();
632 debug->Load(); 619 debug->Load();
633 i::Handle<i::JSObject> js_debug 620 i::Handle<i::JSObject> js_debug
634 = i::Handle<i::JSObject>(debug->debug_context()->global()); 621 = i::Handle<i::JSObject>(debug->debug_context()->global());
635 utility_context_->Global()->Set(String::New("$debug"), 622 utility_context_->Global()->Set(String::New("$debug"),
636 Utils::ToLocal(js_debug)); 623 Utils::ToLocal(js_debug));
637 #endif 624 #endif
638 } 625 }
639 626
640 627
641 void Shell::RenewEvaluationContext() { 628 void Shell::RenewEvaluationContext() {
642 // Initialize the global objects 629 // Initialize the global objects
643 HandleScope scope; 630 HandleScope scope;
644 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); 631 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
645 632
646 // (Re-)create the evaluation context 633 // (Re-)create the evaluation context
647 if (!evaluation_context_.IsEmpty()) { 634 if (!evaluation_context_.IsEmpty()) {
648 evaluation_context_.Dispose(); 635 evaluation_context_.Dispose();
649 } 636 }
650 evaluation_context_ = Context::New(NULL, global_template); 637 evaluation_context_ = Context::New(NULL, global_template);
651 evaluation_context_->SetSecurityToken(Undefined()); 638 evaluation_context_->SetSecurityToken(Undefined());
652 639
640 Context::Scope utility_scope(utility_context_);
641 i::JSArguments js_args = i::FLAG_js_arguments;
642 i::Handle<i::FixedArray> arguments_array =
643 FACTORY->NewFixedArray(js_args.argc());
644 for (int j = 0; j < js_args.argc(); j++) {
645 i::Handle<i::String> arg =
646 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
647 arguments_array->set(j, *arg);
648 }
649 i::Handle<i::JSArray> arguments_jsarray =
650 FACTORY->NewJSArrayWithElements(arguments_array);
651 evaluation_context_->Global()->Set(String::New("arguments"),
652 Utils::ToLocal(arguments_jsarray));
653
653 #ifdef ENABLE_DEBUGGER_SUPPORT 654 #ifdef ENABLE_DEBUGGER_SUPPORT
654 i::Debug* debug = i::Isolate::Current()->debug(); 655 i::Debug* debug = i::Isolate::Current()->debug();
655 debug->Load(); 656 debug->Load();
656 657
657 // Set the security token of the debug context to allow access. 658 // Set the security token of the debug context to allow access.
658 debug->debug_context()->set_security_token(HEAP->undefined_value()); 659 debug->debug_context()->set_security_token(HEAP->undefined_value());
659 660
660 // Start the debugger agent if requested. 661 // Start the debugger agent if requested.
661 if (i::FLAG_debugger_agent) { 662 if (i::FLAG_debugger_agent) {
662 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); 663 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 } 980 }
980 981
981 } // namespace v8 982 } // namespace v8
982 983
983 984
984 #ifndef GOOGLE3 985 #ifndef GOOGLE3
985 int main(int argc, char* argv[]) { 986 int main(int argc, char* argv[]) {
986 return v8::Shell::Main(argc, argv); 987 return v8::Shell::Main(argc, argv);
987 } 988 }
988 #endif 989 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698