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 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 }; | 828 }; |
829 #endif | 829 #endif |
830 | 830 |
831 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { | 831 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { |
832 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 832 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); |
833 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 833 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); |
834 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); | 834 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); |
835 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); | 835 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); |
836 global_template->Set(String::New("readbinary"), | 836 global_template->Set(String::New("readbinary"), |
837 FunctionTemplate::New(ReadBinary)); | 837 FunctionTemplate::New(ReadBinary)); |
| 838 global_template->Set(String::New("readbuffer"), |
| 839 FunctionTemplate::New(ReadBuffer)); |
838 global_template->Set(String::New("readline"), | 840 global_template->Set(String::New("readline"), |
839 FunctionTemplate::New(ReadLine)); | 841 FunctionTemplate::New(ReadLine)); |
840 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 842 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); |
841 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 843 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
842 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 844 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
843 global_template->Set(String::New("enableProfiler"), | 845 global_template->Set(String::New("enableProfiler"), |
844 FunctionTemplate::New(EnableProfiler)); | 846 FunctionTemplate::New(EnableProfiler)); |
845 global_template->Set(String::New("disableProfiler"), | 847 global_template->Set(String::New("disableProfiler"), |
846 FunctionTemplate::New(DisableProfiler)); | 848 FunctionTemplate::New(DisableProfiler)); |
847 | 849 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 if (chars == NULL) { | 1065 if (chars == NULL) { |
1064 return ThrowException(String::New("Error reading file")); | 1066 return ThrowException(String::New("Error reading file")); |
1065 } | 1067 } |
1066 // We skip checking the string for UTF8 characters and use it raw as | 1068 // We skip checking the string for UTF8 characters and use it raw as |
1067 // backing store for the external string with 8-bit characters. | 1069 // backing store for the external string with 8-bit characters. |
1068 BinaryResource* resource = new BinaryResource(chars, size); | 1070 BinaryResource* resource = new BinaryResource(chars, size); |
1069 return String::NewExternal(resource); | 1071 return String::NewExternal(resource); |
1070 } | 1072 } |
1071 | 1073 |
1072 | 1074 |
| 1075 Handle<Value> Shell::ReadBuffer(const Arguments& args) { |
| 1076 String::Utf8Value filename(args[0]); |
| 1077 int length; |
| 1078 if (*filename == NULL) { |
| 1079 return ThrowException(String::New("Error loading file")); |
| 1080 } |
| 1081 char* data = ReadChars(*filename, &length); |
| 1082 if (data == NULL) { |
| 1083 return ThrowException(String::New("Error reading file")); |
| 1084 } |
| 1085 |
| 1086 Handle<Object> buffer = Object::New(); |
| 1087 buffer->Set(String::New(kArrayBufferMarkerPropName), True(), ReadOnly); |
| 1088 |
| 1089 Persistent<Object> persistent_buffer = Persistent<Object>::New(buffer); |
| 1090 persistent_buffer.MakeWeak(data, ExternalArrayWeakCallback); |
| 1091 persistent_buffer.MarkIndependent(); |
| 1092 |
| 1093 buffer->SetIndexedPropertiesToExternalArrayData( |
| 1094 reinterpret_cast<uint8_t*>(data), kExternalUnsignedByteArray, length); |
| 1095 buffer->Set(String::New("byteLength"), |
| 1096 Int32::New(static_cast<int32_t>(length)), ReadOnly); |
| 1097 return buffer; |
| 1098 } |
| 1099 |
| 1100 |
1073 #ifndef V8_SHARED | 1101 #ifndef V8_SHARED |
1074 static char* ReadToken(char* data, char token) { | 1102 static char* ReadToken(char* data, char token) { |
1075 char* next = i::OS::StrChr(data, token); | 1103 char* next = i::OS::StrChr(data, token); |
1076 if (next != NULL) { | 1104 if (next != NULL) { |
1077 *next = '\0'; | 1105 *next = '\0'; |
1078 return (next + 1); | 1106 return (next + 1); |
1079 } | 1107 } |
1080 | 1108 |
1081 return NULL; | 1109 return NULL; |
1082 } | 1110 } |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 } | 1594 } |
1567 | 1595 |
1568 } // namespace v8 | 1596 } // namespace v8 |
1569 | 1597 |
1570 | 1598 |
1571 #ifndef GOOGLE3 | 1599 #ifndef GOOGLE3 |
1572 int main(int argc, char* argv[]) { | 1600 int main(int argc, char* argv[]) { |
1573 return v8::Shell::Main(argc, argv); | 1601 return v8::Shell::Main(argc, argv); |
1574 } | 1602 } |
1575 #endif | 1603 #endif |
OLD | NEW |