OLD | NEW |
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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 return result; | 827 return result; |
828 } | 828 } |
829 }; | 829 }; |
830 #endif | 830 #endif |
831 | 831 |
832 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { | 832 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { |
833 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 833 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); |
834 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 834 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); |
835 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); | 835 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); |
836 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); | 836 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); |
837 global_template->Set(String::New("readbinary"), | |
838 FunctionTemplate::New(ReadBinary)); | |
839 global_template->Set(String::New("readbuffer"), | 837 global_template->Set(String::New("readbuffer"), |
840 FunctionTemplate::New(ReadBuffer)); | 838 FunctionTemplate::New(ReadBuffer)); |
841 global_template->Set(String::New("readline"), | 839 global_template->Set(String::New("readline"), |
842 FunctionTemplate::New(ReadLine)); | 840 FunctionTemplate::New(ReadLine)); |
843 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 841 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); |
844 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 842 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
845 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 843 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
846 global_template->Set(String::New("enableProfiler"), | 844 global_template->Set(String::New("enableProfiler"), |
847 FunctionTemplate::New(EnableProfiler)); | 845 FunctionTemplate::New(EnableProfiler)); |
848 global_template->Set(String::New("disableProfiler"), | 846 global_template->Set(String::New("disableProfiler"), |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 for (int i = 0; i < size;) { | 1047 for (int i = 0; i < size;) { |
1050 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); | 1048 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
1051 i += read; | 1049 i += read; |
1052 } | 1050 } |
1053 fclose(file); | 1051 fclose(file); |
1054 *size_out = size; | 1052 *size_out = size; |
1055 return chars; | 1053 return chars; |
1056 } | 1054 } |
1057 | 1055 |
1058 | 1056 |
1059 Handle<Value> Shell::ReadBinary(const Arguments& args) { | |
1060 String::Utf8Value filename(args[0]); | |
1061 int size; | |
1062 if (*filename == NULL) { | |
1063 return ThrowException(String::New("Error loading file")); | |
1064 } | |
1065 char* chars = ReadChars(*filename, &size); | |
1066 if (chars == NULL) { | |
1067 return ThrowException(String::New("Error reading file")); | |
1068 } | |
1069 // We skip checking the string for UTF8 characters and use it raw as | |
1070 // backing store for the external string with 8-bit characters. | |
1071 BinaryResource* resource = new BinaryResource(chars, size); | |
1072 return String::NewExternal(resource); | |
1073 } | |
1074 | |
1075 | |
1076 Handle<Value> Shell::ReadBuffer(const Arguments& args) { | 1057 Handle<Value> Shell::ReadBuffer(const Arguments& args) { |
1077 String::Utf8Value filename(args[0]); | 1058 String::Utf8Value filename(args[0]); |
1078 int length; | 1059 int length; |
1079 if (*filename == NULL) { | 1060 if (*filename == NULL) { |
1080 return ThrowException(String::New("Error loading file")); | 1061 return ThrowException(String::New("Error loading file")); |
1081 } | 1062 } |
1082 char* data = ReadChars(*filename, &length); | 1063 char* data = ReadChars(*filename, &length); |
1083 if (data == NULL) { | 1064 if (data == NULL) { |
1084 return ThrowException(String::New("Error reading file")); | 1065 return ThrowException(String::New("Error reading file")); |
1085 } | 1066 } |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 } | 1576 } |
1596 | 1577 |
1597 } // namespace v8 | 1578 } // namespace v8 |
1598 | 1579 |
1599 | 1580 |
1600 #ifndef GOOGLE3 | 1581 #ifndef GOOGLE3 |
1601 int main(int argc, char* argv[]) { | 1582 int main(int argc, char* argv[]) { |
1602 return v8::Shell::Main(argc, argv); | 1583 return v8::Shell::Main(argc, argv); |
1603 } | 1584 } |
1604 #endif | 1585 #endif |
OLD | NEW |