Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1586)

Side by Side Diff: src/d8.cc

Issue 9283015: Introduce readbinary function in d8 to read binary files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/d8.h ('K') | « src/d8.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 return result; 796 return result;
797 } 797 }
798 }; 798 };
799 #endif 799 #endif
800 800
801 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { 801 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() {
802 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 802 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
803 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); 803 global_template->Set(String::New("print"), FunctionTemplate::New(Print));
804 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); 804 global_template->Set(String::New("write"), FunctionTemplate::New(Write));
805 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); 805 global_template->Set(String::New("read"), FunctionTemplate::New(Read));
806 global_template->Set(String::New("readbinary"),
807 FunctionTemplate::New(ReadBinary));
806 global_template->Set(String::New("readline"), 808 global_template->Set(String::New("readline"),
807 FunctionTemplate::New(ReadLine)); 809 FunctionTemplate::New(ReadLine));
808 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); 810 global_template->Set(String::New("load"), FunctionTemplate::New(Load));
809 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); 811 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
810 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); 812 global_template->Set(String::New("version"), FunctionTemplate::New(Version));
811 global_template->Set(String::New("enableProfiler"), 813 global_template->Set(String::New("enableProfiler"),
812 FunctionTemplate::New(EnableProfiler)); 814 FunctionTemplate::New(EnableProfiler));
813 global_template->Set(String::New("disableProfiler"), 815 global_template->Set(String::New("disableProfiler"),
814 FunctionTemplate::New(DisableProfiler)); 816 FunctionTemplate::New(DisableProfiler));
815 817
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 for (int i = 0; i < size;) { 1016 for (int i = 0; i < size;) {
1015 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); 1017 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
1016 i += read; 1018 i += read;
1017 } 1019 }
1018 fclose(file); 1020 fclose(file);
1019 *size_out = size; 1021 *size_out = size;
1020 return chars; 1022 return chars;
1021 } 1023 }
1022 1024
1023 1025
1026 Handle<Value> Shell::ReadBinary(const Arguments& args) {
Jakob Kummerow 2012/01/24 11:30:20 Wouldn't it make more sense to call this ReadExter
1027 String::Utf8Value filename(args[0]);
Jakob Kummerow 2012/01/24 11:30:20 What happens when the file doesn't exist? Maybe ad
1028 int size;
1029 char* chars = ReadChars(*filename, &size);
1030 // We skip checking the string for UTF8 characters and use it raw as
1031 // backing store for the external string with 8-bit characters.
1032 BinaryResource* resource = new BinaryResource(chars, size);
1033 i::Handle<i::String> string(
1034 FACTORY->NewExternalStringFromAscii(resource));
1035 return Utils::ToLocal(string);
1036 }
1037
1038
1024 #ifndef V8_SHARED 1039 #ifndef V8_SHARED
1025 static char* ReadToken(char* data, char token) { 1040 static char* ReadToken(char* data, char token) {
1026 char* next = i::OS::StrChr(data, token); 1041 char* next = i::OS::StrChr(data, token);
1027 if (next != NULL) { 1042 if (next != NULL) {
1028 *next = '\0'; 1043 *next = '\0';
1029 return (next + 1); 1044 return (next + 1);
1030 } 1045 }
1031 1046
1032 return NULL; 1047 return NULL;
1033 } 1048 }
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 } 1519 }
1505 1520
1506 } // namespace v8 1521 } // namespace v8
1507 1522
1508 1523
1509 #ifndef GOOGLE3 1524 #ifndef GOOGLE3
1510 int main(int argc, char* argv[]) { 1525 int main(int argc, char* argv[]) {
1511 return v8::Shell::Main(argc, argv); 1526 return v8::Shell::Main(argc, argv);
1512 } 1527 }
1513 #endif 1528 #endif
OLDNEW
« src/d8.h ('K') | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698