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

Unified 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 side-by-side diff with in-line comments
Download patch
« src/d8.h ('K') | « src/d8.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index bfb99440272688ef271be0856c910dc7def74adc..e9c3c0e72d8a738f52fef3c2a53ff62565fae20b 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -803,6 +803,8 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate() {
global_template->Set(String::New("print"), FunctionTemplate::New(Print));
global_template->Set(String::New("write"), FunctionTemplate::New(Write));
global_template->Set(String::New("read"), FunctionTemplate::New(Read));
+ global_template->Set(String::New("readbinary"),
+ FunctionTemplate::New(ReadBinary));
global_template->Set(String::New("readline"),
FunctionTemplate::New(ReadLine));
global_template->Set(String::New("load"), FunctionTemplate::New(Load));
@@ -1021,6 +1023,19 @@ static char* ReadChars(const char* name, int* size_out) {
}
+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
+ String::Utf8Value filename(args[0]);
Jakob Kummerow 2012/01/24 11:30:20 What happens when the file doesn't exist? Maybe ad
+ int size;
+ char* chars = ReadChars(*filename, &size);
+ // We skip checking the string for UTF8 characters and use it raw as
+ // backing store for the external string with 8-bit characters.
+ BinaryResource* resource = new BinaryResource(chars, size);
+ i::Handle<i::String> string(
+ FACTORY->NewExternalStringFromAscii(resource));
+ return Utils::ToLocal(string);
+}
+
+
#ifndef V8_SHARED
static char* ReadToken(char* data, char token) {
char* next = i::OS::StrChr(data, token);
« 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