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

Side by Side Diff: src/d8.cc

Issue 389573006: Change ScriptCompiler::CompileOptions and add d8 --cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: even more rebase Created 6 years, 5 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/d8.h ('k') | src/debug.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 // 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 5
6 // Defined when linking against shared lib on Windows. 6 // Defined when linking against shared lib on Windows.
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED)
8 #define V8_SHARED 8 #define V8_SHARED
9 #endif 9 #endif
10 10
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 163 }
164 #endif // !V8_SHARED 164 #endif // !V8_SHARED
165 165
166 166
167 // Converts a V8 value to a C string. 167 // Converts a V8 value to a C string.
168 const char* Shell::ToCString(const v8::String::Utf8Value& value) { 168 const char* Shell::ToCString(const v8::String::Utf8Value& value) {
169 return *value ? *value : "<string conversion failed>"; 169 return *value ? *value : "<string conversion failed>";
170 } 170 }
171 171
172 172
173 // Compile a string within the current v8 context.
174 Local<UnboundScript> Shell::CompileString(
175 Isolate* isolate, Local<String> source, Local<Value> name,
176 v8::ScriptCompiler::CompileOptions compile_options) {
177 ScriptOrigin origin(name);
178 ScriptCompiler::Source script_source(source, origin);
179 Local<UnboundScript> script =
180 ScriptCompiler::CompileUnbound(isolate, &script_source, compile_options);
181
182 // Was caching requested & successful? Then compile again, now with cache.
183 if (script_source.GetCachedData()) {
184 if (compile_options == ScriptCompiler::kProduceCodeCache) {
185 compile_options = ScriptCompiler::kConsumeCodeCache;
186 } else if (compile_options == ScriptCompiler::kProduceParserCache) {
187 compile_options = ScriptCompiler::kConsumeParserCache;
188 } else {
189 ASSERT(false); // A new compile option?
190 }
191 ScriptCompiler::Source cached_source(
192 source, origin, new v8::ScriptCompiler::CachedData(
193 script_source.GetCachedData()->data,
194 script_source.GetCachedData()->length,
195 v8::ScriptCompiler::CachedData::BufferNotOwned));
196 script = ScriptCompiler::CompileUnbound(isolate, &cached_source,
197 compile_options);
198 }
199 return script;
200 }
201
202
173 // Executes a string within the current v8 context. 203 // Executes a string within the current v8 context.
174 bool Shell::ExecuteString(Isolate* isolate, 204 bool Shell::ExecuteString(Isolate* isolate,
175 Handle<String> source, 205 Handle<String> source,
176 Handle<Value> name, 206 Handle<Value> name,
177 bool print_result, 207 bool print_result,
178 bool report_exceptions) { 208 bool report_exceptions) {
179 #ifndef V8_SHARED 209 #ifndef V8_SHARED
180 bool FLAG_debugger = i::FLAG_debugger; 210 bool FLAG_debugger = i::FLAG_debugger;
181 #else 211 #else
182 bool FLAG_debugger = false; 212 bool FLAG_debugger = false;
183 #endif // !V8_SHARED 213 #endif // !V8_SHARED
184 HandleScope handle_scope(isolate); 214 HandleScope handle_scope(isolate);
185 TryCatch try_catch; 215 TryCatch try_catch;
186 options.script_executed = true; 216 options.script_executed = true;
187 if (FLAG_debugger) { 217 if (FLAG_debugger) {
188 // When debugging make exceptions appear to be uncaught. 218 // When debugging make exceptions appear to be uncaught.
189 try_catch.SetVerbose(true); 219 try_catch.SetVerbose(true);
190 } 220 }
191 ScriptOrigin origin(name); 221
192 ScriptCompiler::Source script_source(source, origin);
193 Handle<UnboundScript> script = 222 Handle<UnboundScript> script =
194 ScriptCompiler::CompileUnbound(isolate, &script_source); 223 Shell::CompileString(isolate, source, name, options.compile_options);
195 if (script.IsEmpty()) { 224 if (script.IsEmpty()) {
196 // Print errors that happened during compilation. 225 // Print errors that happened during compilation.
197 if (report_exceptions && !FLAG_debugger) 226 if (report_exceptions && !FLAG_debugger)
198 ReportException(isolate, &try_catch); 227 ReportException(isolate, &try_catch);
199 return false; 228 return false;
200 } else { 229 } else {
201 PerIsolateData* data = PerIsolateData::Get(isolate); 230 PerIsolateData* data = PerIsolateData::Get(isolate);
202 Local<Context> realm = 231 Local<Context> realm =
203 Local<Context>::New(isolate, data->realms_[data->realm_current_]); 232 Local<Context>::New(isolate, data->realms_[data->realm_current_]);
204 realm->Enter(); 233 realm->Enter();
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 return false; 1362 return false;
1334 #endif // V8_SHARED 1363 #endif // V8_SHARED
1335 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 1364 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1336 } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) { 1365 } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) {
1337 options.natives_blob = argv[i] + 15; 1366 options.natives_blob = argv[i] + 15;
1338 argv[i] = NULL; 1367 argv[i] = NULL;
1339 } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) { 1368 } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) {
1340 options.snapshot_blob = argv[i] + 16; 1369 options.snapshot_blob = argv[i] + 16;
1341 argv[i] = NULL; 1370 argv[i] = NULL;
1342 #endif // V8_USE_EXTERNAL_STARTUP_DATA 1371 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1372 } else if (strcmp(argv[i], "--cache") == 0 ||
1373 strncmp(argv[i], "--cache=", 8) == 0) {
1374 const char* value = argv[i] + 7;
1375 if (!*value || strncmp(value, "=code", 6) == 0) {
1376 options.compile_options = v8::ScriptCompiler::kProduceCodeCache;
1377 } else if (strncmp(value, "=parse", 7) == 0) {
1378 options.compile_options = v8::ScriptCompiler::kProduceParserCache;
1379 } else if (strncmp(value, "=none", 6) == 0) {
1380 options.compile_options = v8::ScriptCompiler::kNoCompileOptions;
1381 } else {
1382 printf("Unknown option to --cache.\n");
1383 return false;
1384 }
1385 argv[i] = NULL;
1343 } 1386 }
1344 } 1387 }
1345 1388
1346 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 1389 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
1347 1390
1348 // Set up isolated source groups. 1391 // Set up isolated source groups.
1349 options.isolate_sources = new SourceGroup[options.num_isolates]; 1392 options.isolate_sources = new SourceGroup[options.num_isolates];
1350 SourceGroup* current = options.isolate_sources; 1393 SourceGroup* current = options.isolate_sources;
1351 current->Begin(argv, 1); 1394 current->Begin(argv, 1);
1352 for (int i = 1; i < argc; i++) { 1395 for (int i = 1; i < argc; i++) {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 } 1691 }
1649 1692
1650 } // namespace v8 1693 } // namespace v8
1651 1694
1652 1695
1653 #ifndef GOOGLE3 1696 #ifndef GOOGLE3
1654 int main(int argc, char* argv[]) { 1697 int main(int argc, char* argv[]) {
1655 return v8::Shell::Main(argc, argv); 1698 return v8::Shell::Main(argc, argv);
1656 } 1699 }
1657 #endif 1700 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698