Chromium Code Reviews| Index: src/mksnapshot.cc |
| =================================================================== |
| --- src/mksnapshot.cc (revision 11803) |
| +++ src/mksnapshot.cc (working copy) |
| @@ -25,6 +25,8 @@ |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| +#include <errno.h> |
| +#include <stdio.h> |
| #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| #include <bzlib.h> |
| #endif |
| @@ -33,6 +35,7 @@ |
| #include "v8.h" |
| #include "bootstrapper.h" |
| +#include "flags.h" |
| #include "natives.h" |
| #include "platform.h" |
| #include "serialize.h" |
| @@ -308,6 +311,61 @@ |
| "\nException thrown while compiling natives - see above.\n\n"); |
| exit(1); |
| } |
| + context->Enter(); |
|
ulan
2012/06/19 09:42:15
Move context->Enter(), context->Exit() inside the
Erik Corry
2012/06/19 10:20:46
Done.
|
| + if (i::FLAG_extra_code != NULL) { |
| + // Capture 100 frames if anything happens. |
| + V8::SetCaptureStackTraceForUncaughtExceptions(true, 100); |
| + HandleScope scope; |
| + const char* name = i::FLAG_extra_code; |
| + FILE* file = i::OS::FOpen(name, "rb"); |
| + if (file == NULL) { |
| + fprintf(stderr, "Failed to open '%s': errno %d\n", name, errno); |
| + exit(1); |
| + } |
| + |
| + fseek(file, 0, SEEK_END); |
| + int size = ftell(file); |
| + rewind(file); |
| + |
| + char* chars = new char[size + 1]; |
| + chars[size] = '\0'; |
| + for (int i = 0; i < size;) { |
| + int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
| + if (read < 0) { |
| + fprintf(stderr, "Failed to read '%s': errno %d\n", name, errno); |
|
ulan
2012/06/19 09:42:15
Indentation.
Do we want to exit(1) here too?
Erik Corry
2012/06/19 10:20:46
Done.
|
| + } |
| + i += read; |
| + } |
| + fclose(file); |
| + Local<String> source = String::New(chars); |
| + TryCatch try_catch; |
| + Local<Script> script = Script::Compile(source); |
| + if (try_catch.HasCaught()) { |
| + fprintf(stderr, "Failure compiling '%s' (see above)\n", name); |
| + exit(1); |
| + } |
| + Handle<Value> ret = script->Run(); |
| + if (try_catch.HasCaught()) { |
| + fprintf(stderr, "Failure running '%s'\n", name); |
| + Local<Message> message = try_catch.Message(); |
| + Local<String> message_string = message->Get(); |
| + Local<String> message_line = message->GetSourceLine(); |
| + int len = 2 + message_string->Utf8Length() + message_line->Utf8Length(); |
| + char* buf = new char(len); |
| + message_string->WriteUtf8(buf); |
| + fprintf(stderr, "%s at line %d\n", buf, message->GetLineNumber()); |
| + message_line->WriteUtf8(buf); |
| + fprintf(stderr, "%s\n", buf); |
| + int from = message->GetStartColumn(); |
| + int to = message->GetEndColumn(); |
| + int i; |
| + for (i = 0; i < from; i++) fprintf(stderr, " "); |
| + for ( ; i <= to; i++) fprintf(stderr, "^"); |
| + fprintf(stderr, "\n"); |
| + exit(1); |
| + } |
| + } |
| + context->Exit(); |
| // Make sure all builtin scripts are cached. |
| { HandleScope scope; |
| for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { |