OLD | NEW |
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 #endif // !V8_SHARED | 160 #endif // !V8_SHARED |
161 | 161 |
162 | 162 |
163 // Converts a V8 value to a C string. | 163 // Converts a V8 value to a C string. |
164 const char* Shell::ToCString(const v8::String::Utf8Value& value) { | 164 const char* Shell::ToCString(const v8::String::Utf8Value& value) { |
165 return *value ? *value : "<string conversion failed>"; | 165 return *value ? *value : "<string conversion failed>"; |
166 } | 166 } |
167 | 167 |
168 | 168 |
| 169 // Compile a string within the current v8 context. |
| 170 Local<UnboundScript> Shell::CompileString( |
| 171 Isolate* isolate, Local<String> source, Local<Value> name, |
| 172 v8::ScriptCompiler::CompileOptions compile_options) { |
| 173 ScriptOrigin origin(name); |
| 174 ScriptCompiler::Source script_source(source, origin); |
| 175 Local<UnboundScript> script = |
| 176 ScriptCompiler::CompileUnbound(isolate, &script_source, compile_options); |
| 177 |
| 178 // Was caching requested & successful? Then compile again, now with cache. |
| 179 if (script_source.GetCachedData()) { |
| 180 if (compile_options == ScriptCompiler::kProduceCodeCache) { |
| 181 compile_options = ScriptCompiler::kConsumeCodeCache; |
| 182 } else if (compile_options == ScriptCompiler::kProduceParserCache) { |
| 183 compile_options = ScriptCompiler::kConsumeParserCache; |
| 184 } else { |
| 185 ASSERT(false); // A new compile option? |
| 186 } |
| 187 ScriptCompiler::Source cached_source( |
| 188 source, origin, new v8::ScriptCompiler::CachedData( |
| 189 script_source.GetCachedData()->data, |
| 190 script_source.GetCachedData()->length, |
| 191 v8::ScriptCompiler::CachedData::BufferNotOwned)); |
| 192 script = ScriptCompiler::CompileUnbound(isolate, &cached_source, |
| 193 compile_options); |
| 194 } |
| 195 return script; |
| 196 } |
| 197 |
| 198 |
169 // Executes a string within the current v8 context. | 199 // Executes a string within the current v8 context. |
170 bool Shell::ExecuteString(Isolate* isolate, | 200 bool Shell::ExecuteString(Isolate* isolate, |
171 Handle<String> source, | 201 Handle<String> source, |
172 Handle<Value> name, | 202 Handle<Value> name, |
173 bool print_result, | 203 bool print_result, |
174 bool report_exceptions) { | 204 bool report_exceptions) { |
175 #ifndef V8_SHARED | 205 #ifndef V8_SHARED |
176 bool FLAG_debugger = i::FLAG_debugger; | 206 bool FLAG_debugger = i::FLAG_debugger; |
177 #else | 207 #else |
178 bool FLAG_debugger = false; | 208 bool FLAG_debugger = false; |
179 #endif // !V8_SHARED | 209 #endif // !V8_SHARED |
180 HandleScope handle_scope(isolate); | 210 HandleScope handle_scope(isolate); |
181 TryCatch try_catch; | 211 TryCatch try_catch; |
182 options.script_executed = true; | 212 options.script_executed = true; |
183 if (FLAG_debugger) { | 213 if (FLAG_debugger) { |
184 // When debugging make exceptions appear to be uncaught. | 214 // When debugging make exceptions appear to be uncaught. |
185 try_catch.SetVerbose(true); | 215 try_catch.SetVerbose(true); |
186 } | 216 } |
187 ScriptOrigin origin(name); | 217 |
188 ScriptCompiler::Source script_source(source, origin); | |
189 Handle<UnboundScript> script = | 218 Handle<UnboundScript> script = |
190 ScriptCompiler::CompileUnbound(isolate, &script_source); | 219 Shell::CompileString(isolate, source, name, options.compile_options); |
191 if (script.IsEmpty()) { | 220 if (script.IsEmpty()) { |
192 // Print errors that happened during compilation. | 221 // Print errors that happened during compilation. |
193 if (report_exceptions && !FLAG_debugger) | 222 if (report_exceptions && !FLAG_debugger) |
194 ReportException(isolate, &try_catch); | 223 ReportException(isolate, &try_catch); |
195 return false; | 224 return false; |
196 } else { | 225 } else { |
197 PerIsolateData* data = PerIsolateData::Get(isolate); | 226 PerIsolateData* data = PerIsolateData::Get(isolate); |
198 Local<Context> realm = | 227 Local<Context> realm = |
199 Local<Context>::New(isolate, data->realms_[data->realm_current_]); | 228 Local<Context>::New(isolate, data->realms_[data->realm_current_]); |
200 realm->Enter(); | 229 realm->Enter(); |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 return false; | 1358 return false; |
1330 #endif // V8_SHARED | 1359 #endif // V8_SHARED |
1331 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 1360 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
1332 } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) { | 1361 } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) { |
1333 options.natives_blob = argv[i] + 15; | 1362 options.natives_blob = argv[i] + 15; |
1334 argv[i] = NULL; | 1363 argv[i] = NULL; |
1335 } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) { | 1364 } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) { |
1336 options.snapshot_blob = argv[i] + 16; | 1365 options.snapshot_blob = argv[i] + 16; |
1337 argv[i] = NULL; | 1366 argv[i] = NULL; |
1338 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 1367 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 1368 } else if (strncmp(argv[i], "--cache", 7) == 0) { |
| 1369 const char* value = argv[i] + 7; |
| 1370 if (!*value || strncmp(value, "=code", 6) == 0) { |
| 1371 options.compile_options = v8::ScriptCompiler::kProduceCodeCache; |
| 1372 } else if (strncmp(value, "=parse", 7) == 0) { |
| 1373 options.compile_options = v8::ScriptCompiler::kProduceParserCache; |
| 1374 } else if (strncmp(value, "=none", 6) == 0) { |
| 1375 options.compile_options = v8::ScriptCompiler::kNoCompileOptions; |
| 1376 } else { |
| 1377 printf("Unknown option to --cache.\n"); |
| 1378 return false; |
| 1379 } |
| 1380 argv[i] = NULL; |
1339 } | 1381 } |
1340 } | 1382 } |
1341 | 1383 |
1342 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 1384 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
1343 | 1385 |
1344 // Set up isolated source groups. | 1386 // Set up isolated source groups. |
1345 options.isolate_sources = new SourceGroup[options.num_isolates]; | 1387 options.isolate_sources = new SourceGroup[options.num_isolates]; |
1346 SourceGroup* current = options.isolate_sources; | 1388 SourceGroup* current = options.isolate_sources; |
1347 current->Begin(argv, 1); | 1389 current->Begin(argv, 1); |
1348 for (int i = 1; i < argc; i++) { | 1390 for (int i = 1; i < argc; i++) { |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 } | 1680 } |
1639 | 1681 |
1640 } // namespace v8 | 1682 } // namespace v8 |
1641 | 1683 |
1642 | 1684 |
1643 #ifndef GOOGLE3 | 1685 #ifndef GOOGLE3 |
1644 int main(int argc, char* argv[]) { | 1686 int main(int argc, char* argv[]) { |
1645 return v8::Shell::Main(argc, argv); | 1687 return v8::Shell::Main(argc, argv); |
1646 } | 1688 } |
1647 #endif | 1689 #endif |
OLD | NEW |