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); |