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 #include <errno.h> | 5 #include <errno.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 Local<ObjectTemplate> os_templ = ObjectTemplate::New(isolate); | 1572 Local<ObjectTemplate> os_templ = ObjectTemplate::New(isolate); |
1573 AddOSMethods(isolate, os_templ); | 1573 AddOSMethods(isolate, os_templ); |
1574 global_template->Set( | 1574 global_template->Set( |
1575 String::NewFromUtf8(isolate, "os", NewStringType::kNormal) | 1575 String::NewFromUtf8(isolate, "os", NewStringType::kNormal) |
1576 .ToLocalChecked(), | 1576 .ToLocalChecked(), |
1577 os_templ); | 1577 os_templ); |
1578 | 1578 |
1579 return global_template; | 1579 return global_template; |
1580 } | 1580 } |
1581 | 1581 |
1582 static void EmptyMessageCallback(Local<Message> message, Local<Value> error) { | 1582 static void PrintNonErrorsMessageCallback(Local<Message> message, |
1583 // Nothing to be done here, exceptions thrown up to the shell will be reported | 1583 Local<Value> error) { |
| 1584 // Nothing to do here for errors, exceptions thrown up to the shell will be |
| 1585 // reported |
1584 // separately by {Shell::ReportException} after they are caught. | 1586 // separately by {Shell::ReportException} after they are caught. |
| 1587 // Do print other kinds of messages. |
| 1588 switch (message->ErrorLevel()) { |
| 1589 case v8::Isolate::kMessageWarning: |
| 1590 case v8::Isolate::kMessageLog: |
| 1591 case v8::Isolate::kMessageInfo: |
| 1592 case v8::Isolate::kMessageDebug: { |
| 1593 break; |
| 1594 } |
| 1595 |
| 1596 case v8::Isolate::kMessageError: { |
| 1597 // Ignore errors, printed elsewhere. |
| 1598 return; |
| 1599 } |
| 1600 |
| 1601 default: { |
| 1602 UNREACHABLE(); |
| 1603 break; |
| 1604 } |
| 1605 } |
| 1606 // Converts a V8 value to a C string. |
| 1607 auto ToCString = [](const v8::String::Utf8Value& value) { |
| 1608 return *value ? *value : "<string conversion failed>"; |
| 1609 }; |
| 1610 Isolate* isolate = Isolate::GetCurrent(); |
| 1611 v8::String::Utf8Value msg(message->Get()); |
| 1612 const char* msg_string = ToCString(msg); |
| 1613 // Print (filename):(line number): (message). |
| 1614 v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName()); |
| 1615 const char* filename_string = ToCString(filename); |
| 1616 Maybe<int> maybeline = message->GetLineNumber(isolate->GetCurrentContext()); |
| 1617 int linenum = maybeline.IsJust() ? maybeline.FromJust() : -1; |
| 1618 printf("%s:%i: %s\n", filename_string, linenum, msg_string); |
1585 } | 1619 } |
1586 | 1620 |
1587 void Shell::Initialize(Isolate* isolate) { | 1621 void Shell::Initialize(Isolate* isolate) { |
1588 // Set up counters | 1622 // Set up counters |
1589 if (i::StrLength(i::FLAG_map_counters) != 0) | 1623 if (i::StrLength(i::FLAG_map_counters) != 0) |
1590 MapCounters(isolate, i::FLAG_map_counters); | 1624 MapCounters(isolate, i::FLAG_map_counters); |
1591 // Disable default message reporting. | 1625 // Disable default message reporting. |
1592 isolate->AddMessageListener(EmptyMessageCallback); | 1626 isolate->AddMessageListenerWithErrorLevel( |
| 1627 PrintNonErrorsMessageCallback, |
| 1628 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
| 1629 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
| 1630 v8::Isolate::kMessageLog); |
1593 } | 1631 } |
1594 | 1632 |
1595 | 1633 |
1596 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { | 1634 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { |
1597 // This needs to be a critical section since this is not thread-safe | 1635 // This needs to be a critical section since this is not thread-safe |
1598 base::LockGuard<base::Mutex> lock_guard(context_mutex_.Pointer()); | 1636 base::LockGuard<base::Mutex> lock_guard(context_mutex_.Pointer()); |
1599 // Initialize the global objects | 1637 // Initialize the global objects |
1600 Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 1638 Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
1601 EscapableHandleScope handle_scope(isolate); | 1639 EscapableHandleScope handle_scope(isolate); |
1602 Local<Context> context = Context::New(isolate, NULL, global_template); | 1640 Local<Context> context = Context::New(isolate, NULL, global_template); |
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3020 } | 3058 } |
3021 | 3059 |
3022 } // namespace v8 | 3060 } // namespace v8 |
3023 | 3061 |
3024 | 3062 |
3025 #ifndef GOOGLE3 | 3063 #ifndef GOOGLE3 |
3026 int main(int argc, char* argv[]) { | 3064 int main(int argc, char* argv[]) { |
3027 return v8::Shell::Main(argc, argv); | 3065 return v8::Shell::Main(argc, argv); |
3028 } | 3066 } |
3029 #endif | 3067 #endif |
OLD | NEW |