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

Side by Side Diff: src/d8.cc

Issue 199063003: New Compilation API, part 1, try 2 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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/api.cc ('k') | src/heap.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 #else 198 #else
199 bool FLAG_debugger = false; 199 bool FLAG_debugger = false;
200 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 200 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
201 HandleScope handle_scope(isolate); 201 HandleScope handle_scope(isolate);
202 TryCatch try_catch; 202 TryCatch try_catch;
203 options.script_executed = true; 203 options.script_executed = true;
204 if (FLAG_debugger) { 204 if (FLAG_debugger) {
205 // When debugging make exceptions appear to be uncaught. 205 // When debugging make exceptions appear to be uncaught.
206 try_catch.SetVerbose(true); 206 try_catch.SetVerbose(true);
207 } 207 }
208 Handle<Script> script = Script::New(source, name); 208 ScriptOrigin origin(name);
209 Handle<UnboundScript> script = ScriptCompiler::CompileUnbound(
210 isolate, ScriptCompiler::Source(source, origin));
209 if (script.IsEmpty()) { 211 if (script.IsEmpty()) {
210 // Print errors that happened during compilation. 212 // Print errors that happened during compilation.
211 if (report_exceptions && !FLAG_debugger) 213 if (report_exceptions && !FLAG_debugger)
212 ReportException(isolate, &try_catch); 214 ReportException(isolate, &try_catch);
213 return false; 215 return false;
214 } else { 216 } else {
215 PerIsolateData* data = PerIsolateData::Get(isolate); 217 PerIsolateData* data = PerIsolateData::Get(isolate);
216 Local<Context> realm = 218 Local<Context> realm =
217 Local<Context>::New(isolate, data->realms_[data->realm_current_]); 219 Local<Context>::New(isolate, data->realms_[data->realm_current_]);
218 realm->Enter(); 220 realm->Enter();
219 Handle<Value> result = script->Run(); 221 Handle<Value> result = script->BindToCurrentContext()->Run();
220 realm->Exit(); 222 realm->Exit();
221 data->realm_current_ = data->realm_switch_; 223 data->realm_current_ = data->realm_switch_;
222 if (result.IsEmpty()) { 224 if (result.IsEmpty()) {
223 ASSERT(try_catch.HasCaught()); 225 ASSERT(try_catch.HasCaught());
224 // Print errors that happened during execution. 226 // Print errors that happened during execution.
225 if (report_exceptions && !FLAG_debugger) 227 if (report_exceptions && !FLAG_debugger)
226 ReportException(isolate, &try_catch); 228 ReportException(isolate, &try_catch);
227 return false; 229 return false;
228 } else { 230 } else {
229 ASSERT(!try_catch.HasCaught()); 231 ASSERT(!try_catch.HasCaught());
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // Realm.eval(i, s) evaluates s in realm i and returns the result. 400 // Realm.eval(i, s) evaluates s in realm i and returns the result.
399 void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) { 401 void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
400 Isolate* isolate = args.GetIsolate(); 402 Isolate* isolate = args.GetIsolate();
401 PerIsolateData* data = PerIsolateData::Get(isolate); 403 PerIsolateData* data = PerIsolateData::Get(isolate);
402 int index = data->RealmIndexOrThrow(args, 0); 404 int index = data->RealmIndexOrThrow(args, 0);
403 if (index == -1) return; 405 if (index == -1) return;
404 if (args.Length() < 2 || !args[1]->IsString()) { 406 if (args.Length() < 2 || !args[1]->IsString()) {
405 Throw(args.GetIsolate(), "Invalid argument"); 407 Throw(args.GetIsolate(), "Invalid argument");
406 return; 408 return;
407 } 409 }
408 Handle<Script> script = Script::New(args[1]->ToString()); 410 Handle<UnboundScript> script = ScriptCompiler::CompileUnbound(
411 isolate, ScriptCompiler::Source(args[1]->ToString()));
409 if (script.IsEmpty()) return; 412 if (script.IsEmpty()) return;
410 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]); 413 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
411 realm->Enter(); 414 realm->Enter();
412 Handle<Value> result = script->Run(); 415 Handle<Value> result = script->BindToCurrentContext()->Run();
413 realm->Exit(); 416 realm->Exit();
414 args.GetReturnValue().Set(result); 417 args.GetReturnValue().Set(result);
415 } 418 }
416 419
417 420
418 // Realm.shared is an accessor for a single shared value across realms. 421 // Realm.shared is an accessor for a single shared value across realms.
419 void Shell::RealmSharedGet(Local<String> property, 422 void Shell::RealmSharedGet(Local<String> property,
420 const PropertyCallbackInfo<Value>& info) { 423 const PropertyCallbackInfo<Value>& info) {
421 Isolate* isolate = info.GetIsolate(); 424 Isolate* isolate = info.GetIsolate();
422 PerIsolateData* data = PerIsolateData::Get(isolate); 425 PerIsolateData* data = PerIsolateData::Get(isolate);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 i::Vector<const char> shell_source = 802 i::Vector<const char> shell_source =
800 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); 803 i::NativesCollection<i::D8>::GetRawScriptSource(source_index);
801 i::Vector<const char> shell_source_name = 804 i::Vector<const char> shell_source_name =
802 i::NativesCollection<i::D8>::GetScriptName(source_index); 805 i::NativesCollection<i::D8>::GetScriptName(source_index);
803 Handle<String> source = 806 Handle<String> source =
804 String::NewFromUtf8(isolate, shell_source.start(), String::kNormalString, 807 String::NewFromUtf8(isolate, shell_source.start(), String::kNormalString,
805 shell_source.length()); 808 shell_source.length());
806 Handle<String> name = 809 Handle<String> name =
807 String::NewFromUtf8(isolate, shell_source_name.start(), 810 String::NewFromUtf8(isolate, shell_source_name.start(),
808 String::kNormalString, shell_source_name.length()); 811 String::kNormalString, shell_source_name.length());
809 Handle<Script> script = Script::Compile(source, name); 812 ScriptOrigin origin(name);
813 Handle<Script> script = Script::Compile(source, &origin);
810 script->Run(); 814 script->Run();
811 // Mark the d8 shell script as native to avoid it showing up as normal source 815 // Mark the d8 shell script as native to avoid it showing up as normal source
812 // in the debugger. 816 // in the debugger.
813 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); 817 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script);
814 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() 818 i::Handle<i::Script> script_object = compiled_script->IsJSFunction()
815 ? i::Handle<i::Script>(i::Script::cast( 819 ? i::Handle<i::Script>(i::Script::cast(
816 i::JSFunction::cast(*compiled_script)->shared()->script())) 820 i::JSFunction::cast(*compiled_script)->shared()->script()))
817 : i::Handle<i::Script>(i::Script::cast( 821 : i::Handle<i::Script>(i::Script::cast(
818 i::SharedFunctionInfo::cast(*compiled_script)->script())); 822 i::SharedFunctionInfo::cast(*compiled_script)->script()));
819 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); 823 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 } 1767 }
1764 1768
1765 } // namespace v8 1769 } // namespace v8
1766 1770
1767 1771
1768 #ifndef GOOGLE3 1772 #ifndef GOOGLE3
1769 int main(int argc, char* argv[]) { 1773 int main(int argc, char* argv[]) {
1770 return v8::Shell::Main(argc, argv); 1774 return v8::Shell::Main(argc, argv);
1771 } 1775 }
1772 #endif 1776 #endif
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698